| 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 around a squared/rectangular
neighborhood.
Usage
meanFilter(X, radius, times = 1)
quantileFilter(X, radius, probs, times = 1)
medianFilter(X, radius, times = 1)
Arguments
X |
A numeric |
radius |
Size of squared or rectangular kernel to apply median. See Details. |
times |
How many times do you want to apply the filter? |
probs |
|
Details
radius must be defined as a 2-length numeric vector
specifying the number of rows and columns of the window which will be used to
make calculations. If the length of radius is 1, the window will be a square.
Functions use C++ algorithms for running some statistical calculations. The
mean is far obvious, however, there are several ways to perform quantiles.
quantileFilter function uses
arma::quantile: a
RcppArmadillo function, which is equivalent to use R quantile
funtion with type = 5.
medianFilter is a wraper of quantileFilter, so the same
observations are applied to it.
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")