library(raster)
library(ggplot2)
library(reshape2)
data(rlogo)
reference <- rlogo
## Shift reference 2 pixels to the right and 3 up
missreg <- shift(reference, x = 2, y = 3)
## Compare shift
p <- ggRGB(reference, NULL, NULL, 3)
p
p + ggRGB(missreg, 3, NULL, NULL, alpha = 0.5, ggLayer=TRUE)
## Coregister images (and report statistics)
coreg <- coregisterImages(missreg, master = reference, nSamples = 500, reportStats = TRUE)
## Plot mutual information per shift
ggplot(coreg$MI) + geom_raster(aes(x,y,fill=mi))
## Plot joint histograms per shift (x/y shift in facet labels)
df <- melt(coreg$jointHist)
df$L1 <- factor(df$L1, levels = names(coreg$jointHist))
df[df$value == 0, "value"] <- NA ## don't display p = 0
ggplot(df) + geom_raster(aes(x = Var2, y = Var1,fill=value)) + facet_wrap(~L1) +
scale_fill_gradientn(name = "p", colours = heat.colors(10), na.value = NA)
## Compare correction
p <- ggRGB(reference, NULL, NULL, 3)
p
p + ggRGB(coreg$coregImg, 3, NULL, NULL, alpha = 0.5, ggLayer=TRUE)Run the code above in your browser using DataLab