provides different methods for pan sharpening a coarse resolution (typically multispectral) image with a higher reolution panchromatic image. Values of the pan-chromatic and multispectral images must be of the same scale, (e.g. from 0:1, or all DNs from 0:255)
panSharpen(img, pan, r, g, b, pc = 1, method = "brovey", norm = TRUE)
pan-sharpened SpatRaster
SpatRaster. Coarse resolution multispectral image
SpatRaster. High resolution image, typically panchromatic.
Character or Integer. Red band in img
. Only relevant if method!='pca'
Character or Integer. Green band in img
. Only relevant if method!='pca'
Character or Integer. Blue band in img
. Only relevant if method!='pca'
Integer. Only relevant if method = 'pca'
. Which principal component to replace. Usually this should be the first component (default). Only if the first component is dominated by something else than brightness it might be worth a try to use the second component.
Character. Choose method from c("pca", "ihs", "brovey").
Logical. Rescale pan image to match the 1st PC component. Only relevant if method = 'pca'
. If TRUE
only min and max are matched to the 1st PC. If FALSE
pan will be histogram matched to the 1st PC.
Pan sharpening options:
method='pca'
: Performs a pca using rasterPCA. The first component is then swapped for the pan band an the PCA is rotated backwards.
method='ihs'
: Performs a color space transform to Intensity-Hue-Saturation space, swaps intensity for the histogram matched pan and does the backwards transformation.
method='brovey'
: Performs Brovey reweighting. Pan and img must be at the same value scale (e.g. 0:1, or 0:255) otherwise you'll end up with psychodelic colors.
library(terra)
library(ggplot2)
## Fake panchromatic image (30m resolution covering
## the visible range (integral from blue to red))
pan <- sum(lsat[[1:3]])
ggR(pan, stretch = "lin")
## Fake coarse resolution image (150m spatial resolution)
lowResImg <- aggregate(lsat, 5)
## Brovey pan sharpening
lowResImg_pan <- panSharpen(lowResImg, pan, r = 3, g = 2, b = 1, method = "brovey")
lowResImg_pan
## Plot
ggRGB(lowResImg, stretch = "lin") + ggtitle("Original")
ggRGB(lowResImg_pan, stretch="lin") + ggtitle("Pansharpened (Brovey)")
Run the code above in your browser using DataLab