Compute or extract an index layer from a multi-band mosaic raster.
Usage
mosaic_index(
mosaic,
index = "R",
r = 3,
g = 2,
b = 1,
re = NA,
nir = NA,
swir = NA,
tir = NA,
plot = TRUE,
in_memory = TRUE,
workers = 1
)
Arguments
- mosaic
A mosaic of class
SpatRaster
, generally imported withmosaic_input()
.- index
A character value (or a vector of characters) specifying the target mode for conversion to a binary image. Use
pliman_indexes_rgb()
andpliman_indexes_me()
to see the available RGB and multispectral indexes, respectively. Users can also calculate their own index usingR, G, B, RE, NIR, SWIR, and TIR
bands (eg.,index = "R+B/G"
) or using the names of the mosaic's layers (ex., "(band_1 + band_2) / 2").- r, g, b, re, nir, swir, tir
The red, green, blue, red-edge, near-infrared, shortwave Infrared, and thermal infrared bands of the image, respectively. By default, the function assumes a BGR as input (b = 1, g = 2, r = 3). If a multispectral image is provided up to seven bands can be used to compute built-in indexes. There are no limitation of band numbers if the index is computed using the band name.
- plot
Plot the computed index? Defaults to
TRUE
.- in_memory
Logical, indicating whether the indexes should be computed in memory. Defaults to
TRUE
. In most cases, this is 2-3 times faster, but errors can occur ifmosaic
is a largeSpatRaster
. IfFALSE
, raster algebra operations are performed on temporary files.- workers
numeric. The number of workers you want to use for parallel processing when computing multiple indexes.
Details
This function computes or extracts an index layer from the input
mosaic raster based on the specified index name. If the index is not found
in the package's predefined index list (see image_index()
for more
details), it attempts to compute the index using the specified band
indices. The resulting index layer is returned as an SpatRaster
object.
Examples
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
names(mosaic)
elev2 <- mosaic_index(mosaic, "elevation * 5", plot = FALSE)
oldpar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
mosaic_plot(mosaic)
mosaic_plot(elev2)
# return the original parameters
par(oldpar)
}
#> Warning: The current raster is in the lat/lon coordinate system, which may result in processing errors when trying to segment individuals in the `mosaic_analyze()` function. It is highly suggested to reproject the raster using mosaic_project() with EPSG:32632
#> class : SpatRaster
#> dimensions : 90, 95, 1 (nrow, ncol, nlyr)
#> resolution : 0.008333333, 0.008333333 (x, y)
#> extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source : elev.tif
#> name : elevation
#> min value : 141
#> max value : 547
#> Index 'elevation * 5' is not available. Trying to compute your own index.