Color finding on RGB image

I have an RGB image ,i have to find the dominant color from this image. Dominant color means the highlighting color. (That will be red,blue,green, yellow etc.). What all are the steps that can be implemented in this process?

26 Comments

Please define "highlighting color" ?
Do you know what is dominant color ?
No, I do not know what dominant color is, and I do not think you know what dominant color is either. In one of your previous Questions I posted links to previous discussions explaining why none of us know what "dominant color" means, what some of the complications are.
Color dominance can be established in several ways – use of color, strength of hue, sharpness, contrast and perception of color. I have attached an image , we can easily find what is the dominant color in this image. So i would like to get the dominant color same as this
im not sure if this is what you are trying to do. have you tried getting the mean of the RGB image. and then extracting the individual mean of the RGB vector?
Here the dominant color is that which color have high sharpen and contrast. How can i find this
I have gone through that, where they mentioned about gray level image . Here i want to find it for the RGB image and i have to find the color
by using the given code in that article, u can be able to find the contrast between the highest valued pixel and the lowest valued. taking it to rgb image, u can define ranges for a specific rgb color. from there u can then check the size of the regions to find the color which has the greatest pixel contrast. the values of the colors can be found if you do a google search on rgb color chart.
"Here the dominant color is that which color have high sharpen and contrast."
In your earlier demo image, you are pushing for yellow to be called the dominant color of the image, but yellow does not have high sharpness or contrast in that image.
Actually i have analyzed about 'What is dominant color', finally i found those conclusion (high contrast and sharpness). which color have the high sharpness or contrast in that demo image?
So if you have a solid medium green image, but it has a single bright red pixel in it, then that is a sharp boundary between the single red pixels and the background, and it is high contrast because the red and green channels vary quite a bit compared to the background. That implies that the single red pixel is the "dominant color" by that definition.
Huge amount of pixels will be in a normal image. So i didn't meant about one pixel , i meant a certain range of pixels (eg :its like 5% of the total number of pixels)
Walter Roberson's test image. What is the dominant color?:
@Stephen Cobeldick: Green is the dominant color here.Red is not, because the red color is a small portion of the image (lower than 5%). Can you explain what is dominant color ?
In your demo.img with the yellow waterfall, the black is sharp boundaries and high contrast to the yellow and green, and is the only color that has more than 5% of the pixels; so is it correct that the dominant color for that image is [0 0 0] ?
In the case of your demo6 image with the lanterns, no color is more than 0.52%, so is it correct that that image has no dominant color?
This dominant color is a complicated task to define. If anyone knows then explain it
And for this? (5% + 1 pixel):
Why is green NOT dominant?
I went through every Question that mentioned dominant color or primary color (including the ones where that it was an accidental combination of words.) In the entire time that MATLAB Answers has existed, not one person has known what "dominant color" is.
@Stephen Cobeldick : Can you explain what is dominant color ?
@sam CP: no, because I don't understand why green is not dominant in my second example image.
Jan
Jan on 25 Jun 2018
Edited: Jan on 27 Jun 2018
@sam CP: In this and other threads of you several people try to explain repeatedly, that there is not definition of "dominant color". Does this information reach you?
Even asking again and again will not change this answer.
"High contrast and sharpness" is not a unique definition also. I asked you already what the "dominant color" of the French flag is and I'm sure that this is an example of an image, which cannot have one dominant color.
So it is your turn to provide a unique definition, such that the forum can suggest an implementation. But without such a definition from you, this question has no relation to Matlab and would be off-topic.
One cannot program a search for "dominant" or "recessive" color because this is a human perception, unique to each person. A computer does not have human perception (yet). There is also the color blindness issue.
Hmmm, that link at least gives more information to go with, but I can't say I am inspired with any ideas as to how one might program the concept.

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 27 Jun 2018
I took the actionable ideas from the paper that OCDER linked to, and developed some code.
The paper talked in terms of purity of primary color, and it talked in terms of contrast, and it talked in terms of portion of the image occupied. So my code calculates though three factors, normalizes them each to 1, and then comes up with an aggregate statistic by taking the geometric mean (geometric mean is less likely to favor a location that ranks high in only one of the three.)
What I found is that if the image has black, then the measure is likely to pick out the black as being the most dominant. This is because:
  • black often occupies a large total fraction of the area (even if only in ones and twos in the background.)
  • black is pure primary color
  • isolated black pixels surrounded by non-black pixels have a high contrast
So when the three measures are used together, it is not uncommon for black to be declared most dominant.
data.jpg and data6.jpg both have black pixels selected as most dominant. The standard demo image "peppers" picks out a yellow pixel though.

8 Comments

sam  CP
sam CP on 27 Jun 2018
Edited: sam CP on 27 Jun 2018
Can u explain about how to find purity of primary color, contrast and portion of the image occupied?
Walter Roberson
Walter Roberson on 27 Jun 2018
Edited: Walter Roberson on 27 Jun 2018
For portion occupied I used the same code I posted before to convert rgb triple into colormap and index and use accumarray to count the number of each.
The primary colors are the 8 at the corners of the rgb color cube. For each unique rgb triple I determine the distance to the closest cube corner as a euclidian distance and then normalize by the maximum distance possible (which would be the center of the cube.) This gives 0 at the primary colors and 1 at the weakest combination, so take 1 minus the result to get a value that is 1 at the purest and 0 at least pure.
I calculated contrast on a pixel by pixel basis using nlfilter to find the sum of squares of differences between surrounding pixels and central pixels divided by the number of pixels that were not the same as the central pixel, so an average contrast contribution from each neighbour that is not the same as the central. This involved calling nlfilter four times, once per bit plane and once for the counting.
Can i see the code that you have done ?
Grab the code in https://www.mathworks.com/matlabcentral/answers/407086-can-i-use-color-map-to-find-which-color-is-the-most-used-color-in-an-image#answer_326023 and start modifying. The plotting takes more code than the basic calculations for everything except the contrast calculation.
We have already discussed about this code.
Right. So since I explained how it works already, you should not have difficulty starting with it and adding more calculations on to it. The difficult part about cataloging different RGB pixels into unique color indices is already done. Tone purity only has to be calculated once for each unique RGB combination.
Would it be worth using Lab to make it slightly more perceptually uniform?
Defining distance in L*a*b* is a bit tricky, as you have to figure out whether the three components should be treated as being on the same scale. I got sidetracked for a bit trying to figure out what the ranges of values were, got sidetracked from that, ended up calculating as if they were all equal.
With the test images I ran through, it ended up not making any difference as to which pixel was selected, but it did make a difference in the details of the pattern. I suppose that would mean that if there was an image with more neutral colors, then it might pick out a different neutral color.
However, along with the changes needed to determine distance in L*a*b* space, I took the opportunity to disqualify black from the list of eligible pure colors. That did make a difference, leading to the selection of an olive yellow pixel in the waterfall image (instead of the large black background); a red pixel in the lantern image (instead of the more subtle black mixed in with the green); and a white pixel on the peppers image (instead of a yellow pixel.)
In all three cases, the exact pixel selected ends up being driven mostly by the contrast calculation, and ends up being a pixel on the boundary of a similar area (that might be quite small), because boundaries establish contrast.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!