Learn R Programming

mapview (version 1.1.0)

slideView: slideView

Description

Two images are overlaid and a slider is provided to interactively compare the two images in a before-after like fashion. img1 and img2 can either be two RasterLayers, two RasterBricks/Stacks or two character strings. In the latter case it is assumed that these point to .png images on the disk.

This is a modified implementation of http://bl.ocks.org/rfriberg/8327361

Usage

"slideView"(img1, img2, r = 3, g = 2, b = 1, na.color = mapviewGetOption("na.color"), maxpixels = mapviewGetOption("plainview.maxpixels"), ...)
"slideView"(img1, img2, col.regions = mapviewGetOption("raster.palette")(256), na.color = mapviewGetOption("na.color"), maxpixels = mapviewGetOption("plainview.maxpixels"))
"slideView"(img1, img2)
"slideview"(...)

Arguments

img1
a RasterStack/Brick, RasterLayer or path to a .png file
img2
a RasterStack/Brick, RasterLayer or path to a .png file
r
integer. Index of the Red channel, between 1 and nlayers(x)
g
integer. Index of the Green channel, between 1 and nlayers(x)
b
integer. Index of the Blue channel, between 1 and nlayers(x)
na.color
the color to be used for NA pixels
maxpixels
integer > 0. Maximum number of cells to use for the plot. If maxpixels < ncell(x), sampleRegular is used before plotting.
...
additional arguments passed on to repective functions.
col.regions
color (palette).See levelplot for details.
color
the color palette to be used for visualising RasterLayers

Methods (by class)

  • img1 = RasterLayer,img2 = RasterLayer: for RasterLayers
  • img1 = character,img2 = character: for png files
  • ANY: alias for ease of typing

Details

Compare two images trough interactive swiping overlay

Examples

Run this code
### raster data ###
library(sp)
library(raster)

data(poppendorf)

stck1 <- subset(poppendorf, c(3, 4, 5))
stck2 <- subset(poppendorf, c(2, 3, 4))
slideView(stck1, stck2)

## Not run: 
# ### example taken from
# ### http://www.news.com.au/technology/environment/nasa-images-reveal-
# ### aral-sea-is-shrinking-before-our-eyes/story-e6frflp0-1227074133835
# 
# library(jpeg)
# library(raster)
# 
# web_img2000 <- "http://cdn.newsapi.com.au/image/v1/68565a36c0fccb1bc43c09d96e8fb029"
# 
# jpg2000 <- readJPEG(readBin(web_img2000, "raw", 1e6))
# 
# # Convert imagedata to raster
# rst_blue2000 <- raster(jpg2000[, , 1])
# rst_green2000 <- raster(jpg2000[, , 2])
# rst_red2000 <- raster(jpg2000[, , 3])
# 
# img2000 <- brick(rst_red2000, rst_green2000, rst_blue2000)
# 
# web_img2013 <- "http://cdn.newsapi.com.au/image/v1/5707499d769db4b8ec76e8df61933f2a"
# 
# jpg2013 <- readJPEG(readBin(web_img2013, "raw", 1e6))
# 
# # Convert imagedata to raster
# rst_blue2013 <- raster(jpg2013[, , 1])
# rst_green2013 <- raster(jpg2013[, , 2])
# rst_red2013 <- raster(jpg2013[, , 3])
# 
# img2013 <- brick(rst_red2013, rst_green2013, rst_blue2013)
# 
# slideView(img2000, img2013)
# ## End(Not run)

Run the code above in your browser using DataLab