Linell
Linell

Reputation: 749

Counting Objects via Mean-Shift Segmentation

I'm trying to use mean-shift segmentation to count the objects found in an image. I've been working with [pyrMeanShiftFiltering][1] in OpenCV. Using the following code, I'm able to produce an image that has been segmented. However, I do not know how to actually count the number of "items" in that image.

Simply running pyrMeanShiftFiltering( img, res, spatialRad, colorRad, maxPyrLevel ); on this image
unsegmented books

produces this image enter image description here

In this example, it doesn't seem much different, although there are some images where the segmentation makes a huge difference in the colors and such present. However, for the majority of test cases, I'm going to assume that the colors will not be terribly distinct and that the edges will not be distinct (as they are in the example given) enough to use edge detection on the image itself.

Based off of this, how can I go about finding the number of objects found inside of that image? I'm looking for a bit of code, although any poke in the correct direction will help.

Upvotes: 2

Views: 1524

Answers (1)

dajuric
dajuric

Reputation: 2507

If the objects contain different colors (and those colors are distinctive) the simplest soultion would be to count how many clusters are there (remove cluster for the white color since the pages are white/yellow).

On images that you have shown you could also use corner detector since you have very distinctive corners, then look the surrounding and filter those corners by color (the surrounding color has to contain some color and white one (from pages)) then match corners that lie in the same vertical line and finally count them.

One other idea is to extrapolate white/yellow color from pages (clustering + histogram filtering) and to count different blobs.

Maybe the best approach is to extrapolate white/yeelow color from pages by finding cover color (blue, green) and closest white color => find blobs. Those blobs can be labeled to the closest cover color. Then you have blobs that present pages and are labeled according the closest cover color. Those blobs may be broken to several pieces (one book partly covers the other book) and two different blobs may belong to the same object (a book with multiple color cover) but you now that those blobs have to be rectangular. So you could find lines in that binarized image and try to connect them with closest line. Then you will finally have one blob that matches one book. Finally you can count them.

Upvotes: 2

Related Questions