Perhaps some variation of

  SetTextContrastColor <- function(color)
  {
    ifelse( mean(col2rgb(color)) > 127, "black", "white")
  }

Mark Heckmann wrote:
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]]




--
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to