Ask Your Question
0

Identifying dominant (background) colour in still images using mean-shift

asked 2014-03-10 16:34:31 -0600

Yan gravatar image

Are there any functions in openCV which perform the mean-shift algorithm in colour space only? It seems like the meanShift() function is aimed only at motion tracking. I want to ignore spatial information and simply find the dominant (modal) colour(s).

The context is that I'm trying to identify the background in images of pinned butterfly specimens. I don't want to use k-means clustering, as the other colours in the images can be very variable (see examples below). The backgrounds can vary in brightness across the image, but are of (approximately) uniform hue, or are sometimes speckled (which I get rid of by using cv2.bilateralFilter()). However, I can't use a single hue channel, because the background is often white, grey, or dark, and jpeg compression can lead to rather variable hue values even within a similar looking background. Instead, I'm thinking of looking for the dominant region in c1c2c3 colour space.

Once I have at least part of the background, The idea is to mask out the rest using GrabCut(), identify the contours in the mask, and perform logistic regression on the Hu moments to identify which masked area is most butterfly-like.

Thanks

Yan

Blue background large butterfly image descriptionimage description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-03-11 12:45:55 -0600

xaffeine gravatar image

I think you could use mean-shift (or bilateral) filtering to do some smoothing and then take color histograms (or even mean color) near the corners of the images to get the background color you are looking for.

edit flag offensive delete link more

Comments

Thanks. It's the speckled background that really causes the problems. I've ended up doing 3 rounds of bilateral filtering then a mean shift (using pyrMeanShiftFiltering). To get around the problem that the corners may not represent the true background, I've then taken a mean over the largest flood-filled area from a selection of starting points inside the image.

Instead of flood fill, I guess once pyrMeanShiftFiltering has segmented the image, I could pick the largest area of a uniform colour, but I don't know how to do that.

Yan gravatar imageYan ( 2014-03-12 04:24:11 -0600 )edit

Question Tools

Stats

Asked: 2014-03-10 16:34:31 -0600

Seen: 902 times

Last updated: Mar 11 '14