1\name{SGDF2PCT}
2\alias{SGDF2PCT}
3\alias{vec2RGB}
4%- Also NEED an '\alias' for EACH other topic documented here.
5\title{Convert RGB three band to single band colour table}
6\description{
7  This function converts a three-band SpatialGridDataFrame into a single band of colour indices and a colour look-up table using \code{RGB2PCT}. \code{vec2RGB} uses given breaks and colours (like \code{image}) to make a three column matrix of red, green, and blue values for a numeric vector.
8}
9\usage{
10SGDF2PCT(x, ncolors = 256, adjust.bands=TRUE)
11vec2RGB(vec, breaks, col)
12}
13%- maybe also 'usage' for other objects documented here.
14\arguments{
15  \item{x}{a three-band SpatialGridDataFrame object}
16  \item{ncolors}{a number of colours between 2 and 256}
17  \item{adjust.bands}{default TRUE; if FALSE the three bands must lie each between 0 and 255, but will not be streched within those bounds}
18  \item{vec}{a numeric vector}
19  \item{breaks}{a set of breakpoints for the colours: must give one more breakpoint than colour}
20  \item{col}{a list of colors}
21}
22
23\value{
24The value returned is a list:
25  \item{idx}{a vector of colour indices in the same spatial order as the input object}
26  \item{ct}{a vector of RGB colours}
27}
28\references{\url{https://gdal.org/}}
29\author{Roger Bivand}
30
31\examples{
32logo <- system.file("pictures/Rlogo.jpg", package="rgdal")[1]
33SGlogo <- readGDAL(logo)
34cols <- SGDF2PCT(SGlogo)
35SGlogo$idx <- cols$idx
36image(SGlogo, "idx", col=cols$ct)
37SGlogo <- readGDAL(logo)
38cols <- SGDF2PCT(SGlogo, ncolors=64)
39SGlogo$idx <- cols$idx
40image(SGlogo, "idx", col=cols$ct)
41SGlogo <- readGDAL(logo)
42cols <- SGDF2PCT(SGlogo, ncolors=8)
43SGlogo$idx <- cols$idx
44image(SGlogo, "idx", col=cols$ct)
45data(meuse.grid)
46coordinates(meuse.grid) <- c("x", "y")
47gridded(meuse.grid) <- TRUE
48fullgrid(meuse.grid) <- TRUE
49summary(meuse.grid$dist)
50opar <- par(no.readonly=TRUE)
51par(mfrow=c(1,2), mar=c(1,1,1,1)+0.1)
52image(meuse.grid, "dist", breaks=seq(0,1,1/10), col=bpy.colors(10))
53RGB <- vec2RGB(meuse.grid$dist, breaks=seq(0,1,1/10), col=bpy.colors(10))
54summary(RGB)
55meuse.grid$red <- RGB[,1]
56meuse.grid$green <- RGB[,2]
57meuse.grid$blue <- RGB[,3]
58cols <- SGDF2PCT(meuse.grid[c("red", "green", "blue")], ncolors=10,
59 adjust.bands=FALSE)
60is.na(cols$idx) <- is.na(meuse.grid$dist)
61meuse.grid$idx <- cols$idx
62image(meuse.grid, "idx", col=cols$ct)
63par(opar)
64# Note: only one wrongly classified pixel after NA handling/dropping
65# The functions are not written to be reversible
66sort(table(findInterval(meuse.grid$dist, seq(0,1,1/10), all.inside=TRUE)))
67sort(table(cols$idx))
68}
69\keyword{spatial}
70