Skip to contents

Subset a hyperspectral raster to three bands and apply a linear or histogram-equalized stretch. Supports predefined band combinations and custom wavelength selection.

Usage

hsi_calc_stretch(
  x,
  type,
  tol = 25,
  histeq = FALSE,
  filename = "",
  overwrite = FALSE,
  ...
)

Arguments

x

A SpatRaster with hyperspectral data. Band names must be numeric wavelengths in nm.

type

Character or numeric. A predefined band combination ("RGB", "CIR", "NIR", "SWIR") or a numeric vector of exactly 3 wavelengths in nm.

tol

Numeric. Wavelength tolerance for band matching in nm. Default 25.

histeq

Logical. Use histogram equalization instead of linear stretch. Default FALSE.

filename

Character. Output filename. Default "" keeps result in memory.

overwrite

Logical. Overwrite existing file. Default FALSE.

...

Additional arguments passed to terra::writeRaster().

Value

A SpatRaster with 3 stretched bands.

Examples

if (FALSE) { # \dontrun{
x <- terra::rast("REFLECTANCE_testdata.tif")

x_stretch <- hsi_calc_stretch(x, type = "RGB")

x_stretch <- hsi_calc_stretch(x, type = c(400, 500, 600))

x_stretch <- hsi_calc_stretch(
  x,
  type = "CIR",
  histeq = TRUE,
  filename = "output_stretch.tif",
  overwrite = TRUE
)
} # }