Digital Image Processing: Image Restoration: Noise Removal
Digital Image Processing: Image Restoration: Noise Removal
ie/bmacnamee
Digital Image Processing
Image Restoration:
Noise Removal
2
of
58
Contents
In this lecture we will look at image
restoration techniques used for noise removal
What is image restoration?
Noise and images
Noise models
Noise removal using spatial domain filtering
3
of
58
What is Image Restoration?
Image restoration attempts to restore
images that have been degraded
Identify the degradation process and attempt
to reverse it
Similar to image enhancement, but more
objective
4
of
58
Better visual
representation
Subjective
No quantitative
measures
Remove effects of
sensing environment
Objective
Mathematical, model
dependent
quantitative measures
What is Image Restoration? Enhancement vs. Restoration
Enhancement Restoration
5
of
58
Enhancement Restoration
Spatial
Domain
Frequency
Domain
Point Processing
>>imadjust
>>histeq
Spatial filtering
>>filter2
Filtering
>>fft2/ifft2
>>fftshift
Inverse filtering
Wiener filtering
Image Preprocessing
What is Image Restoration?
Spatial filtering
>>filter2
Spatial
Domain
Frequency
Domain
6
of
58
Image Restoration General
One has to have some a priori knowledge
about the degragation process.
Usually we need to know:
The noise in the original image
Model for degragation
Some information from original image
7
of
58
A Model of Image Degradation and
Restoration
) , ( ) , ( * ) , ( ) , ( y x y x f y x h y x g q + =
) , ( ) , ( ) , ( ) , ( G v u N v u F v u H v u + =
The degradation process is modeled as a degradation
function that together with an additive noise term.
In frequency domain representation:
Where: f(x,y) is the input image, g(x,y) is the
degraded image, h(x,y) is the degradation
function, and is the additive noise.
) , ( y x q
8
of
58
Degradation Model
f(x,y)
h(x,y)
g(x,y)
n(x,y)
E
Degradation Model: g = h*f + n
9
of
58
Restoration Model
f(x,y)
Degradation
Model
f(x,y)
Restoration
Filter
Unconstrained Constrained
Inverse Filter
Pseudo-inverse Filter
Wiener Filter
10
of
58
Restoration Model
The objective of restoration is to obtain an
estimate of the original image f(x,y).
Generally, the more we know about H, and ,
the closer will be to f(x,y).
The approach used throughout most of this
chapter is based on various types of image
restoration filters.
) , ( y x f
.
) , ( y x f
.
q
11
of
58
Noise and Images
The sources of noise in digital
images arise during image
acquisition (digitization) and
transmission
Imaging sensors can be
affected by ambient
conditions
Interference can be added
to an image during
transmission
12
of
58
Noise Models
There are many different models for the
image noise term (x, y):
Gaussian
Most common model
Rayleigh
Erlang
Exponential
Uniform
Impulse
Salt and pepper noise
13
of
58
Noise Models
2 2
2 / ) (
2
1
) (
o
o t
=
z
e z p
Gaussian noise:
4
) 4 (
; 4 /
) (
2
) (
2
0
/
2
) (
o t
= +
=
>
<
b
b a
z p
a z for e a z
b
a z for
b a z
Rayleigh noise:
14
of
58
Noise Models
2 2
0
! 1
0 0
/ ; /
) (
1
a b a b
z p
z for e
b
z a
z for
az
b b
=
=
>
<
o
Erlang (Gamma) noise:
2 2
0
0 0
/ 1 ; / 1
) (
a a
z p
z for ae
z for
az
=
=
>
<
o
Exponential noise:
15
of
58
Noise Models
12 / ) ( ; 2 / ) (
) (
2 2
1
0
a b b a
z p
b z a if
a b
otherwise
= +
=
s s
o
Uniform noise:
=
=
=
otherwise
b z f or p
a z f or p
z p
b
a
0
) (
Impulse noise:
16
of
58
For p
a
=p
b
=0.05
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
Input image
128 128 255 0 128 128 128 128 128 128
128 128 128 128 0 128 128 128 128 0
128 128 128 128 128 128 128 128 128 128
128 128 0 128 128 128 128 128 128 128
128 128 128 255 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128 128
0 128 128 128 128 255 128 128 128 128
128 128 128 128 128 128 128 128 128 255
128 128 128 128 128 128 128 255 128 128
Degraded image
Noise level p=0.05 means that approximately 5% of
pixels are contaminated by salt or pepper noise
(highlighted by red color)
Noise Models
Impulse noise is also called salt-and-pepper noise.
17
of
58
MATLAB Command
>Y = IMNOISE(X,'salt & pepper',p)
Notes:
The intensity of input images is assumed to be
normalized to [0,1]. If X is not double, you need to
do normalization first, i.e., X=X/255; If X is uint8,
MATLAB would do the normalization automatically
The default value of p is 0.05 (i.e., 5 percent of
pixels are contaminated)
Imnoise function can produce other types of noise
as well (you need to change the noise type salt &
pepper)
Example: impulsenoise.m
18
of
58
Noise Models
Remarks:
The preceding PDFs provide useful tools for modeling a
broad range of noise corruption situations in practice.
Gaussian noise arises due to factors such as electronic
circuit noise and sensor noise caused by poor illumination
and/or high temperature.
Rayleigh is helpful in characterizing noise phenomena in
range imaging.
Exponential and gamma find application in laser imaging.
Impuse noise is found in situations where quick transients,
such as faulty switching.
Uniform is the least descriptive of practical situations.
However, it is quite useful in simulations.
19
of
58
Noise Example
The test pattern to the right is
ideal for demonstrating the
addition of noise
The following slides will show
the result of adding noise
based on various models to
this image
Histogram to go here
Image
Histogram
20
of
58
Noise Example (cont)
Gaussian Rayleigh Erlang
21
of
58
Noise Example (cont)
Exponential Uniform Impulse
22
of
58
Periodic Noise
Periodic noise in an image arises typically
from electrical or electromechanical
interference during image acquisition.
Characteristics
Spatially dependent
Periodic easy to observe in frequency
domain
Processing method
Suppressing noise component in frequency
domain
23
of
58
Periodic Noise
spatial Frequency (note the four pairs of bright dots)
See Table 4-1:
24
of
58
Estimation of Noise Parameters
Periodic noise typically are estimated by
inspection of the Fourier spectrum of the image.
The parameters of noise PDFs may be known
from sensor specifications.
It is often necessary to estimate them for a
particular imaging device.
When images generated by the sensor are
available, frequently it is possible to estimate the
parameters of the PDF from small patches of
constant gray level.
25
of
58
Estimation of Noise Parameters
Gaussian noise Rayleigh noise Uniform noise
26
of
58
Estimation of Noise Parameters
2 2
( )
( ) ( )
i
i
i i
z S
i i
z S
z p z
z p z
o
e
e
=
=
o t
= +
=
>
<
b
b a
z p
a z for e a z
b
a z for
b a z
29
of
58
Restoration of Noise Only Degradation
We can consider a noisy image to be
modelled as follows:
where f(x, y) is the original image pixel, (x,
y) is the noise term and g(x, y) is the
resulting noisy pixel
) , ( ) , ( ) , (
) , ( ) , ( ) , (
v u N v u F v u G
y x y x f y x g
+ =
+ = q
30
of
58
If the noise is known, we can just subtract them
from g(x,y) or G(u,v) to restore f(x,y) or F(u,v).
Usually, the noise is unknown, so subtracting
them from g(x,y) or G(u,v) is not a realistic
option.
In the case of periodic noise, it is possible to
estimate N(u,v) from the spectrum of G(u,v),
then N(u,v) can be subtracted from G(u,v) to
obtain an estimate of the original image.
However, this type of knowledge is the
exception, rather than the rule.
When only additive noise is present, spatial
filtering is a choice. In this case, enhancement
and restoration become almost the same.
Restoration of Noise Only
Degradation
31
of
58
Mean filters
We can use different kinds of spatial filters
to remove different kinds of noise
The arithmetic mean filter is a very simple
one and is calculated as follows:
This is implemented as the
simple smoothing filter
Blurs the image to remove
noise
e
=
xy
S t s
t s g
mn
y x f
) , (
) , (
1
) , (
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
32
of
58
Other Means
There are different kinds of mean filters all of
which exhibit slightly different behaviour:
Geometric Mean
Harmonic Mean
Contraharmonic Mean
33
of
58
Other Means (cont)
There are other variants on the mean which
can give different performance
Geometric Mean:
Achieves similar smoothing to the arithmetic
mean, but tends to lose less image detail
mn
S t s
xy
t s g y x f
1
) , (
) , ( ) , (
(
(
=
[
e
34
of
58
Mean Filters
Original
Image
Image
Corrupted
By Gaussian
Noise
After A 3*3
Geometric
Mean Filter
After A 3*3
Arithmetic
Mean Filter
Example: meanfilter.m
35
of
58
Other Means (cont)
Harmonic Mean:
Works well for salt noise, but fails for pepper
noise
Also does well for other kinds of noise such
as Gaussian noise
e
=
xy
S t s
t s g
mn
y x f
) , (
) , (
1
) , (
36
of
58
Other Means (cont)
Contraharmonic Mean:
Q is the order of the filter and adjusting its value changes
the filters behaviour
Positive values of Q eliminate pepper noise
Negative values of Q eliminate salt noise
Q=0 Reduced to arithmetic mean filter
Q=-1Reduced to the harmonic mean filter
e
e
+
=
xy
xy
S t s
Q
S t s
Q
t s g
t s g
y x f
) , (
) , (
1
) , (
) , (
) , (
37
of
58
Mean Filters(cont)
Image
Corrupted
By Pepper
Noise
Result of
Filtering Above
With 3*3
Contraharmonic
Q=1.5
Blurred the dark
area, and cleared
the background
38
of
58
Mean Filters(cont)
Image
Corrupted
By Salt
Noise
Result of
Filtering Above
With 3*3
Contraharmonic
Q=-1.5
Blurred the
background, and
cleared the dark
area
39
of
58
Mean Filters(cont)
Choosing the
wrong value for
Q when using
contraharmonic
mean filter can
have drastic
results
Q=-1.5 Q=1.5
40
of
58
Mean Filters(cont)
Arithmetic and Geometric mean filters
Random noise: Gaussian or uniform noise
Harmonic mean filter
Salt noise, not good for pepper noise
Gaussian noise
Contraharmonic mean filter
Impulse noise
Prior knowledge about the noise is dark or
light
41
of
58
Order Statistics Filters
Spatial filters that are based on ordering the
pixel values that make up the
neighbourhood operated on by the filter
Useful spatial filters include
Median filter
Max and min filter
Midpoint filter
Alpha trimmed mean filter
42
of
58
Median Filter
Median Filter:
Excellent at noise removal, without the
smoothing effects that can occur with other
smoothing filters
Particularly good when salt and pepper
noise is present
)} , ( { ) , (
) , (
t s g median y x f
xy
S t s e
=
43
of
58
Image
Corrupted
By Salt And
Pepper Noise
P
a
=P
b
=0.1
Result of 1
Pass With A
3*3 Median
Filter
Result of 2
Passes With
A 3*3 Median
Filter
Result of 3
Passes With
A 3*3 Median
Filter
Example: medianfilter1.m
Median Filter
44
of
58
Note:
It is a good example of the power of median filtering in
handling impulse additive noise.
Repeat passes of a median filter tend to blur the image.
It is desirable to keep the number of passes as low as
possible.
Median Filter
45
of
58
Max and Min Filter
Max Filter:
Min Filter:
Max filter is good for pepper noise and min
is good for salt noise
)} , ( { max ) , (
) , (
t s g y x f
xy
S t s e
=
)} , ( { min ) , (
) , (
t s g y x f
xy
S t s e
=
46
of
58
Noise Removal Examples (cont)
Image
Corrupted
By Pepper
Noise
Image
Corrupted
By Salt
Noise
Result Of
Filtering
Above
With A 3*3
Min Filter
Result Of
Filtering
Above
With A 3*3
Max Filter
Example: maxminfilter.m
47
of
58
For max filter, it will remove pepper noise, but
it also removed some dark pixels from the
borders of dark objects.
The same as min filter, it will remove some
white points around the border of light objects.
Noise Removal Examples (cont)
48
of
58
Midpoint Filter
Midpoint Filter:
Good for Gaussian and random uniform
noise
(
+ =
e e
)} , ( { min )} , ( { max
2
1
) , (
) , ( ) , (
t s g t s g y x f
xy xy
S t s S t s
49
of
58
Alpha-Trimmed Mean Filter
Alpha-Trimmed Mean Filter:
We can delete the d/2 lowest and d/2 highest grey levels.
So g
r
(s, t) represents the remaining mn d pixels
d=0: the arithmetic mean filter
d=(mn-1)/2: Median filter
Other d: Multiple types of noise: Good for the
combination of salt-and-pepper and Gaussian noise
=
xy
S t s
r
t s g
d mn
y x f
) , (
) , (
1
) , (
50
of
58
Noise Removal Examples (cont)
Image
Corrupted
By Uniform
Noise
Image Further
Corrupted
By Salt and
Pepper Noise
Filtered By
5*5 Arithmetic
Mean Filter
Filtered By
5*5 Median
Filter
Filtered By
5*5 Geometric
Mean Filter
Filtered By
5*5 Alpha-Trimmed
Mean Filter
51
of
58
Adaptive Filters
The filters discussed so far are applied to an
entire image without any regard for how
image characteristics vary from one point to
another
The behaviour of adaptive filters changes
depending on the characteristics of the
image inside the filter region
An increase in filter complexity
We will take a look at the adaptive median
filter
52
of
58
Adaptive Median Filtering
The median filter performs relatively well on
impulse noise as long as the spatial density of the
impulse noise is not large (P
a
and P
b
are less than
0.2)
The adaptive median filter can handle much more
spatially dense impulse noise, and also performs
some smoothing for non-impulse noise
An additional benefit of the adaptive median filter is
that it seeks to preserve detail while smoothing
nonimpulse noise.
The key insight in the adaptive median filter is that
the filter size changes depending on the
characteristics of the image
53
of
58
Adaptive Median Filtering (cont)
Remember that filtering looks at each
original pixel image in turn and generates a
new filtered pixel
First examine the following notation:
z
min
= minimum grey level in S
xy
z
max
= maximum grey level in S
xy
z
med
= median of grey levels in S
xy
z
xy
= grey level at coordinates (x, y)
S
max
=maximum allowed size of S
xy
54
of
58
Adaptive Median Filtering (cont)
Level A: A1 = z
med
z
min
A2 = z
med
z
max
If A1 > 0 and A2 < 0, Go to level B
Else increase the window size
If window size repeat S
max
level A
Else output z
med
Level B: B1 = z
xy
z
min
B2 = z
xy
z
max
If B1 > 0 and B2 < 0, output z
xy
Else output z
med
Z
med
is an impulse?
Z
xy
is an impulse?
55
of
58
Adaptive Median Filtering (cont)
The key to understanding the algorithm is to
remember that the adaptive median filter
has three purposes:
Remove impulse noise
Provide smoothing of other noise
Reduce distortion, by not changing these
intermediate-level points. (excessive thinning
or thickening of object boundaries)
56
of
58
Adaptive Filtering Example
Image corrupted by salt
and pepper noise with
probabilities P
a
= P
b
=0.25
Result of filtering with a 7
* 7 median filter
Result of adaptive
median filtering with s
max
= 7
Choice of maximum allowed window size depends on the application. It should
be increased as the density of the impulse increases.
A reasonable value can be estimated by experiment with various sizes of
standard median filter.
57
of
58
Summary
In this lecture we looked at image restoration
for noise removal
Restoration is slightly more objective than
enhancement
Spatial domain techniques are particularly
useful for removing random noise