meanFilter {imagine}R Documentation

Make a 2D filter calculations from numeric matrix

Description

This functions take a matrix object, and for each cell calculate mean, median or certain quantile about a squared neighborhood by matrix of dimension (radius*radius).

Usage

meanFilter(X, radius, times = 1)

quantileFilter(X, radius, probs, times = 1, na = NA)

medianFilter(X, radius, times = 1, na = NA)

Arguments

X

A numeric matrix object used for apply filters.

radius

Size of squared kernel to apply median.

times

How many times do you want to apply the filter?

probs

numeric vector of probabilities with values in [0,1].

na

NA as default. But, if specified, it must be an integer value higher than the maximum of X.

Details

Functions use C++ algorithms. More details are shown in the vignette.

Value

A matrix object with the same dimensions of X.

quantileFilter don't use a kernel but, for each cell, it returns the position of quantile 'probs' (value between 0 and 1).

medianFilter is a wrapper of quantileFilter with probs = 0.5.

Examples

# Generate example matrix
nRows <- 50
nCols <- 100

myMatrix <- matrix(runif(nRows*nCols, 0, 100), nrow = nRows, ncol = nCols)
radius <- 3

# Make convolution
myOutput1 <- meanFilter(X = myMatrix, radius = radius)
myOutput2 <- quantileFilter(X = myMatrix, radius = radius, probs = 0.1)
myOutput3 <- medianFilter(X = myMatrix, radius = radius)

# Plot results
par(mfrow = c(2, 2))
image(myMatrix, zlim = c(0, 100), title = "Original")
image(myOutput1, zlim = c(0, 100), title = "meanFilter")
image(myOutput2, zlim = c(0, 100), title = "quantileFilter")
image(myOutput3, zlim = c(0, 100), title = "medianFilter")

[Package imagine version 1.5.2 Index]