Partitions a 2D binary image into rectangles