-5

I am going to do program one android application which will detect color of any solid background image using live camera preview or using captured image by camera.

Can I converts an rgb/hex value color into the closest color name which I already defined in particular list. Suppose I have defined 10 well known colors in my list. Once I would identified hex code of any color I need to find its closest color from list which I have.

How can I do this using efficient and fast algorithm? Is there any API in android palette class to do the same?

Thanks

sam_k
  • 5,983
  • 14
  • 76
  • 110
  • Why downvote? This question is more specific then my previous question. – sam_k May 28 '15 at 06:46
  • Previous question contains about color code detection using live camera. – sam_k May 28 '15 at 06:47
  • What is the definition of "closest"? Close in brightness, close in color, close in saturization? Be aware that this is culture dependent. Some folks in Africa cannot distinguish between green and brown because for them, both colors are called "earth". Unfortunately I can't find the video right now. But see http://en.wikipedia.org/wiki/Checker_shadow_illusion why dark grey != light grey. – Thomas Weller May 28 '15 at 06:51
  • @Thomas Closest means close in terms of hexcode in predefined list. – sam_k May 28 '15 at 06:53
  • So `FF0000` and `FE0000` have a distance of `10000` but `0000FF` and `0000FE` have a distance of `1`? Certainly not. If you think about your problem, you'll find an algorithm soon. – Thomas Weller May 28 '15 at 07:06
  • @Thomas I am not sure which closest. But FF0000 and FE0000 are closest match as they have same color by human normal eye. 0000FF and 0000FE also same colors. I want to develop program which can give same known color from the list for FE0000 and 0000FE. – sam_k May 28 '15 at 12:58
  • Why you people close this question, Even nobody is giving reply over there too. – sam_k May 28 '15 at 12:59

1 Answers1

-1

I may suggest just to calculate distances to all of predefined colors and choose the one that is the nearest. You may try to define distance between color1(r1, g1, b1) and color2(r2, g2, b2) as follows: |color1 - color2| = sqrt(sqr(r1-r2) + sqr(g1 - g2) + sqr(b2 - b1)). If you have about 1000 predefined colors this will work very fast even for linear search. You may also google better distance functions for this problem.

Yevs
  • 167
  • 1
  • 7