Skip to contents

Set raster extent to physical units

Usage

hsi_set_extent(raster, reference, um_per_pixel, origin = 0, units = "cm")

Arguments

raster

A SpatRaster with hyperspectral data.

reference

A SpatVector with a single point in pixel space that marks the physical origin anchor on the vertical axis.

um_per_pixel

Numeric. Physical size of one pixel in µm.

origin

Numeric. Physical position assigned to reference in µm. Default 0.

units

Character. Output units for the calibrated raster extent. One of "um", "mm", or "cm". Default "cm".

Value

A SpatRaster with a physically calibrated extent.

Details

This keeps the current raster values unchanged, but updates the spatial extent so that downstream plotting and profile extraction work in physical units.

The calibration is linear: the raster grid is converted from pixels to physical units using the supplied micrometers-per-pixel ratio. The horizontal axis starts at the first cell centre, and the vertical axis is anchored to reference at origin.

Importantly, at this stage, calibration metag does not carry forvard into analysis products. Calibrate immediate products, where real world units are necessary.

Examples

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

# Anchor point in pixel space, e.g. the core top in the first column.
reference <- terra::vect(cbind(1, terra::nrow(x)), type = "points")

# 60 µm per pixel, supplied directly.
um <- hsi_calibration_direct(60)

x_cal <- hsi_set_extent(x, reference, um_per_pixel = um, units = "cm")
} # }