Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It seems that you don't need to detect the "broken contours", rather avoid to fill the inside of the those shapes. To achieve this, probably the best solution is to apply a morphological closing on the shape (morphologyEx function). This will close the gaps in the shape and you can apply the flood fill to remove the background.

If you want to detect the narrow gaps, probably a black hat operation (also morphologyEx) will give you these points.

It seems that you don't need to detect the "broken contours", rather avoid to fill the inside of the those shapes. To achieve this, probably the best solution is to apply a morphological closing on the shape (morphologyEx function). This will close the gaps in the shape and you can apply the flood fill to remove the background.

If you want to detect the narrow gaps, probably a black hat operation (also morphologyEx) will give you these points.

[EDIT] Here are the results of the closing operation on the second image (binarized) using a 7x7 pixel rectangular kernel. The gaps were closed:

image description

Here, you can use floodfill to erase the background. Then, you can copy the alpha mask to the original image if you want to keep the original shapes.