Making a mask that is dynamic.. [closed]

asked 2015-03-22 08:33:34 -0600

215 gravatar image

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

image description

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 flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-29 00:34:47.902653

Comments

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.

Guanta gravatar imageGuanta ( 2015-03-22 09:06:07 -0600 )edit

What kind of histogram HSV , RGB

215 gravatar image215 ( 2015-03-22 09:26:24 -0600 )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/...).

Guanta gravatar imageGuanta ( 2015-03-22 10:10:01 -0600 )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

215 gravatar image215 ( 2015-03-24 11:09:19 -0600 )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...).

Guanta gravatar imageGuanta ( 2015-03-24 11:28:01 -0600 )edit

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

215 gravatar image215 ( 2015-03-24 11:42:53 -0600 )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.

Guanta gravatar imageGuanta ( 2015-03-24 11:54:56 -0600 )edit