javaopenimaj

Getting blobs of an image without holes


I have an image that has various blobs and I want to get only blobs that do not have holes.

I tried using SuzukiContourProcessor.findContours to accomplish that, but it returns Contours of types ContourType.HOLE and ContourType.OUTER. Is there a way to convert a ContourType.OUTER to a list of ContourType.HOLE somehow?

Or is there a better way to accomplish what I'm after?


Solution

  • You're on the right lines: findContours returns a hierarchy of detections, so you just need to filter out the ones you don't want (i.e. looking for contours without children I'd guess). Take a look at this to see the kind of thing you can do (this goes further and looks for regions with a specific hierarchical structure - the test method - but you should be able to see to to modify the idea for your specific problem): https://github.com/jonhare/COMP3204/blob/master/app/src/main/java/uk/ac/soton/ecs/comp3204/l5/RAGDemo.java