# How to apply a filter kernel

A filter that can be used for digital signals like audio, video or image processing can be defined using a matrix ("kernel") that weights the surrounding area (this is a description I read in lecture notes from someone else).

The kernel $$\left(\begin{array}{ccc} 1 & 1 & 1 \\ 1 & 1 & 1\\ 1 & 1 & 1\end{array}\right)$$ defines an erode filter.

Could you please tell me how this kernel is applied to e.g. an image (and therefore a 2D field of pixels)? Thank you in advance!

• The term erode "filter" is a little bit of a misnomer here as it's a highly non-linear operation. Filter in the more stringent sense refers to a linear time invariant operation. Convolution with a kernel is a filter, applying the erode process isn't – Hilmar Sep 22 '11 at 12:57
• IMO, the answer is one line: convolution. Research convolution and the math equation and implementation of convolution and that is done. (in this case you would do 2d convolution). – Trevor Boyd Smith Sep 22 '11 at 14:47
• I think the real question should be "how do you filter something with an FIR filter?" or "how does convolution work?" or "how do you implement convolution?". – Trevor Boyd Smith Sep 22 '11 at 14:48
• This is not a kernel, but a structuring element. Hence, it is applied completely differently. See @kolentebert's answer below. Simply speaking, it is a shape that you overlay on an image to extract local maxima/minima. – sansuiso May 1 '13 at 7:40