When I apply MorphologicalComponents
to images like the one below (which consist of white rectangles laid on a black background), I get a single object returned, as opposed to the two rectangles (since they happen to be "connected", as the two rectangles overlap):
Test image:
Output after applying MorphologicalComponents
:
However I would like to obtain them as different components; if possible also obtaining the two full rectangles in other cases where they overlap more, such as in the unfortunate case of the following image:
I have tried simple transformations such as finding the perimeter:
from where I think shouldn't be too difficult to close the rectangles and retrieve them, but haven't managed so far... I have also tried more exotic ideas and transformations such as applying MorphologicalTransform
to obtain the vertical and horizontal edges in two separate images, to them add them together, but again I have the problem of closing the different rectangles separately. I really need some help at this point, would appreciate any input.