Learn R Programming

fieldRS (version 0.2.3)

pixFilter: pixFilter

Description

Erosion and dilation filter of a raster image.

Usage

pixFilter(x, y, method)

Arguments

x

Object of class RasterLayer.

y

A numeric element.

method

A character element. One of "erode" or "dilate".

Value

A RasterLayer.

Details

Uses focal to filter x using either an erosion or a dilation filter, specified by method. If "erosion" is chosen, the function will identify and filter out border pixels around each cluster of pixels in x. Small or isolated groups of pixels will also be removed. If "dilation" is set, the function will increase the size of each cluster of pixels and simultaneously remove all gaps within them. The size of the buffer used in this function is defined by y and is expressed in number of pixels.

Examples

Run this code
# NOT RUN {
{

require(raster)

# read raster data
r <- raster(system.file("extdata", "ndvi.tif", package="fieldRS")) > 2000
r[r == 0] <- NA

# filter image (3x3 erosion)
or <- pixFilter(r, 1, "erode")
plot(r)
plot(or)

#' # filter image (3x3 dilation)
or <- pixFilter(r, 1, "dilate")
plot(r)
plot(or)

}
# }

Run the code above in your browser using DataLab