3

Currently working on one academic project regarding color detection in android. I am trying to detect color using android cameras that would during live preview or after the picture is taken.

I am looking for something like this image. This is ColorGrab android application screenshot. Basically I wanted to identify every color as a particular one color. Lets take a example for that, suppose application detected #FF6CBB but this color is actually similar to pink but I want to mark this color as RED in my list. So Basically I want to convert all colors in basic 8 to 10 colors. So any color code which should be fall in particular range and that range should represent only one color.

In this image color code is not actually hex code of Red but we can make this detected color code in Red Color category.

Overall my program goal should be identify any color code of the color wheel as a one color among of particular 10 colors. How and which way I can compute this thing, Shall I use shortest euclidean distance between two colors?

Can anybody please tell me algorithm or way to compute this thing.

image 1 

Screen Shot of ColorGrab Application

example of color distribution

enter image description here

sam_k
  • 5,983
  • 14
  • 76
  • 110
  • What is your actual color distribution? You have HSV information there; is the Hue channel better suited to your needs? – beaker May 28 '15 at 16:25
  • @beaker Thanks for your comment, Actually i am totally new for this I do not know how to proceed first. – sam_k May 28 '15 at 16:29
  • Okay, but you have to know what the 10 colors are that you're trying to detect, right? – beaker May 28 '15 at 16:30
  • @beaker yes i have that 10 colors list. Like this link, is this solution solve my problem in efficient way? http://stackoverflow.com/questions/4126029/java-color-code-convert-to-color-name – sam_k May 28 '15 at 16:32
  • Sure, that's using L1 distance and should give you reasonable answers. You could also use L2 (Euclidean) distance if you wanted. Note that RGB is not exactly linear. For some discussion on this, see http://stackoverflow.com/questions/9018016/how-to-compare-two-colors. – beaker May 28 '15 at 16:37
  • @beaker which is best way to make it robust and efficient? is that LAB colors will work? – sam_k May 28 '15 at 16:42
  • For 10 colors, I don't think it really matters. Try it out and see what it looks like. See if the results look right to you. Color is very subjective. – beaker May 28 '15 at 16:43
  • @beaker thanks for your input. I will try soon. – sam_k May 28 '15 at 16:47
  • @beaker One more thing i would like to ask is that actually i want to detect colorcode of any object or focus thing while camera preview is started. As like above first image. How can I do that in android? – sam_k May 28 '15 at 16:49
  • That is beyond my expertise and probably warrants a new question. – beaker May 28 '15 at 16:58
  • @beaker thanks for info, I will ask new question for this thing. I though may be you aware about this as your profile shows related to opencv project – sam_k May 28 '15 at 16:59

1 Answers1

0

k-nearest neighbors (k=1 in your case) with euclidean distance might work in your case, because you only have 3 dimensions (this method suffer from the curse of dimensionality )

You can also expirement with different distance measures such as Hamming distance

iTech
  • 18,192
  • 4
  • 57
  • 80
  • Can you please elaborate your answer in detail. I confused in between some big terms like curse of dimensionality and all. – sam_k May 28 '15 at 06:43
  • What is the value of K? Can you explain me how you suggest me to take k=1 in my case? – sam_k May 28 '15 at 06:48
  • K is how many closest points you will select, in your case you just need to pick a single color. – iTech May 28 '15 at 06:51
  • Course of dimensionality in this context is when you have many variables that you calculate the distance with. In your case it is only 3 (R,G and B) so this method should work. – iTech May 28 '15 at 06:52
  • thanks for your reply. Shall i apply this solution to my problem? http://stackoverflow.com/questions/4126029/java-color-code-convert-to-color-name – sam_k May 28 '15 at 06:55
  • Although the distance definition in that answer is not euclidean distance, but it should work fine. – iTech May 28 '15 at 07:00
  • So for more efficiency shall i apply Euclidean distance or simple RGBDistance? – sam_k May 28 '15 at 12:49
  • What is K in your answer? Can you please elaborate your answer more. – sam_k May 28 '15 at 13:00
  • It should not matter much it is just a different formula. As I said K is how many nearest points you consider for your calculation. For example, in a different context such as regression or classification someone can pick the nearest 3 points (i.e. k=3) and average them. – iTech May 28 '15 at 14:55
  • So k means number of colors which should be in list predefined. – sam_k May 28 '15 at 15:08