|
Source: (implementation largely custom); [PITA00:122-124], [LIND91:367-370], [DAVI98:60-62], [BORO97]
The easiest way to understand convolution filters is to think of it as a weighted summation, or average. A convolution is done like any other area process filter, in that the surrounding pixels of a certain original pixel are used to calculate the value of the corresponding filtered pixel. We have already seen one type of convolution, the standard blur. In the blur, each of the surrounding pixels had equal weight, but the weight of the surrounding pixels in determining an average would not have to be equal.
In a convolution filter, a convolution kernel is defined, usually as a 3x3 or 5x5 matrix. The entries (positive or negative integers) in the matrix are the weights given to the pixels that surround the center pixel (which corresponds to the center matrix element). Basically, for a particular pixel, the surrounding pixels are multiplied by the corresponding coefficient in the convolution kernel and summed together. In my implementation, this summation is divided by the sum of the coefficients of the convolution kernel in order to produce a weighted average (if the sum of the coefficients is less than or equal to zero, no divide takes place). The weighted average is the value given to the corresponding filtered pixel. This is repeated for every pixel in the image:
sum = sum of coefficients in kernel;
divide each element in kernel by sum;
for every pixel in the image do
{
R = G = B = 0;
for every pixel in radius r surrounding the center pixel do
{
R += currentpixel.r *
corrspd kernel value;
G += currentpixel.g *
corrspd kernel value;
B += currentpixel.b *
corrspd kernel value;
}
filterpixel.r = R;
filterpixel.g = G;
filterpixel.b = B;
}

Figure 3: Convolution,
LIND91:368]
So where is this kernel defined? Well, I chose to call this ‘custom convolution’ because the user defines the kernel coefficients. The custom convolution dialog is a 5x5 matrix of edit boxes. Negative or positive integer values can be entered in the matrix; this matrix is the kernel. I have listed some convolution kernels below and the effects they produce. The design of these kernels is based on high level mathematics and is beyond the scope of this report.
Blur:
1 1 1 1 2 1
1 1 1 2 4 2
1 1 1 1 2 1
Sharpen:
-1 -1 -1 0 -1 0
-1 9 -1 -1 5 -1
-1 -1 -1 0 -1 0
Edge Enhancement: 0 0 0
0 -1 0 -1 0 0
-1 1 0 0 1 0
0 1 0
0 0 0 0 0 0
0 0 0
Find Edges:
0 1 0 -1 -1 -1
1 -2 1
1 -4 1 -1 8 -1
-2 4 -2
0 1 0 -1 -1 -1
1 -2 1
Emboss:
-2 -1 0
-1 1 1
0 1 2
Figure 3: Convolution

Convolution using edge enhancement kernel
(third edge enhancement from above)

Convolution using shadow kernel
Return to
the list of filters
|