Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Mark A. Schulze
http://www.markschulze.net/
mark@markschulze.net
========================================
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
1D median filter:
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:
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
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)