# Making a mask that is dynamic..

I am looking for a method that is capable of creating a mask based on what color occur most.. So the idea is that it based what color is occurring most is capable of creating a binary map, that filter those things out which doesn't have the same color as the rest of the picture...

so an ex. would be this picture

It can clearly be seen that most of the image is blue, so based on that color should a mask be created which filters everything that is blue away, and only show the 3 pink dots..

edit retag close merge delete

So, you have three problems 1) finding the most frequent color --> you can use here a histogram to find that. 2) creating the mask --> this is just a comparison with the color-value which you found in step 1. 3) Applying the mask --> you can use here the copyTo() method or do it by hand.

( 2015-03-22 09:06:07 -0500 )edit

What kind of histogram HSV , RGB

( 2015-03-22 09:26:24 -0500 )edit

Well, the color space is up to you, creating the 3 dimensional histogram is probably the most difficult part, but the example code of http://docs.opencv.org/modules/imgpro... tells you pretty well what you need to do. (What you don't want is to create 3 histograms for each color channel which is done in http://docs.opencv.org/doc/tutorials/...).

( 2015-03-22 10:10:01 -0500 )edit

I used Â´minMaxLoc' to find the highest value, but the value I get as the highest Hue value is 339498 which doesn't make sense, since the highest possible value should be 0 to 180

( 2015-03-24 11:09:19 -0500 )edit

guess you called minMaxLoc in a wrong way, example-usage:

double min, max; minMaxLoc(input, &min, &max);

Also note that this doesn't work for multi-channels. Also it doesn't give you the most frequent color but just the maximum value, so if you called it with a grayscale version of your image it will most certainly give you '255' ( I guess this is actually not what you want...).

( 2015-03-24 11:28:01 -0500 )edit

I don't think so ... Here is the code.. http://pastebin.com/RjsR9qjn

( 2015-03-24 11:42:53 -0500 )edit

Ahh, okay, you are actually computing the histogram, maybe it's cause of MatND type of your histogram. Sry, don't know how to solve it right now.

( 2015-03-24 11:54:56 -0500 )edit