Learn R Programming

rgdal (version 0.5-1)

SGDF2RGB: Convert RGB three band to single band colour table

Description

This function converts a three-band SpatialGridDataFrame into a single band of colour indices and a colour look-up table. The function is in preliminary form only.

Usage

SGDF2RGB(x, ncolors = 256)

Arguments

x
a three-band SpatialGridDataFrame object
ncolors
a number of colours between 2 and 256

Value

  • The value returned is a list:
  • idxa vector of colour indices in the same spatial order as the input object
  • cta vector of RGB colours

Details

The function makes a system() call to the GDAL utility rgb2pct.py, which is only available if GDAL has been built with Python support. It is hoped to replace this extra dependency with compiled code if the function proves useful.

References

http://www.remotesensing.org/gdal/

Examples

Run this code
logo <- system.file("pictures/Rlogo.jpg", package="rgdal")[1]
  SGlogo <- readGDAL(logo)
  cols <- SGDF2RGB(SGlogo)
  SGlogo$idx <- cols$idx
  image(SGlogo, "idx", col=cols$ct)
  SGlogo <- readGDAL(logo)
  cols <- SGDF2RGB(SGlogo, ncolors=64)
  SGlogo$idx <- cols$idx
  image(SGlogo, "idx", col=cols$ct)

Run the code above in your browser using DataLab