Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


spatialfil (version 0.15)

applyFilter: Function for applying convolution kernel to a matrix or array

Description

This function applies the a convolution kernel based filter to a matrix or array object type.

Usage

applyFilter(x, kernel)

Arguments

x
An object of class matrix or array
kernel
A matrix containing the values chosen as convolution kernel

Value

An object with the same size of x containing data processed by convolution kernel

Details

The application of a convolution kernel over a 2D matrix dataset allows to apply functions as smoothing or edge detection. The aim of this function is to filter 2D matrices in order to help signal finding across (images-derived) data. It is also possible to filter 3D arrays considering them as slices of a series of images to be processed. Higher dimensions arrays are not allowed. The kernel parameter is a simple square matrix with an odd number of rows/columns, that can be pre-calculated by using the function convKernel. Not square matrices or matrices with even number of rows/columns will exit an error.

Examples

Run this code
## Not run:
M <- array(runif(1000000), dim = c(100,100,100))
# smooth the array M
Mfil <- applyFilter(x = M, kernel = convKernel(sigma = 1.4, k = 'gaussian'))
image(M[,,50], col = grey(1:1000/1000))
image(Mfil[,,50], col = grey(1:1000/1000))

# now combining two filters in cascade
Mfil <- applyFilter(x = applyFilter(x = M, kernel = convKernel(k = 'sobel')),
                    kernel = convKernel(sigma = 1.4, k = 'gaussian'))
image(Mfil[,,50], col = grey(1:1000/1000))
## End(**Not run**)

Run the code above in your browser using DataLab