Learn R Programming

spatialfil (version 0.15)

convKernel: Function for creating convolution kernel for different filters

Description

This function creates the convolution kernel for applying a filter to an array/matrix

Usage

convKernel(sigma = 1.4, k = c("gaussian", "LoG", "sharpen", "laplacian",
  "emboss", "sobel"))

Arguments

sigma
The numeric value of standard deviation for the Gaussian or LoG filter
k
character value:
  • gaussianfor Gaussian kernel
  • LoGfor Laplacian of Gaussian kernel
  • sharpenfor 3x3 convolution matrix for sharpening edges
  • laplacianfor a 3x3 con

Value

  • An object of class convKern with the matrix of convolution kernel whose size varies according the value of sigma (in case of gaussian or LoG option selected), and k being the convolution kernel type label

Details

The convolution kernel is a matrix that is used by spacialfil function over a matrix, or array, for filtering the data. Gaussian kernel is calculated starting from the 2 dimension, isotropic, Gaussian distribution: $$G(x)=\frac{1}{2\pi\sigma^{2}}e^{-\frac{x^{2}+y^{2}}{2\sigma^{2}}}$$ Laplacian of Gaussian kernel applies a second derivative to enhance regions of rapid intensity changes: $$LoG\left ( x,y \right )=\frac{-1}{\pi\sigma^{4}}\left ( 1-\frac{x^{2}+y^{2}}{2\sigma^{2}}\right ) e^{-\frac{x^{2}+y^{2}}{2\sigma^{2}}}$$ the use of the underlying Gaussian kernel (so the name Laplacian of Gaussian or LoG) is needed to reduce the effect of high frequency noise that can affect the signal distribution. Laplacian is a Sharpen enhance the detail. Emboss kernel is a 3x3 convolution kernel that embosses the edges. (but also the noise) in original dataset. Sobel convolution kernel returns the possibility to detect edges in a more sofisticated way, the convKernel function returns only one of the two matrices needed to apply the filter. The second one is calculated by transposing the returned matrix in the other needed one.

References

  • gaussiankernelhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm
  • LoGkernel:http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
  • sharpenkernel:https://en.wikipedia.org/wiki/Kernel_(image_processing)
  • laplaciankernel:https://en.wikipedia.org/wiki/Discrete_Laplace_operator
  • embosskernel:http://coding-experiments.blogspot.it/2010/07/convolution.html
  • sobelkernel:https://en.wikipedia.org/wiki/Sobel_operator

Examples

Run this code
## Not run:
# creates a convolution kernel with Gaussian function and sigma = 1.4
K <- convKernel(sigma = 1.4, k = 'gaussian')
plot(K)
## End(**Not run**)

Run the code above in your browser using DataLab