**Common Names:** Mean filtering, Smoothing, Averaging, Box filtering

Mean filtering is a simple, intuitive and easy to implement method of
*smoothing* images, *i.e.* reducing the amount of intensity variation
between one pixel and the next. It is often used to reduce noise in
images.

The idea of mean filtering is simply to replace each pixel value in an
image with the mean (`average') value of its neighbours, including
itself. This has the effect of eliminating pixel values which are
unrepresentative of their surroundings. Mean filtering is usually
thought of as a convolution filter. Like other
convolutions it is based around a kernel, which
represents the shape and size of the neighbourhood to be sampled when
calculating the mean. Often a 3×3 square kernel is used, as
shown in Figure 1, although larger kernels (*e.g.* 5×5
squares) can be used for more severe smoothing. (Note that a small
kernel can be applied more than once in order to produce a similar
- but not identical - effect as a single pass with a large kernel.)

Figure 13×3 averaging kernel often used in mean filtering

Computing the straightforward convolution of an image with this kernel carries out the mean filtering process.

Mean filtering is most commonly used as a simple method for reducing noise in an image.

We illustrate the filter using .

shows this image corrupted by Gaussian noise with a mean of zero and a standard deviation (SD) of 8.

shows the effect of applying a 3×3 mean filter. Note that the noise is less apparent, but the image has been `softened'. If we increase the size of the mean filter to 5×5, we obtain an image with less noise and less high frequency detail, as shown in .

shows the same image more severely corrupted by Gaussian noise with a mean of zero and a SD of 13.

is the result of mean filtering with a 3×3 kernel.

provides an even more challenging task. It shows an image containing `salt and pepper' shot noise.

shows the effect of smoothing this image with a 3×3 mean filter. Since the shot noise pixel values are often very different from the surrounding values, they tend to distort the pixel average calculated by the mean filter significantly.

Using a 5×5 filter instead gives . This result is not a significant improvement noise reduction and, furthermore, the image is bow very blurred.

These examples illustrate the two main problems with mean filtering, which are:

- A single pixel with a very unrepresentative value can
significantly affect the mean value of all the pixels in its
neighbourhood.
- When the filter neighbourhood straddles an edge, the filter will interpolate new values for pixels on the edge and so will blur that edge. This may be a problem if sharp edges are required in the output.

Both of these problems are tackled by the median filter. The median filter is often a better filter for reducing noise than the mean filter, but it takes longer to compute.

In general the mean filter acts as a lowpass frequency filter and, therefore, reduces the spatial intensity derivatives present in the image. We have already seen this effect as a `softening' of the facial features in the above example. Now consider the image which depicts a scene containing a wider range of different spatial frequencies. After smoothing once with a 3×3 mean filter we obtain . Notice that the low spatial frequency information in the background has not been effected significantly by filtering, but the (once crisp) edges of the foreground subject have been appreciably smoothed. After filtering with a 7×7 filter, we obtain an even more dramatic illustration of this phenomena . Compare this result to that obtained by passing a 3×3 filter over the original image three times .

Variations on the mean smoothing filter discussed here include
*Threshold Averaging* wherein smoothing is applied subject to the
condition that the center pixel value is changed only if the
difference between its original value and the average value is greater
than a preset threshold. This has the effect that noise is smoothed
with a less dramatic loss in image detail.

Other convolution filters that do not calculate the mean of a neighbourhood are also often used for smoothing. One of the most common of these is the Gaussian smoothing filter.

- The mean filter is computed using a convolution. Can
you think of any ways in which the special properties of the mean
filter kernel can be used to speed up the convolution? What is the
*computational complexity*of this faster convolution? - Use an edge detector on the image and note the
strength of the output. Then apply a 3×3 mean filter to the
original image and run the edge detector again. Comment on the
difference. What happens if a 5×5 or a 7×7 filter is used?
- Applying a 3×3 mean filter twice does not produce quite the same
result as applying a 5×5 mean filter once. However, a 5×5
convolution mask
*can*be constructed which is equivalent. What does this mask look like? - Create a 7×7 convolution mask which has an equivalent
effect to three passes with a 3×3 mean filter.
- How do you think the mean filter would cope with Gaussian noise which was not symmetric about zero? Try some examples.

**R. Boyle and R. Thomas** *Computer Vision: A First Course*,
Blackwell Scientific Publications, 1988, pp 32 - 34.

**E. Davies** *Machine Vision: Theory, Algorithms and
Practicalities*, Academic Press, 1990, Chap 3.

**D. Vernon** *Machine Vision*, Prentice-Hall, 1991, Chap 4.

General advice about the local HIPR installation is available here

©1994 Bob Fisher, Simon Perkins, Ashley Walker and Erik Wolfart

Department of Artificial Intelligence

University of Edinburgh

UK