Skip to content
Prev 349934 / 398513 Next

Convert color hex code to color names

To add slightly to that:

What you want to do is write a function that returns the named color that has the smallest difference to your input hex-triplet. But note that color difference is a large topic. Assuming you want to minimize *perceptual* differences, you want to calculate your differences in Lab color space. The function convertColor() has the option to convert hex to Lab. Example:
convertColor(t(col2rgb("thistle")), from="sRGB", to="Lab", scale.in=255)

Within Lab space, you can take the Euclidian distance.

That all said, I can't imagine why one would want to do this in the first place - color triplets are much more convenient than label strings :-)


B.
On Apr 13, 2015, at 11:45 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be> wrote: