Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Segmentation for Color Analysis in OpenCV

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?

like image 844
TonyRo Avatar asked Mar 04 '13 16:03

TonyRo


People also ask

How image is segmented based on color?

Image segmentation is a process of assigning a labe l to every pixel in an image such that pixels with same label share certain visual characteristics. Sometimes it becomes necessary to calculate the total number of colors from the given RGB image to quantize the image, to detect cancer and brain tumour.

What are the three types of color representation in colored images in OpenCV?

In the most common color space, RGB (Red Green Blue), colors are represented in terms of their red, green, and blue components. In more technical terms, RGB describes a color as a tuple of three components.


2 Answers

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

like image 70
Adi Shavit Avatar answered Sep 22 '22 16:09

Adi Shavit


I'm not an expert but I really don't see how the Watershed algorithm can be very useful to your segmentation problem.

From my limited experience/exposure to this kind of problems, I would think that the way to go would be to try a sliding-windows approach to segmentation. Basically this entails walking the image using a window of a set size, and attempting to determine if the window encompasses background vs. an object. You will want to try different window sizes and steps.

Doing this should allow you to detect the object in the image, presuming that the images contain relatively well defined objects. You might also attempt to perform segmentation after converting the image to black and white with a certain threshold the gives good separation of background vs. objects.

Once you've identified the object(s) via the sliding window you can attempt to determine the most prominent color using one of the methods you mentioned.

UPDATE

Based on your comment, here's another potential approach that might work for you:

If you believe the objects will have mostly uniform color you might attempt to process the image to:

  1. remove noise;
  2. map original image to reduced color space (i.e. 256 or event 16 colors)
  3. detect connected components based on pixel color and determine which ones are large enough

You might also benefit from re-sampling the image to lower resolution (i.e. if the image is 1024 x 768 you might reduce it to 256 x 192) to help speed up the algorithm.

The only thing left to do would be to determine which component is the background. This is where it might make sense to also attempt to do the background removal by converting to black/white with a certain threshold.

like image 30
Mike Dinescu Avatar answered Sep 18 '22 16:09

Mike Dinescu