convertColor            package:grDevices            R Documentation

_C_o_n_v_e_r_t _b_e_t_w_e_e_n _c_o_l_o_u_r _s_p_a_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Convert colours between standard colour space representations.
     This function is experimental.

_U_s_a_g_e:

     convertColor(color, from, to, from.ref.white, to.ref.white,
                  scale.in=1, scale.out=1, clip=TRUE)

_A_r_g_u_m_e_n_t_s:

   color: A matrix whose rows specify colors. 

from,to : Input and output color spaces.  See 'Details' below.

from.ref.white,to.ref.white: Reference whites or 'NULL' if these are
          built in to the definition, as for RGB spaces. 'D65' is the
          default, see 'Details' for others. 

scale.in, scale.out: Input is divided by 'scale.in', output is
          multiplied by 'scale.out'. Use 'NULL' to suppress scaling
          when input or output is not numeric.

    clip: If 'TRUE', truncate RGB output to [0,1], 'FALSE' return
          out-of-range RGB, 'NA' set out of range colors to 'NaN'.

_D_e_t_a_i_l_s:

     Color spaces are specified by objects of class 'colorConverter',
     created by 'colorConverter' or 'make.rgb'. Built-in color spaces
     may be referenced by strings: '"XYZ"', '"sRGB"', '"Apple RGB"',
     '"CIE RGB"', '"Lab"', '"Luv"'. The converters for these colour
     spaces are in the object 'colorspaces'.

     The '"sRGB"' color space is that used by standard PC monitors.
     '"Apple RGB"' is used by Apple monitors. '"Lab"' and '"Luv"' are
     approximately perceptually uniform spaces standardized by the
     Commission Internationale d'Eclairage. 'XYZ' is a 1931 CIE
     standard capable of representing all visible colors (and then
     some), but not in a perceptually uniform way.

     The 'Lab' and 'Luv' spaces describe colors of objects, and so
     require the specification of a reference 'white light' color. 
     Illuminant 'D65' is a standard indirect daylight, Illuminant 'D50'
     is close to direct sunlight, and Illuminant 'A' is the light from
     a standard incandescent bulb. Other standard CIE illuminants
     supported are 'B', 'C', 'E' and 'D55'.  RGB colour spaces are
     defined relative to a particular reference white, and can be only
     approximately translated to other reference whites.  The Bradford
     chromatic adaptation algorithm is used for this.

     The RGB color spaces are specific to a particular class of
     display. An RGB space cannot represent all colors, and the 'clip'
     option controls what is done to out-of-range colors.

_V_a_l_u_e:

     A 3-row matrix whose columns specify the colors.

_R_e_f_e_r_e_n_c_e_s:

     For all the conversion equations <URL:
     http://www.brucelindbloom.com/>

     For the white points <URL:
     http://www.efg2.com/Lab/Graphics/Colors/Chromaticity.htm>

_S_e_e _A_l_s_o:

     'col2rgb' and 'colors' for ways to specify colors in graphics.

     'make.rgb' for specifying other colour spaces.

_E_x_a_m_p_l_e_s:

     require(graphics); require(stats) # for na.omit
     par(mfrow=c(2,2))
     ## The displayable colors from four planes of Lab space
     ab <- expand.grid(a=(-10:15)*10,b=(-15:10)*10)

     Lab <- cbind(L=20,ab)
     srgb <- convertColor(Lab,from="Lab",to="sRGB",clip=NA)
     clipped <- attr(na.omit(srgb),"na.action")
     srgb[clipped,] <- 0
     cols <- rgb(srgb[,1],srgb[,2],srgb[,3])
     image((-10:15)*10,(-15:10)*10,matrix(1:(26*26),ncol=26),col=cols,
       xlab="a",ylab="b",main="Lab: L=20")

     Lab <- cbind(L=40,ab)
     srgb <- convertColor(Lab,from="Lab",to="sRGB",clip=NA)
     clipped <- attr(na.omit(srgb),"na.action")
     srgb[clipped,] <- 0
     cols <- rgb(srgb[,1],srgb[,2],srgb[,3])
     image((-10:15)*10,(-15:10)*10,matrix(1:(26*26),ncol=26),col=cols,
       xlab="a",ylab="b",main="Lab: L=40")

     Lab <- cbind(L=60,ab)
     srgb <- convertColor(Lab,from="Lab",to="sRGB",clip=NA)
     clipped <- attr(na.omit(srgb),"na.action")
     srgb[clipped,] <- 0
     cols <- rgb(srgb[,1],srgb[,2],srgb[,3])
     image((-10:15)*10,(-15:10)*10,matrix(1:(26*26),ncol=26),col=cols,
       xlab="a",ylab="b",main="Lab: L=60")

     Lab <- cbind(L=80,ab)
     srgb <- convertColor(Lab,from="Lab",to="sRGB",clip=NA)
     clipped <- attr(na.omit(srgb),"na.action")
     srgb[clipped,] <- 0
     cols <- rgb(srgb[,1],srgb[,2],srgb[,3])
     image((-10:15)*10,(-15:10)*10,matrix(1:(26*26),ncol=26),col=cols,
       xlab="a",ylab="b",main="Lab: L=80")

     (cols <- t(col2rgb(palette())))
     (lab <- convertColor(cols,from="sRGB",to="Lab",scale.in=255))
     round(convertColor(lab,from="Lab",to="sRGB",scale.out=255))

