Skip to contents

Apply Minimum Noise Fraction transformation to a SpatRaster

Usage

hsi_apply_mnf(x, fit, n = NULL, filename = "", overwrite = FALSE, ...)

Arguments

x

A SpatRaster with hyperspectral data.

fit

An object of class mnf as returned by hsi_calc_mnf().

n

Positive integer. Number of signal-rich MNF components to retain. Inspect fit$values to choose. Default NULL.

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 n MNF component layers.

Details

MNF components are ordered by decreasing noise fraction: the first component carries the most noise and the last carries the most signal. n selects the signal-rich tail, so the output layer MNF_1 always corresponds to the most signal-rich component regardless of the total number of components computed. The internal index reversal is hidden from the user.

x is used only as a spatial template (extent, CRS, resolution). Its band count is irrelevant — only cell count must match nrow(fit$x).

Separating hsi_calc_mnf() from hsi_apply_mnf() means the expensive eigen decomposition runs once; hsi_apply_mnf() can be called repeatedly with different values of n without recomputing the transform.

Examples

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

x_mnf <- hsi_apply_mnf(x, fit = fit, n = 10L)

x_mnf <- hsi_apply_mnf(
  x,
  fit = fit,
  n = 10L,
  filename = "output_mnf.tif",
  overwrite = TRUE
)
} # }