Segmenting bulk of spherical objects
I am trying to segment an image with spherical-shaped objects, something like this being the source:
I tried several approaches:
- blur, adaptive thresholding, skeletonization, then connected components analysis, but it is very sensitive to lighting conditions;
- hough circles (with various pre-filters) which gives too much bogus results, reacts to single points and so on;
- distance map (after adaptive threshold) and watershed, with which I did not get very far (perhaps lack of experience).
The adaptive thresholding gives visually nicely separated objects (below shown with superimposed distance map) but I am having hard time to see which way to proceed all way to segmentation.
I am aware I am not using some features of the scene which are known are not exploited by the algorithm, such as
- all objects are plus minus circular (modulo occlusion);
- the objects cover the entire scene, i.e. they are packed quite tightly;
- size range is known (this is used after segmentation to prune the result only for what is meaningful, but this knowledge comes only after segmentation as clean-up, not as improvement of the segmentation itself)
I would be grateful for some ideas on how to move on.
change a ruler (to a different color)
Your case (where the objects have all very similar colour) is an ideal case where you could use depth edges and get very good results. The paper discussing this can be found here.
I was thinking along depth edges already, using 3 flashes (RGB), but that is not possible at the moment. For the record, matlab code for the paper you reference is here: https://github.com/erilyth/Depth-base... .
I know, I tried translating it to OpenCV once, not completely ready but the proof of concept can be found here: https://gist.github.com/StevenPuttema...