by the operators of smaller size. Note that the larger operators leave a larger border (since new
values cannot be computed in that region) and this can be seen in the increase in border size for
the larger operators, in Figure 3.15(b) and (c).
3.4.4 Gaussian averaging operator
The Gaussian averaging operator has been considered to be optimal for image smoothing. The
template for the Gaussian operator has values set by the Gaussian relationship. The Gaussian
function g at coordinates x y is controlled by the variance
2
according to:
gx y  =
1
2
2
e
x
2
+y
2
2
2
(3.24)
Equation 3.24 gives a way to calculate coefficients for a Gaussian template which is then
convolved with an image. The effects of selection of Gaussian templates of differing size are
shown in Figure 3.16. The Gaussian function essentially removes the influence of points greater
than 3 in (radial) distance from the centre of the template. The 3 ×3 operator (Figure 3.16a)
retains many more of the features than those retained by direct averaging (Figure 3.14). The
effect of larger size is to remove more detail (and noise) at the expense of losing features.
This is reflected in the loss of internal eye component by the 5 ×5 and the 7 ×7 operators in
Figure 3.16(b) and (c), respectively.
(a) 3 × 3 (b) 5 × 5 (c) 7 × 7
Figure 3.16 Applying Gaussian averaging
A surface plot of the 2D Gaussian function of Equation 3.24 has the famous bell shape, as
shown in Figure 3.17. The values of the function at discrete points are the values of a Gaussian
template. Convolving this template with an image gives Gaussian averaging: the point in the
averaged picture is calculated from the sum of a region where the central parts of the picture
are weighted to contribute more than the peripheral points. The size of the template essentially
dictates appropriate choice of the variance. The variance is chosen to ensure that template
coefficients drop to near zero at the template’s edge. A common choice for the template size is
5×5 with variance unity, giving the template shown in Figure 3.18.
This template is then convolved with the image to give the Gaussian blurring function. It is
possible to give the Gaussian blurring function antisymmetric properties by scaling the x and y
88 Feature Extraction and Image Processing
Gaussian_template(19, 4)
Figure 3.17 Gaussian function
0.002 0.013 0.220 0.013 0.002
0.013 0.060 0.098 0.060 0.013
0.220 0.098
0.162
0.098 0.220
0.013 0.060 0.098 0.060 0.013
0.002 0.013 0.220 0.013 0.002
Figure 3.18 Template for the 5 ×5 Gaussian averaging operator  =10
coordinates. This can find application when an object’s shape, and orientation, is known before
image analysis.
By reference to Figure 3.16 it is clear that the Gaussian filter can offer improved performance
compared with direct averaging: more features are retained while the noise is removed. This
can be understood by Fourier transform theory. In Section 2.4.2 (Chapter 2) we found that the
Fourier transform of a square isa2Dsinc function. This has a non-even frequency response
(the magnitude of the transform does not reduce in a smooth manner) and has regions where the
transform becomes negative, called sidelobes. These can have undesirable effects since there are
high frequencies that contribute more than some lower ones, which is a bit paradoxical in low-
pass filtering to remove noise. In contrast, the Fourier transform of a Gaussian function is another
Gaussian function, which decreases smoothly without these sidelobes. This can lead to better
performance since the contributions of the frequency components reduce in a controlled manner.
In a software implementation of the Gaussian operator, we need a function implementing
Equation 3.24, the Gaussian_template function in Code 3.9. This is used to calculate the
coefficients of a template to be centred on an image point. The two arguments are winsize,
the (square) operator’s size, and the standard deviation that controls its width, as discussed
earlier. The operator coefficients are normalized by the sum of template values, as before. This
summation is stored in sum, which is initialized to zero. The centre of the square template is
then evaluated as half the size of the operator. Then, all template coefficients are calculated by
Basic image processing operations 89

Get Feature Extraction & Image Processing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.