Image to Image Contrast Matching
Performs image to image contrast adjustments based on histogram matching using empirical cumulative distribution functions from both images.
histMatch(x, ref, xmask = NULL, refmask = NULL, nSamples = 1e+05, intersectOnly = TRUE, paired = TRUE, forceInteger = FALSE, returnFunctions = FALSE, ...)
x |
Raster*. Source raster which is to be modified. |
ref |
Raster*. Reference raster, to which x will be matched. |
xmask |
RasterLayer. Mask layer for |
refmask |
RasterLayer. Mask layer for |
nSamples |
Integer. Number of random samples from each image to build the histograms. |
intersectOnly |
Logical. If |
paired |
Logical. If |
forceInteger |
Logical. Force integer output. |
returnFunctions |
Logical. If |
... |
Further arguments to be passed to writeRaster. |
A Raster* object of x
adjusted to the histogram of ref
. If returnFunctions = TRUE
a list of functions (one for each layer) will be returned instead.
x
and ref
must have the same number of layers.
Richards and Jia: Remote Sensing Digital Image Analysis. Springer, Berlin, Heidelberg, Germany, 439pp.
library(ggplot2) library(raster) data(rlogo) ## Original image a (+1 to prevent log(0)) img_a <- rlogo + 1 ## Degraded image b img_b <- log(img_a) ## Cut-off half the image (just for better display) img_b[, 1:50] <- NA ## Compare Images before histMatching ggRGB(img_a,1,2,3)+ ggRGB(img_b, 1,2,3, ggLayer = TRUE, stretch = "lin", q = 0:1) + geom_vline(aes(xintercept = 50))+ ggtitle("Img_a vs. Img_b") ## Do histogram matching img_b_matched <- histMatch(img_b, img_a) ## Compare Images after histMatching ggRGB(img_a, 1, 2, 3)+ ggRGB(img_b_matched, 1, 2, 3, ggLayer = TRUE, stretch = "lin", q = 0:1) + geom_vline(aes(xintercept = 50))+ ggtitle("Img_a vs. Img_b_matched") ## Histogram comparison opar <- par(mfrow = c(1, 3), no.readonly = TRUE) img_a[,1:50] <- NA redLayers <- stack(img_a, img_b, img_b_matched)[[c(1,4,7)]] names(redLayers) <- c("img_a", "img_b", "img_b_matched") hist(redLayers) ## Reset par par(opar)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.