0

I tried to gets the prominent color of an image using this example. This is working perfect for plain images. But when I'm giving an image like this,

enter image description here

It's give me the color RGB(0,4,7)(a black one). How may I fix this?

Community
  • 1
  • 1
codebot
  • 2,540
  • 3
  • 38
  • 89
  • 2
    Looks like that example tries to filter out the greys... your example image looks like it includes only greys. Try removing the grey filter, or maybe give the second best answer a go (ColorFinder: http://pieroxy.net/blog/pages/color-finder/index.html) – PeteB Nov 16 '15 at 08:19
  • How may I remove the grey filter ? I commented the `isGrey` condition. But still have the issue. – codebot Nov 16 '15 at 08:23
  • I've just skimmed the code and once the isGray condition is removed it should work correctly. It will return the RGB of the most common colour in the image by direct matching (it doesn't group similar colours together). Are you certain that the value being returned is not the single most frequent exact RGB value? Check the answer to that question by http://stackoverflow.com/users/1207655/martin-wilson for a nice description. – PeteB Nov 16 '15 at 08:31
  • Do you want the perceived predominant color? Then don't use the code you have. It's just counting which exact color occurs most often. There is say 182 times the color (0,4,7) in your image and less of multiple different desaturated blueish colors, e.g. 170 times a very bright blueish color and 100 times a darker one. In sum they would probably win but that code does not do that. You'll get closer to the perceived color by blurring or downsizing the image to 1 pixel & then taking that pixel's color (which is basically the same as making it so blurry that you see only 1 color). – zapl Nov 16 '15 at 08:53
  • thanks, will try on this. – codebot Nov 16 '15 at 09:20

1 Answers1

0

In fact you are not looking for the dominant color, but more for the dominant range of color. So you are looking for the bigger cluster in the RGB histogram. Take a look to the papers of Arnaud LeTrotter (at this time he was working at the LSIS laboratory in Marseille, France), it's exactly what he did. He added some tolerance to the main color detection in order to have the main range.

FiReTiTi
  • 5,597
  • 12
  • 30
  • 58