Skip to contents

FocalStatistics: moving-window mean, sum, min, max, range, median, sample variance or standard deviation, or Shannon entropy, as terra::focal (cells outside the grid are NA). FilterKernel: mean, binomial, Gaussian, Laplacian, sharpen, Prewitt, Sobel and Gabor kernels. FocalFilter: weighted window sum (correlation) as terra::focal(x, w, fun = "sum"). CannyEdges: Canny (1986) detector. GreyMorphology: erosion, dilation, opening and closing with a flat square element. Identical to the Python arm morie.fn.rastops.

Usage

FocalStatistics(grid, size = 3, fun = "mean", na_rm = FALSE)

FilterKernel(
  name,
  size = 3,
  sigma = 1,
  theta = 0,
  wavelength = 4,
  gamma = 0.5,
  psi = 0
)

FocalFilter(grid, kernel, na_rm = FALSE)

CannyEdges(grid, sigma = 1, low = 0.1, high = 0.2, size = 5)

GreyMorphology(grid, operation, size = 3)

Arguments

grid

Numeric matrix (row 1 = north).

size

Window or kernel size (odd).

fun

Statistic.

na_rm

Drop NA values.

name

Kernel name.

sigma, theta, wavelength, gamma, psi

Gaussian and Gabor parameters.

kernel

Weight matrix.

low, high

Hysteresis thresholds (fractions of the maximum gradient).

operation

"erosion", "dilation", "opening" or "closing".

Value

Matrix.

References

Canny, J. (1986). A computational approach to edge detection. IEEE Transactions on Pattern Analysis and Machine Intelligence 8, 679-698.

Serra, J. (1982). Image Analysis and Mathematical Morphology. Academic Press.

Examples

FocalStatistics(matrix(1:9, 3, byrow = TRUE), fun = "median", na_rm = TRUE)
#>      [,1] [,2] [,3]
#> [1,]  3.0  3.5  4.0
#> [2,]  4.5  5.0  5.5
#> [3,]  6.0  6.5  7.0
FocalFilter(matrix(1:9, 3, byrow = TRUE), FilterKernel("prewitt_x"))[2, 2]
#> [1] 6