Restore image from rectangles method implementation(refactoring).