Making a mask that is dynamic.. [closed]
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..
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.What kind of histogram HSV , RGB
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/...).
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
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...).
I don't think so ... Here is the code.. http://pastebin.com/RjsR9qjn
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.