SGDF2PCT                package:rgdal                R Documentation

_C_o_n_v_e_r_t _R_G_B _t_h_r_e_e _b_a_n_d _t_o _s_i_n_g_l_e _b_a_n_d _c_o_l_o_u_r _t_a_b_l_e

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

     This function converts a three-band SpatialGridDataFrame into a
     single band of colour indices and a colour look-up table using
     'RGB2PCT'. 'vec2RGB' uses given breaks and colours (like 'image')
     to make a three column matrix of red, green, and blue values for a
     numeric vector.

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

     SGDF2PCT(x, ncolors = 256, adjust.bands=TRUE)
     vec2RGB(vec, breaks, col)

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

       x: a three-band SpatialGridDataFrame object

 ncolors: a number of colours between 2 and 256

adjust.bands: default TRUE; if FALSE the three bands must lie each
          between 0 and 255, but will not be streched within those
          bounds

     vec: a numeric vector

  breaks: a set of breakpoints for the colours: must give one more
          breakpoint than colour

     col: a list of colors

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

     The value returned is a list: 

     idx: a vector of colour indices in the same spatial order as the
          input object

      ct: a vector of RGB colours

_A_u_t_h_o_r(_s):

     Roger Bivand

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

     <URL: http://www.gdal.org/>

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

     logo <- system.file("pictures/Rlogo.jpg", package="rgdal")[1]
     SGlogo <- readGDAL(logo)
     cols <- SGDF2PCT(SGlogo)
     SGlogo$idx <- cols$idx
     image(SGlogo, "idx", col=cols$ct)
     SGlogo <- readGDAL(logo)
     cols <- SGDF2PCT(SGlogo, ncolors=64)
     SGlogo$idx <- cols$idx
     image(SGlogo, "idx", col=cols$ct)
     SGlogo <- readGDAL(logo)
     cols <- SGDF2PCT(SGlogo, ncolors=8)
     SGlogo$idx <- cols$idx
     image(SGlogo, "idx", col=cols$ct)
     data(meuse.grid)
     coordinates(meuse.grid) <- c("x", "y")
     gridded(meuse.grid) <- TRUE
     fullgrid(meuse.grid) <- TRUE
     summary(meuse.grid$dist)
     opar <- par(no.readonly=TRUE)
     par(mfrow=c(1,2), mar=c(1,1,1,1)+0.1)
     image(meuse.grid, "dist", breaks=seq(0,1,1/10), col=bpy.colors(10))
     RGB <- vec2RGB(meuse.grid$dist, breaks=seq(0,1,1/10), col=bpy.colors(10))
     summary(RGB)
     meuse.grid$red <- RGB[,1]
     meuse.grid$green <- RGB[,2]
     meuse.grid$blue <- RGB[,3]
     cols <- SGDF2PCT(meuse.grid[c("red", "green", "blue")], ncolors=10, adjust.bands=FALSE)
     is.na(cols$idx) <- is.na(meuse.grid$dist)
     meuse.grid$idx <- cols$idx
     image(meuse.grid, "idx", col=cols$ct)
     par(opar)
     # Note: only one wrongly classified pixel after NA handling/dropping
     # The functions are not written to be reversible
     sort(table(findInterval(meuse.grid$dist, seq(0,1,1/10), all.inside=TRUE)))
     sort(table(cols$idx))

