Reputation: 25
I want to separate a noiseless 1-bit (black and white) image with white circles based on the concave part of the outline. Please refer to the picture below.
This is the white object to separate:
The target result is:
Here is my implementation with the watershed algorithm:
The above result is not what I want. If the size of the separated objects is similar, my algorithm is fine, but if the size difference is large, a problem occurs as shown in the picture above. I would like to implement an opencv algorithm that can segment a region like the second picture.
However, the input photo is not necessarily a perfect circle. It can be oval like the picture below:
Or it can be squished:
However, I would like to separate it based on the concave part of the outline anyway.
I think it can be implemented by using the distanceTransform function well, but I'm not sure how to approach it. Please let me know which way to refer. Thank you.
Upvotes: 0
Views: 253
Reputation: 6288
If you want to find the minimal openings, you can use a medial axis based approach.
Pseudo code:
compute contours of bitmap
compute medial-axis of bitmap
for each point on medial-axis:
get minimal distance d from medial axis algorithm
for each local minimum of distance d:
get two points on bitmap contours with minimal distance that are at least d apart from each other
use these points for deviding line
If you need a working implementation in python
, please let me know. I would use skimage
lib. For other languages you might have to implement medial-axis on your own. But that shouldn't be a big deal.
Upvotes: 0
Reputation: 1163
Here is an algorithm which should give you a good start.
Upvotes: 1