Input Image:
Expected Output:
I intend to fit three (or some number of) polygons (for this case, rectangles) to signify the "big" white blobs in this image. The rectangles drawn in the output image are as per my perception of the white regions. I do not expect the algorithm to come up with these same bouding regions. What I wish for is to fit some number of tight polygons around the clusters of white pixels.
My initial solution consisted of finding contours for this image, and fitting a closed convex polygon around each contour, by finding the convex hull of the points in each contour.
However, since the white regions are highly fragmented with black regions within and ridged around the edges, the number of contours returned by cv2.findContours is very high (around 500 or so). Due to this, fitting a convex hull does not improve the shape of the white regions. The white regions mostly retain their original abstract shapes. My goal would be to merge the many small contours of a white region into one whole containing contour over which I can then fit a convex hull.
How do I solve this problem? Should I use a clustering algorithm on the contour points initially to find the contours that are close by each other?