I'm writing a program to get the name of a color. I can get the rgb value of the pixel, but couldn't find out how to get its name. Is there any c++ library that can get the name of a color from its rgb value? Or find the closest matching color name?
Asked
Active
Viewed 3,368 times
2
-
1Do you have a list of names you plan on using? Or are you going by some standard? Colors don't intrinsically have names. – tychon Nov 18 '13 at 19:35
-
You will have a range of hex values corresponding to 1 name. Defining the granularity of the range is totally up to you. You can have 10 colors or 10000. If you have a limited use then you can hardcode the names (assuming it's a manageable number). – Rahul Shardha Nov 18 '13 at 19:39
-
I do not have the names and I'm not sure what color I will get. The basic idea I have is to get names from HTML defined colors. – user1964417 Nov 18 '13 at 19:40
-
You might want to think about how close a hex value needs to be before you call it "*that* color". #000000 is pretty obvious "black", but are #010100 and #010204 too? In RGB space there are 16,216,214 different colors (I might be off by a few percent there). – Jongware Nov 18 '13 at 20:20
1 Answers
3
Aside from HTML color tables, there's also the RAL standard, a well known system used in the industry.
What one would need is basically the code table with names and RGB values. One can easily find the closest match for the appropriate color name, as long as the table's resolution and spectrum is sufficient:
- http://www.ralcolor.com/
- http://www.gobias.com/convert-ral-to-rgb.html
- http://en.wikipedia.org/wiki/List_of_colors
A simple CSV reader, to load the color tables may be a solution.
-
1When looking up in those tables, I'd recommend finding the closest color in HSV space, rather than RGB space. You'll probably get better matches, i.e., matches closer to what a person would have chosen. – HeywoodFloyd Nov 18 '13 at 20:31
-
Sounds reasonable. How would you compare HSV vectors? According to something like this: http://en.wikipedia.org/wiki/Color_difference ? I tend to use the scalar product of RGB vectors, perhaps with luminance weighting only. Or a conversion to YUV http://stackoverflow.com/a/5392276/1175253 – Sam Nov 18 '13 at 20:37
-
1Whoever wrote the wikipedia article gave it a lot more thought than I did. I don't know if YUV or HSV comparison would be closer to what a person would choose. My gut feeling is HSV, since I think people would put light red and dark red together before a red and a green of the same luminance. – HeywoodFloyd Nov 18 '13 at 21:26
-
1I would recommend using the [Lab colorspace](http://en.wikipedia.org/wiki/Lab_color_space) instead of RGB or HSV, since "Lab color is designed to approximate human vision. It aspires to perceptual uniformity [...]". – liviucmg May 28 '14 at 23:15
-