Skip to content
Prev 207960 / 398502 Next

detect brightness of hex color value in R / convert from hex to hsl/hsv space how?

On Fri, 29 Jan 2010, Mark Heckmann wrote:

            
You can use the "colorspace" package for that. hex2RGB() converts a hex 
string to "RGB" coordinates which in turn can be easily converted to 
systems like "HSV" or (preferably) HCL (called "polarLUV" in colorspace).

R> as(hex2RGB("#910322"), "polarLUV")
             L        C        H
[1,] 31.61831 95.14145 6.913428

"L" corresponds to the luminance (whether a color is light or dark), "C" 
is chroma (how colorful the color is compared to a gray with the same 
luminance), and "H" is the hue.

hth,
Z