im.pca {imageRy}R Documentation

Perform Principal Component Analysis (PCA) on a Raster Image

Description

This function applies Principal Component Analysis (PCA) to a multispectral raster image, extracting all available principal components. It reduces dimensionality while preserving the most important variance in the dataset.

Usage

im.pca(input_image, n_samples = 100, n_components = 3)

Arguments

input_image

A 'SpatRaster' object representing the input multispectral image.

n_samples

An integer specifying the number of random samples used for PCA computation (default: 100).

n_components

Number of principal components to compute.

Details

Principal Component Analysis (PCA) is a statistical technique used to transform correlated raster bands into a set of orthogonal components, capturing the most variance in fewer bands.

- The function **automatically determines** the number of components based on the number of bands. - A sample of 'n_samples' pixels is used to compute the PCA transformation. - The **full image** is then projected onto the principal component space. - The resulting raster contains **all computed principal components**. - The output is visualized using a 'viridis' color scale.

Value

A 'SpatRaster' object containing all computed principal components.

See Also

[im.import()], [im.ggplot()]

Examples

library(terra)
library(viridis)

# Create a 3-band raster
r <- rast(nrows = 10, ncols = 10, nlyrs = 3)
values(r) <- runif(ncell(r) * 3)

# Perform PCA
pca_result <- im.pca(r, n_samples = 100)

# Plot the first principal component
plot(pca_result[[1]])


[Package imageRy version 0.3.0 Index]