Linear stretch of values in a Raster object. Provide the desired output range (minv and maxv) and the lower and upper bounds in the original data, either as quantiles (if minq=0
and maxq=1
you use the minimum and maximum cell values), or as actual values (smin
and smax
; e.g. precomputed quantile values). If smin
and smax
are both not NA
, minq
and maxq
are ignored.
# S4 method for Raster
stretch(x, minv=0, maxv=255, minq=0, maxq=1, smin=NA, smax=NA,
samplesize=1000000, filename='', ...)
Raster
Raster object
numeric >= 0 and smaller than maxv. lower bound of stretched value
numeric <= 255 and larger than maxv. upper bound of stretched value
numeric >= 0 and smaller than maxq. lower quantile bound of original value. Ignored if smin is supplied
numeric <= 1 and larger than minq. upper quantile bound of original value. Ignored if smax is supplied
numeric < smax. user supplied lower value for the layers, to be used instead of a quantile computed by the function itself
numeric > smin. user supplied upper value for the layers, to be used instead of a quantile computed by the function itself
numeric > 1. If samplesize < ncell(x), a regular sample of samplesize is taken from x to compute the quantiles (to speed things up)
character. Filename for the output Raster object (optional)
additional arguments as for writeRaster
stretch argument in plotRGB
r <- raster(nc=10, nr=10)
values(r) <- rep(1:2, 50)
stretch(r)
s <- stack(r, r*2)
stretch(s)
Run the code above in your browser using DataLab