Sei sulla pagina 1di 6

What are the mean and median filters?

Mean filter
The mean filter is a simple sliding-window spatial filter that replaces the center value
in the window with the average (mean) of all the pixel values in the window. The
window, or kernel, is usually square but can be any shape. An example of mean
filtering of a single 3x3 window of values is shown below.

unfiltered values

5 3 6

2 1 9

8 4 7

5 + 3 + 6 + 2 + 1 + 9 + 8 + 4 + 7 = 45
45 / 9 = 5

mean filtered

* * *

* 5 *

* * *

Center value (previously 1) is replaced by the mean of all nine values (5).

Median filter
The median filter is also a sliding-window spatial filter, but it replaces the center value
in the window with the median of all the pixel values in the window. As for the mean
filter, the kernel is usually square but can be any shape. An example of median
filtering of a single 3x3 window of values is shown below.

unfiltered values
6 2 0

3 97 4

19 3 10

in order:
0, 2, 3, 3, 4, 6, 10, 15, 97

median filtered

* * *

* 4 *

* * *

Center value (previously 97) is replaced by the median of all nine values (4).

Note that for the first (top) example, the median filter would also return a value of 5,
since the ordered values are 1, 2, 3, 4, 5, 6, 7, 8, 9. For the second (bottom) example,
though, the mean filter returns the value 16 since the sum of the nine values in the
window is 144 and 144 / 9 = 16. This illustrates one of the celebrated features of the
median filter: its ability to remove 'impulse' noise (outlying values, either high or
low). The median filter is also widely claimed to be 'edge-preserving' since it
theoretically preserves step edges without blurring. However, in the presence of noise
it does blur edges in images slightly.

General Image Processing References


Kenneth R. Castleman, Digital Image Processing. Prentice Hall, 1996.

Anil K. Jain, Fundamentals of Digital Image Processing. Prentice Hall, 1989.

William K. Pratt, Digital Image Processing. Wiley, 1991.

Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing. Addison-


Wesley, 1992.

I. Pitas and A. N. Venetsanopoulos, Nonlinear Digital Filters: Principles and


Applications. Kluwer Academic, 1990.
Return to Image Processing in Java.

Mark A. Schulze
http://www.markschulze.net/
mark@markschulze.net

Last Updated: 24 April 2001


Copyright © 1996-2001 by Mark A. Schulze. All Rights Reserved.

========================================

Next: About this document ... Up: smooth_sharpen Previous: Spatial averaging (low-
pass filtering)

Median Filter
Neighborhood averaging can suppress isolated out-of-range noise, but the side effect
is that it also blurs sudden changes such as line featuress, sharp edges, and other
image details all corresponding to high spatial frequencies.

The median filter is an effective method that can, to some extent, distinguish out-of-
range isolated noise from legitmate image features such as edges and lines.
Specifically, the median filter replaces a pixel by the median, instead of the average,
of all pixels in a neighborhood
where represents a neighborhood defined by the user, centered around

location in the image.

1D median filter:

Consider a 1x5 window sliding over a 1D array (either horizontal or vertical) of


pixels. Assume the five pixels currently inside the windows are:

where the middle pixel with value 200 is an isolated out-of-range and is therefore
likely to be noisy. The median of these five values can be found by sorting the values
(in either ascending or descending order). The median is 110, the value in the middle:

The original pixel value 200 is replaced by the median 110.

Question: How do you get rid of noise in the form of horizontal line across the image
using 1D median filter?

2D median filter:

The window of a 2D median filter can be of any central symmetric shape, a round
disc, a square, a rectangle, or a cross. The pixel at the center will be replaced by the
median of all pixel values inside the window.

Programming issues:

Sorting is necessary for finding the median of a set of values. There exit various

sorting algorithm with complexity of . However, in this case, as the

number of pixels is quite limited, a simple sorting method with complexity


can be used. The code segment below sorts a 1-D array of elements:
Example:

This figure shows the comparison of the smoothing results of a 1D signal (blue, 1st
column) by an average filter (red, 2nd column) and by a median filter (red, 3rd
column) both of size five. It is clear that the average filter always blurs edges without
completely suppressing noise, while the median filter can preserve sharp edges while
completely suppressing isolated out-of-range noise, based on the size of the feature. If
its size is less than half of the filter size, indicating the pixel is likely to be an out-of-
range noise, it is replace by the median. However, if the size is greater than half of the
window, large enough to represent some legitimate feature in the image, it is
preserved.
Next: About this document ... Up: smooth_sharpen Previous: Spatial averaging (low-
pass filtering)

Ruye Wang 2014-10-24

Potrebbero piacerti anche