RGB {terra} | R Documentation |
Layers representing colors
Description
With RGB
you can get or set the layers to be used as Red, Green and Blue when plotting a SpatRaster. Currently, a benefit of this is that plot
will send the object to plotRGB
. You can also associated the layers with another color space (HSV, HSI or HSL)
With colorize
you can convert a three-layer RGB SpatRaster into other color spaces. You can also convert it into a single-layer SpatRaster with a color-table.
Usage
## S4 method for signature 'SpatRaster'
RGB(x)
## S4 replacement method for signature 'SpatRaster'
RGB(x, ..., type="rgb")<-value
## S4 method for signature 'SpatRaster'
colorize(x, to="hsv", alpha=FALSE, stretch=NULL,
grays=FALSE, NAzero=FALSE, filename="", overwrite=FALSE, ...)
## S4 method for signature 'SpatRaster'
has.RGB(x, strict=TRUE)
Arguments
x |
SpatRaster |
value |
vector of three (or four) positive integers indicating the layers that are red, green and blue (and optionally a fourth transparency layer). Or |
type |
character. The color space. One of "rgb" "hsv", "hsi" and "hsl" |
to |
character. The color space to transform the values to. If |
alpha |
logical. Should an alpha (transparency) channel be included? Only used if |
stretch |
character. Option to stretch the values to increase contrast: "lin" (linear) or "hist" (histogram). Only used for transforming RGB to col |
grays |
logical. If |
NAzero |
logical. If |
strict |
logical. If |
filename |
character. Output filename |
overwrite |
logical. If |
... |
additional arguments for writing files as in |
Examples
r <- rast(system.file("ex/logo.tif", package="terra"))
plot(r)
has.RGB(r)
RGB(r) <- NULL
has.RGB(r)
plot(r)
RGB(r) <- c(3,1,2)
plot(r)
RGB(r) <- 1:3
x <- colorize(r, "col")
y <- colorize(r, "hsv")
z <- colorize(y, "rgb")