Learn R Programming

RGISTools (version 0.9.7)

varRGB: Generate an RGB image from 3 spectral bands

Description

varRGB creates red-green-blue (RGB) RasterStack images by scaling the pixel values to 0-255 color range.

Usage

varRGB(red, green, blue, q.range = c(), rPath = NULL, cutline = NULL)

Arguments

red

a raster with the red band of the capture.

green

a raster with the green band of the capture.

blue

a raster with the blue band of the capture.

q.range

a vector with the minimum and maximum reflectance quantiles being considered.

rPath

the file path where the resulting RGB image is saved.

cutline

a SpatialPolygonsDataFrame with the boundary of the region of interest.

Details

The function rescales the original reflectance values to a range of 0-255. The functions re-aranges the RGB bands to create a stack with a RGB image ready to visualize with plotRGB. Bands may contain reflectance outliers which cause the image to look dark. Use the q.range argument to remove the outliers and get a better-looking image.

Examples

Run this code
# NOT RUN {
# path to the cropped and cutted MODIS images for the region of Navarre
img.dir <- system.file("ExNavarreVar", package = "RGISTools")
# list all the tif files
img.files <- list.files(img.dir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE)
# print the MOD09 bands
getRGISToolsOpt("MOD09BANDS")

# select the red, blue and NIR bands
red <- raster(img.files[1])
blue <- raster(img.files[3])
green <- raster(img.files[4])

q.range=c(0.001,0.999)
image<-varRGB(red,green,blue,q.range)
print(plotRGB(image))
# }

Run the code above in your browser using DataLab