Image filtering changes pixel values using information from nearby
pixels. Different filters can examine the same neighborhood but
use different rules to determine the output.
A grayscale image stores one intensity value at each pixel.
That value describes how dark or bright the pixel is.
In an 8-bit grayscale image, each pixel can have
one of 256 possible values:
\[
0
\le
I
\le
255
\]
8-bit Grayscale Intensity
0 — Black
255 — White
0
64
128
192
255
A smaller number represents a darker pixel.
A larger number represents a brighter pixel.
2. Image Filtering
Noise can cause unwanted changes in pixel intensities.
Filtering changes pixel values using neighboring image data.
Original Image → Noisy Image → Filtered Image
Original
→
Noisy
→
Filtered
3. The Neighborhood
A neighborhood is a collection of pixels surrounding the location
currently being processed.
Neighborhood shape can be described in several ways.
Common pixel-grid distance measures include
Euclidean distance,
Manhattan or city-block distance, and
Chebyshev or chessboard distance.
Their definitions are introduced separately.
On this page, we use a square neighborhood \(W\).
Example Square Neighborhood
98
102
99
101
255
97
100
103
99
102
96
101
100
104
98
99
102
97
101
100
103
98
99
102
96
Current center pixel
Example
100
\[
r=2
\]
\[
L=5
\]
\[
N=25
\]
The \(5\times5\) neighborhood is only an example.
The filter definitions below are written using variables so they
also apply to other odd-sized square neighborhoods.
4. Neighborhood Variables
Let \(r\) be the radius of a square neighborhood measured from its
center pixel.
\[
L
=
2r+1
\]
\[
N
=
L^2
=
(2r+1)^2
\]
\(W\)
Current neighborhood around the pixel being processed.
\(r\)
Neighborhood radius measured from the center.
\(L\)
Number of pixels along one side of the square
neighborhood.
\(N\)
Total number of pixels in the neighborhood.
\(x_{k,l}\)
Input intensity at image location \((k,l)\).
\(y_{k,l}\)
Filtered output intensity at location \((k,l)\).
For the square example used throughout this page,
\(r=2\), so \(L=5\) and \(N=25\).
5. Mean Filter
The mean filter replaces the center value with the average of all
\(N\) values in the neighborhood.
The smallest value in \(W\) becomes the output at the
center position.
Maximum Filter
98
102
99
101
255
97
100
103
99
102
96
101
100
104
98
99
102
97
101
100
103
98
99
102
96
↓
255
The largest value in \(W\) becomes the output at the
center position.
The selected pixel does not physically move.
Only its intensity value is used as the output value at the center
location.
For a flat gray-scale structuring element, this local
minimum/maximum behavior is closely related to gray-scale
morphology:
erosion uses a local minimum and dilation uses a local maximum.
12. Recursive Median Filtering
An ordinary median filter calculates each output from the current
input neighborhood.
A recursive median filter can reuse output values that were
calculated earlier in the scan.
99
100
101
99
100
98
100
102
101
99
99
100
255
102
101
98
101
100
103
99
97
100
101
99
102
Already filtered
Current pixel
Not processed yet
Current Location
Previous output values may be reused.
Later positions still contribute input values.
101
Example result
A general one-dimensional recursive-median notation is
The exact two-dimensional neighborhood and scan order depend on
the chosen recursive-median implementation.
The defining idea is that previous filtered outputs can influence
later calculations.
13. Comparing the Main Denoising Filters
These filters use the same local neighborhood but apply different
rules to determine the output value.
Mean Filter
Average all neighborhood values.
Average
Median Filter
Sort the neighborhood values and select the middle-ranked value.
Rank
Alpha-Trimmed Mean Filter
Remove values from both ends of the sorted list, then average
the values that remain.
Trim + Average
Sigma Filter
Keep neighborhood values that are sufficiently close to the
center intensity, then average the accepted values.
Range Selection
SNN Mean Filter
Compare symmetric pixel pairs, select one value from each pair,
and average the selected values.
Symmetric Pairs
The main difference is the selection rule used before
producing the output value.
14. Repeated Filtering
A filter can be applied repeatedly.
Each new iteration uses the result of the previous iteration.
\[
I^{(t+1)}
=
F
\left(
I^{(t)}
\right)
\]
\(t\) is the current iteration number,
\(I^{(t)}\) is the image at that iteration,
and \(F\) is the selected filtering operation.
Repeated filtering can strengthen an effect, but it can also
progressively modify edges and small image structures.
15. Histogram
A grayscale histogram counts how many pixels occur at each
intensity.
Example Gray-Level Histogram
Pixel Count
Gray Level
A histogram describes how frequently intensity values occur.
It does not show where those pixels are located.
16. Mean and Standard Deviation
Mean
\[
\mu
=
\frac{1}{M}
\sum_{i=1}^{M}
x_i
\]
\(M\) is the number of intensity samples being summarized.
Standard deviation describes how much the intensities vary
around their mean.
\(M\) is used here instead of \(N\) because these statistics may be
calculated over any selected collection of image pixels, not only
one filtering neighborhood.
17. Interactive Example
The interactive visualizer below uses a square \(5\times5\)
example neighborhood.
In the notation above, this example uses
\(r=2\), \(L=5\), and \(N=25\).
These are example values rather than part of the general filter
definitions.
Select a pixel in the grid and change its 8-bit grayscale value.
The visualizer can then show how the selected nonlinear filter
changes the center output.
The current interactive visualizer focuses on the
mean, median, alpha-trimmed mean, sigma, and SNN mean
filters.
Minimum, maximum, and recursive median are introduced above to
explain the broader family of nonlinear filtering methods.
Summary
Concept
Main Idea
\(W\)
Current filtering neighborhood.
\(r\)
Radius of a square neighborhood.
\(L\)
Side length,
\(L=2r+1\).
\(N\)
Number of neighborhood pixels,
\(N=L^2\).
Mean Filter
Average all \(N\) neighborhood values.
Median Filter
Select rank
\(m=(N+1)/2\)
for odd \(N\).
Alpha-Trimmed Mean
Remove \(d\) values from the sorted list and average
the remaining \(N-d\) values.
Sigma Filter
Keep neighborhood values whose intensity is close to
the center value.
SNN Mean
Form symmetric pairs and select one value from each
pair according to similarity with the center.
Order Statistic
A value identified by its rank after sorting.
Minimum Filter
Select \(x_{(1)}\), the smallest ranked value.
Maximum Filter
Select \(x_{(N)}\), the largest ranked value.
Recursive Median
Previously calculated outputs may influence later
median calculations.
Distance Measures
Euclidean, Manhattan/city-block, and
Chebyshev/chessboard distance are common ways to
describe spatial relationships on a pixel grid.
Nonlinear Filtering Visualizer
\(5\times5\) Neighborhood
Click a pixel to select it.
The center is identified by its orange border.
Be First to Comment