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

Greg Snow Greg.Snow at imail.org
Fri Jan 29 17:44:04 CET 2010


There is a col2grey (and col2gray) function in the TeachingDemos package that use a common algorithm to convert colors to grey based on perceived lightness, that may work for you on deciding the color.

For placing text on colored backgrounds, look at the shadowtext function (also in TeachingDemos) for another way.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Mark Heckmann
> Sent: Friday, January 29, 2010 3:09 AM
> To: r-help at r-project.org
> Subject: [R] detect brightness of hex color value in R / convert from
> hex to hsl/hsv space how?
> 
> To the R color experts:
> I need to detect if a chosen background color (as hex e.g. #910322) is
> light or dark.
> If it is dark I need to ovelay it with light text and vice versa.
> 
> Thus I would like to implement the following pseudo code:
> 
> if (brightness(color) > somevalue) textcolor= dark else textcolor=red
> 
> I am not too familiar with color systems. My idea was to convert the
> hex value to hsv / hsl space and extract the v or l value.
> 1) I am not sure if this is the way to go.
> 2) I do not succeed in it. convertColor {grDevices} or make.rgb
> {grDevices} did not help me with that. How can I convert hex to hsv/
> hsl space
> 
> How would you detect the (perceived) color brightness?
> 
> Thanks
> Mark
> 
> ---------------------------------------
> Mark Heckmann
> Dipl. Wirt.-Ing. cand. Psych.
> Vorstraße 93 B01
> 28359 Bremen
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
> 
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]



More information about the R-help mailing list