Many
image processing operations are implemented using a
filter
(or kernel),
which is applied to each pixel in an image.
In
2D filtering, the filter is simply a matrix of values that describe how to
transform a pixel by replacing it with the sum of products between the values
of nearby pixels and the filter weights.
For
example, consider the following 3x3 filter, and a set of pixel values
(grayscale intensities).

To
apply the filter, we simply multiply corresponding elements together and sum
the results.
In
this case, the value would be (25 + 27 + 2*29 + 31 + 33) = 174
Typically
the image is much larger than the filter.
The
filter is moved through the image to produce filtered outputs, which are stored
in a separate buffer.
The
filter can be any size (NxM matrix).