Learn R Programming

ursa (version 3.9.4)

focal_median: Median spatial filter for image

Description

For each band and for each cell, function finds median value inside of square window. Focal operation of map algebra.

Usage

focal_median(x, size = 3, cover = 1e-06, fillNA = FALSE, saveMargin = TRUE, verbose = 0L)

Arguments

x

Object of class ursaRaster.

size

Positive numeric. Odd values (3, 5, 7, …) are allowed, but if other value is specified, then it expanded to the next odd value not less than original value. Default is 3L.

cover

Numeric. 0<=cover<=1. Quota for NA values in the focal window in relation to the squared size of the focal window. Quota exceeding leads to recording NA value in the cell. Default is cover=1e-6.

fillNA

Logical. If TRUE then only NA values of source image can be changed, and non-NA values of source image are kept without changes. It may provide less reducing of spatial resolution in the task of spatial interpolation. Default is FALSE.

saveMargin

Logical. If TRUE then adaptive window size is used for cells, where original window goes over image boundary. If FALSE then image is expanded to the half size of focal window by NA values and argument cover is applied to this expanded part. Default is TRUE.

verbose

Integer of 0L, 1L, or 2L, or logical, which is coerced to integer. The level of verbosity. Values >0 provide some additional information on console, verbose=1L is less detailed, verbose=2L is more detailed. Default is 0L.

Value

Object of class ursaRaster with the same number of bands as in input raster.

See Also

Other focal operations: focal_mean, focal_extrem.

Examples

Run this code
# NOT RUN {
session_grid(NULL)
a <- ursa_dummy(1,mul=1/8,elements=0,bandname="src")
a[a<80] <- NA
bF <- c(fillNA.F=focal_median(a[1],size=5,cover=0.5,fillNA=FALSE))
bT <- c(fillNA.T=focal_median(a[1],size=5,cover=0.5,fillNA=TRUE))
print(c(diff=bT-bF))
d <- c(a,bF,bT)
print(d)
display(d)
# }

Run the code above in your browser using DataLab