Segmentation of connected squares