im.ndvi {imageRy}R Documentation

Compute the Normalized Difference Vegetation Index (NDVI)

Description

This function calculates the Normalized Difference Vegetation Index (NDVI) from a multispectral raster image. NDVI is a widely used vegetation index that assesses plant health by comparing Near-Infrared (NIR) and Red bands.

Usage

im.ndvi(x, nir, red)

Arguments

x

A 'SpatRaster' object representing the input multispectral image.

nir

An integer specifying the band index of the Near-Infrared (NIR) channel.

red

An integer specifying the band index of the Red channel.

Details

NDVI is calculated as:

NDVI = (NIR - Red) / (NIR + Red)

where: - **High NDVI values (~1)** indicate healthy, dense vegetation. - **Low NDVI values (~0 or negative)** indicate barren land, water bodies, or unhealthy vegetation.

**Important:** - Ensure that 'nir' and 'red' correspond to the correct band indices in your raster image. - Pixels with (NIR + Red) = 0 will result in 'NaN' values.

Value

A 'SpatRaster' object containing the computed NDVI values, ranging from -1 to 1.

References

For more details on NDVI, see: https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index

See Also

[im.dvi()], [im.classify()]

Examples

library(terra)

# Create a dummy 3-band raster (e.g., NIR = band 3, Red = band 2)
r <- rast(nrows = 10, ncols = 10, nlyrs = 3)
values(r) <- runif(ncell(r) * 3)

# Compute NDVI using bands 3 (NIR) and 2 (Red)
ndvi_raster <- im.ndvi(r, nir = 3, red = 2)

# Plot the result
plot(ndvi_raster)

[Package imageRy version 0.3.0 Index]