3

I have two image processing problems that I'm handling using Open-CV.

  1. Identifying similar objects with different colors apart from each other.
  2. Identifying similar colored objects with different sizes apart from each other.

Example images for scenarios 1 and 2;

1

Different colored

2

Different sized

Both the images have three types of objects of interest. (Either three colors or sizes)

The techniques I've come across include thresholding and then using erosion with pixel counting, color segmentation using RGB values.

What is a good work-chain and what is a good place to start?

Tru
  • 1,467
  • 5
  • 18
  • 27
  • IF the objects you are interested at are circles, I would look into [this](http://stackoverflow.com/questions/10404062/opencv-dot-target-detection-not-finding-all-targets-and-found-circles-are-offse/10416428#10416428), [this](http://stackoverflow.com/questions/6416117/simple-object-detection-using-opencv-and-machine-learning/6416361#6416361) and [this](http://stackoverflow.com/questions/10313602/reshaping-noisy-coin-into-a-circle-form/10316493#10316493). – karlphillip Jun 13 '12 at 14:17

3 Answers3

8

For color segmentation you should stay away from RGB as similar colors aren't linearly related.

As an example 2 similar colors (with identical hue) may have very different RGB values:

Same Hue and Very Different RGB values

It's better to work with color spaces like LUV or HSV which have separated color from luminance. For example you may try a clustering algorithm on U,V components of LUV.

Kamyar Infinity
  • 2,711
  • 1
  • 21
  • 32
3
  1. Obviously working with RGB value is probably the best way to start here. Use the function cvSplit, which will give you the three separated plans B, G and R (BGR order with OpenCV, not RGB). In each one of them, you should see only the circles of the corresponding color.

  2. I would recommend here to first perform a edge detection with Canny algorithm, implemented in OpenCV by the function cvCanny, and then do a circle detection with Hough algorithm, also implemented in OpenCV. If I remember well, the OpenCV function for Hough circles returns the circle properties (radius...), which will allow you to identify your circles upon their sizes. Another option for 2. is Hit&Miss algorithm, that uses morphology. I never used morphology with OpenCV though, only with Matlab.

Have fun

CTZStef
  • 1,675
  • 2
  • 18
  • 47
  • 3
    If, like in your sample images, you know that all the objects will be circles, you can forgo the Hough circles, and simply count pixels, since the area is directly proportional to the radius in a known manner. – Steve Heim Jun 13 '12 at 07:54
  • 1
    That's right, if you're sure there will only be circles in your images. Soryy I'm used to far less controlled computer vision problems ^^ – CTZStef Jun 13 '12 at 12:21
  • It's going to be a pellet-like object, which is not necessarily a proper circle. Is there anyway in OpenCV that I can count pixels of irregular blobs to figure out their sizes? – Tru Jun 14 '12 at 15:16
  • The detected blobs from the [cvBlob Library](http://code.google.com/p/cvblob/wiki/FAQ#3_Using_the_library) have methods to get their area and centroids. – Darcara Jun 14 '12 at 16:01
2

Have a look at cvBlob which works very well and can handle complex shapes.

Darcara
  • 1,598
  • 1
  • 13
  • 33