Ops.focal_mean: Low-pass spatial filter for image.

focal_meanR Documentation

Low-pass spatial filter for image.

Description

Low-pass filtering by a square window in the image processing. Focal operation of map algebra. Weight of pixels is proportional to cell area inside of focal window.

Usage

focal_mean(x, size = 3.0, cover = 1e-06, fillNA = FALSE, saveMargin = TRUE
          ,noNA = TRUE, verbose = 0L)

Arguments

x

Object of class ursaRaster.

size

Positive numeric. Size of square focal window. Fractional values are allowed. If size is not odd (3, 5, 7, ...), then window size is expanded to the nearest odd value not less than original value, and pixels on border are taken with the weight, which is proportional to the cell area inside of original size. Default size=3.

cover

Numeric. 0<=cover<=1. Quota for NA values in the focal window in relation to all values. Values are taken with the weight proportional of cell areas inside of 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.

noNA

Logical. If TRUE then NA values are transformed to numerical constant, which is interpreted as "no data" value. Filter without NA values has more perfomance, and generally filter with pre- and post-transformations of NA values have more perfomance too. 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.

Details

The reference is always central pixel, even if window size is even.

If size=3 then multiplicator is 3^(-2) and elements have equal weights:

     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    1    1    1

If size=2 then multiplicator is 2^(-2) and weights of elements are:

     [,1] [,2] [,3]
[1,] 0.25 0.50 0.25
[2,] 0.50 1.00 0.50
[3,] 0.25 0.50 0.25

If size=3.4 then multiplicator is 3.4^(-2) and weights of elements are:

     [,1] [,2] [,3] [,4] [,5]
[1,] 0.04 0.20 0.20 0.20 0.04
[2,] 0.20 1.00 1.00 1.00 0.20
[3,] 0.20 1.00 1.00 1.00 0.20
[4,] 0.20 1.00 1.00 1.00 0.20
[5,] 0.04 0.20 0.20 0.20 0.04

Value

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

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
a <- ursa_dummy(nband=1,mul=1/8,elements=0)
a[a<80] <- NA
print(a)
b1 <- focal_mean(a,size=6,cover=0.5,saveMargin=FALSE)
b2 <- focal_mean(a,size=6,cover=0.5,saveMargin=TRUE)
b3 <- focal_mean(a,size=6,cover=0.5,saveMargin=TRUE,fillNA=TRUE)
print(b3-a)
display(c(a,b1,b2,b3),blank.angle=c(-45,45),blank.density=20)

ursa documentation built on Oct. 17, 2023, 5:11 p.m.