meanFilter | R Documentation |
This functions take a matrix
object, and for each cell
calculate mean, median or certain quantile around a squared/rectangular
neighborhood.
meanFilter(X, radius, times = 1, na_only = FALSE)
quantileFilter(X, radius, probs, times = 1, na_only = FALSE)
medianFilter(X, radius, times = 1, na_only = FALSE)
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? |
na_only |
|
probs |
|
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.
na_only
performs two actions at once: (1) it applies the filter only in
the positions where the original value is NA
and (2) for the rest of
the cells, it is replaced with the value of the original matrix.
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
.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.