rescaleImage: Linear Image Rescaling

View source: R/rescaleImage.R

rescaleImageR Documentation

Linear Image Rescaling

Description

performs linear shifts of value ranges either to match min/max of another image (y) or to any other min and max value (ymin and ymax).

Usage

rescaleImage(x, y, xmin, xmax, ymin, ymax, forceMinMax = FALSE, ...)

Arguments

x

SpatRaster or numeric vector. Image to normalise.

y

SpatRaster or numeric vector. Reference image. Optional. Used to extract min and max values if ymin or ymax are missing.

xmin

Numeric. Min value of x. Either a single value or one value per layer in x. If xmin is not provided it will be extracted from x.

xmax

Numeric. Max value of x. Either a single value or one value per layer in x. If xmax is not provided it will be extracted from x.

ymin

Numeric. Min value of y. Either a single value or one value per layer in x. If ymin is not provided it will be extracted from y.

ymax

Numeric. Max value of y. Either a single value or one value per layer in x. If ymax is not provided it will be extracted from y.

forceMinMax

Logical. Forces update of min and max data slots in x or y.

...

additional arguments passed to terra::writeRaster()

Details

Providing xmin and xmax values manually can be useful if the raster contains a variable of a known, fixed value range, e.g. NDVI from -1 to 1 but the actual pixel values don't encompass this entire range. By providing xmin = -1 and xmax = 1 the values can be rescaled to any other range, e.g. 1 to 100 while comparability to other rescaled NDVI scenes is retained.

Value

Returns a SpatRaster of the same dimensions as the input raster x but shifted and stretched to the new limits.

See Also

histMatch

Examples

lsat2 <- lsat - 1000
lsat2

## Rescale lsat2 to match original lsat value range
lsat2_rescaled <- rescaleImage(lsat2, lsat)
lsat2_rescaled

## Rescale lsat to value range [0,1]
lsat2_unity <- rescaleImage(lsat2, ymin = 0, ymax = 1)
lsat2_unity

RStoolbox documentation built on May 29, 2024, 6:34 a.m.