convolution2D {imagine} | R Documentation |
This function takes a matrix
object, and for each cell multiplies
its neighborhood by the kernel
. Finally, it returns for each cell the mean of
the kernel-weighted sum.
convolution2D(X, kernel, times = 1) convolutionQuantile(X, kernel, probs, times = 1, na = NA) convolutionMedian(X, kernel, times = 1, na = NA)
X |
A |
kernel |
A little matrix used as mask for each cell of |
times |
How many times do you want to apply the filter? |
probs |
|
na |
|
Convolution is a mathematical operation which allows the multiplication of two arrays of numbers, in order to produce an array of numbers of the same dimensionality. Valid results (showed in output) will be only those with non-NA values, so NA holes on a matrix will expand in the order of the kernel size.
convolution2D
returns a matrix
object with the same dimensions
of X
.
convolutionQuantile
uses the kernel but, for each cell, it returns
the position
of quantile 'probs' (value between 0 and 1).
convolutionMedian
is a wrapper of convolutionQuantile
with
probs = 0.5.
# Generate example matrix nRows <- 50 nCols <- 100 myMatrix <- matrix(runif(nRows*nCols, 0, 100), nrow = nRows, ncol = nCols) kernel <- diag(3) # Make convolution myOutput1 <- convolution2D(myMatrix, kernel) myOutput2 <- convolutionQuantile(myMatrix, kernel, probs = 0.7) # Plot results par(mfrow = c(2, 2)) image(myMatrix, zlim = c(0, 100)) image(myOutput1, zlim = c(0, 100)) image(myOutput2, zlim = c(0, 100))