Image Segmentation for Color Analysis in OpenCV

TonyRo picture TonyRo · Mar 4, 2013 · Viewed 7.5k times · Source

I am working on a project that requires me to:

Look at images that contain relatively well-defined objects, e.g.

enter image description here

and pick out the color of n-most (it's generic, could be 1,2,3, etc...) prominent objects in some space (whether it be RGB, HSV, whatever) and return it.

I am looking into ways to segment images like this into the independent objects. Once that's done, I'm under the impression that it won't be particularly difficult to find the contours of the segments and analyze them for average or centroid color, etc...

I looked briefly into the Watershed algorithm, which seems like it could work, but I was unsure of how to generate the marker image for an indeterminate number of blobs.

What's the best way to segment such an image, and if it's using Watershed, what's the best way to generate the corresponding marker image of integers?

Answer

Adi Shavit picture Adi Shavit · May 23, 2013

Check out this possible approach:
Efficient Graph-Based Image Segmentation Pedro F. Felzenszwalb and Daniel P. Huttenlocher

Here's what it looks like on your image:
enter image description here