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!

  • $\begingroup$ 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 $\endgroup$ – Hilmar Sep 22 '11 at 12:57
  • 1
    $\begingroup$ 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). $\endgroup$ – Trevor Boyd Smith Sep 22 '11 at 14:47
  • 1
    $\begingroup$ 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?". $\endgroup$ – Trevor Boyd Smith Sep 22 '11 at 14:48
  • $\begingroup$ 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. $\endgroup$ – sansuiso May 1 '13 at 7:40

Your erode filter is incorrect. The link you gave says it is supposed to find the maximum of the adjacent pixels, and your array does not do this. Instead, it gives the sum of the adjacent pixels. If you normalize the result (since all these additions will increase the brightness), then you will find that your filter simply evenly averages the adjacent pixels.

What you would generally do is take your image and convolve 3x3 blocks of it (or however big the filter is) with your filter. You can also do these in parallel, for speed.


In image processing, to apply such a filter you would iterate over all pixels of the input image and in each step place the filter mask over the image so that its center is located at your current pixel. You then "evaluate" the pixels in the neighborhood that are covered by the mask in some way and write the result back to the current pixel.

For a normal convolution, you multiply each element of the filter with the value of the corresponding pixel, add up the results and write the sum to the current pixel.

Erosion is a morphological operation, and you would implement it (on a binary image) by checking whether all "1" values of your mask lie over "1" pixels in the image. If so, you write a "1" to the current pixel (otherwise a "0").

In both cases, make sure to always read your input pixels from an umodified version of the image (rather than modifying the image in-place).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.