| im.pca | R Documentation |
This function applies Principal Component Analysis (PCA) to a multispectral raster image, extracting principal components from a sample of pixels and projecting the full raster into the PCA space.
im.pca(input_image, n_samples = 100, n_components = 3, plot = TRUE)
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 (default: 3). |
plot |
Logical. If 'TRUE', the resulting principal components are plotted. Default is 'TRUE'. |
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.
- 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 output raster contains the selected principal components. - If 'plot = TRUE', the output is visualized using a 'viridis' color scale.
A 'SpatRaster' object containing the computed principal components.
[im.import()], [im.ggplot()]
library(terra)
# Create a 3-band raster
r <- rast(nrows = 10, ncols = 10, nlyrs = 3)
values(r) <- runif(ncell(r) * 3)
# Perform PCA without plotting
pca_result <- im.pca(r, n_samples = 100, plot = FALSE)
# Plot the first principal component
plot(pca_result[[1]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.