Split image to several rectangles. Refactoring.