Escolar Documentos
Profissional Documentos
Cultura Documentos
IMAGE ENHANCEMENT
What Is Image
Enhancement?
Image enhancement is the process of
making images more useful
The reasons for doing this include:
s = T(r)
(r,s are variables denoting the gray level of f(x, y) and g(x,
y) at any point(x, y) )
05/25/13
8
Frequency Domain
Method
Convolution theorem
g x y h x y f x y ( , ) ( , ) ( , )
G u v H u v F u v ( , ) ( , ) ( , )
H u v ( , )
: transfer function, optical transfer function
Visually, f(x, y) is given and the goal, after computation
of F(u, v), is to select H(u, v) so that the desired image
[ ]
g x y H u v F u v ( , ) ( , ) ( , )
F
1
.
exhibits some highlighted feature of f(x, y)
where G, H, and F are the Fourier transforms of g, h, and f
05/25/13
Image Enhancement Techniques
Point
operation
Mask
operation
Transform
operation
Coloring
operation
Image Negative
Contrast
Stretching
Compression of
dynamic range
Gray level slicing
Image
Subtraction
Image Averaging
Histogram
operations
Smoothing
operations
Median
Filtering
Sharpening
operations
Derivative
operations
Histogram
operations
Low pass
filtering
High pass
Filtering
Band pass
filtering
Homomorphic
filtering
Histogram
operations
False
coloring
Full color
processing
10
Image enhancement
05/25/13
Types of Image
Enhancement
) )( (
05/25/13
15
After contrast stretching, using a simple linear interpolation
between c = 79 and d = 136
This result is a significant improvement over the original, the
enhanced image itself still appears somewhat flat.
Source image
Its histogram
16
Otherwise,we can
achieve better results
by contrast stretching
the image over a more
narrow range of
graylevel values from
the original image
+
'
p
p
p
The gray scale intervals where pixels occur most frequently
would be stretched to improve the overall visibility of a scene
05/25/13 18
Contrast Stretching
05/25/13 19
Contrast Stretching
05/25/13 20
05/25/13 21
Clipping and
Thresholding
Clipping-
local thresholding
Assumptions: smaller image regions are more
likely to have approximately uniform illumination,
thus being more suitable for thresholding
05/25/13
29
Adaptive Thresholding
local thresholding
Assumptions: smaller image regions are more
likely to have approximately uniform illumination,
thus being more suitable for thresholding
05/25/13
30
Chow and Kaneko
approach
Image contains a
strong illumination
gradient, global
thresholding produces
a very poor result
Source Image
05/25/13
33
Display medical
images
and photographing a
screen with
monochrome positive
film
'
Without Background
, a
u otherwise
L u b
v
'
With Background
05/25/13 42
43
Intensity-level slicing:
(a) a transformation function that highlights a range [A, B] of intensities while
diminishing all others to a constant ,low level
(b) a transformation that highlights a range [A, B] of intensities but preserves all others
(c) Original image
(d) result of using the transformation in (a)
These transformations permits segmentation of certain gray level regions from
the rest of the image
a)
d) c)
b)
44
Examples of display transfer functions
Manipulation of the grey scale transfer function:
a) an original, moderately low-contrast transmission light microscope image
(prepared slide of a head louse)
b) expanded linear transfer function adjusted to the minimum and maximum
brightness values
c) positive gamma (log) function
d) negative gamma (log) function
e) negative linear transfer function
f) nonlinear transfer function (high slope linear contrast over central portion of
brightness range, with negative slope or solarization for dark and bright portions)
45
Bit-plane slicing
Higher-order :
Lower-order :
Subtle details
05/25/13
Bit Extraction
05/25/13 46
47
Bit-plane slicing
3 2
1 0
7 6
5 4
Original image
48
Bit-plane slicing
Plane 7 contains
the most
significant bits,
and plane 0
contains the
least significant
bits of the pixels
in the original
image
0 1 2
3 4 5
6 7
05/25/13
Log Transformation
Fourier Spectrum Log Transformed image
( )
10
log 1 v c u +
05/25/13 49
Power Law
Transformation
Power law
transformations have
the following form
Varying gives a
whole
family of curves
* v c u
05/25/13 50
Gamma Correction
Algorithm:
Histograms
corresponding to four
basic image types
Dark image
Bright image
Low-contrast image
High-contrast image
05/25/13
65
Histogram equalization
1
]
1
Equalization
05/25/13 71
Consider the transformation
1 0 ) ( ) (
,
0
r dw w p r T s
r
in
Note that this is the cumulative distribution function (CDF) of p
in
(r)
and satisfies the previous two conditions.
From the previous equation and using the fundamental
theorem of calculus,
) (r p
dr
ds
in
ds
dr
r p s p
in out
05/25/13 72
Therefore, the output histogram is given by
[ ] 1 0 , 1 1
) (
1
) ( ) (
) (
) (
1
1
1
]
1
s
r p
r p s p
s T r
s T r
in
in out
The output probability density function is uniform, regardless of
the input.
Thus, using a transformation function equal to the CDF of input
gray values r, we can obtain an image with uniform gray values.
This usually results in an enhanced image, with an increase in
the dynamic range of pixel values.
05/25/13 73
Step 1:For images with discrete gray values, compute:
n
n
r p
k
k in
) (
1 0
k
r 1 0 L k
L: Total number of gray levels
n
k
: Number of pixels with gray value r
k
n: Total number of pixels in the image
Step 2: Based on CDF, compute the discrete version of the previous
transformation :
k
j
j in k k
r p r T s
0
) ( ) (
1 0 L k
How to implement histogram
equalization?
05/25/13 74
Example:
Consider an 8-level 64 x 64 image with gray values (0, 1, ,7). The
normalized gray values are (0, 1/7, 2/7, , 1). The normalized
histogram is given below:
NB: The gray values in output are also (0, 1/7, 2/7, , 1).
k
j
j in k k
r p r T s
0
) ( ) (
1 0 L k
05/25/13 75
Gray value
# pixels
Normalized gray value
Fraction of
# pixels
05/25/13 76
Applying the transformation,
k
j
j in k k
r p r T s
0
) ( ) (
we have
05/25/13 77
05/25/13 78
Notice that there are only five distinct gray levels --- (1/7,
3/7,5/7, 6/7, 1) in the output image. We will relabel them
as (s
0
,s
1
, , s
4
).
With this transformation, the output image will have
histogram
05/25/13 79
Histogram of output
image
# pixels
Gray values
Note that the histogram of output image is only approximately, and not exactly,
uniform. This should not be surprising, since there is no result that claims
uniformity in the discrete case.
05/25/13 80
Example
Original image and its histogram
05/25/13 81
Histogram equalized image and its histogram
05/25/13 82
Comments:
Histogram equalization may not always produce desirable
results, particularly if the given histogram is very narrow. It
can produce false edges and regions. It can also increase
image graininess and patchiness.
05/25/13 83
05/25/13 84
Histogram Equalization
Motivation:
Motivation:
Solution:
Security monitoring
05/25/13 95
96
Two frames from a videotape sequence of free-swimming
single-celled animals in a drop of pond water , and the
difference image. The length of the white region divided by
the time interval gives the velocity
Analysis of motion in a more complex
situation than shown in fig. Where the
paths of the swimming microorganisms
cross, they are sorted out by assuming
that the path continues in a nearly
straight direction. (Gualtieri &Coltelli,
1992)
05/25/13
97
Image Averaging
Motivation:
Noisy image
n(x, y)=noise
uncorrelated: covariance
Smoothing operations
Median Filtering
Sharpening operations
Derivative operations
Correlation
05/25/13 101
Neighbourhood
Operations
Neighbourhood operations simply
operate on a larger neighbourhood of
pixels than point operations
Neighbourhoods are
mostly a rectangle
around a central pixel
Any size rectangle
and any shape filter
are possible
Origin x
y
Image f (x, y)
(x, y)
Neighbourhood
05/25/13 102
Neighbourhood
Operations
For each pixel in the origin image, the
outcome is written on the same
location at the target image.
Origin x
y
Image f (x, y)
(x, y)
Neighbourhood
Target Origin
05/25/13 103
Simple Neighbourhood
Operations
Simple neighbourhood operations
example:
l k
l k
l k h l n k m f
l k f l n k m h
n m f n m h n m g
) , ( ) , (
) , ( ) , (
) , ( ) , ( ) , (
In practice, to reduce computations, h( n , m ) is of finite extent:
where is a small set (called neighborhood). is also called as the support
of h.
h( n , m ) =0, for (k,l)
05/25/13 106
If h(m,n) is a 3 by 3 mask given by
w
1
w
3
w
2
w
4
w
6
w
5
w
7
w
9
w
8
h =
) 1 , 1 ( ) , 1 ( ) 1 , 1 (
) 1 , ( ) , ( ) 1 , (
) 1 , 1 ( ) , 1 ( ) 1 , 1 (
) , (
9 8 7
6 5 4
3 2 1
+ + + + + + +
+ + + +
+ + +
n m f w n m f w n m f w
n m f w n m f w n m f w
n m f w n m f w n m f w
n m g
(x,y)
y
x
f(-1,-1) f(-1, 0)
f(-1, 1)
f( 0,-1) f( 0, 0) f( 0, 1)
f( 1,-1) f( 1, 0) f( 1, 1)
(m=0,n=0)
05/25/13 107
The output g(m, n) is computed by sliding the mask over each pixel of the
image f(m, n). This filtering procedure is sometimes referred to as moving
average filter.
Special care is required for the pixels at the border of image f(m, n). This
depends on the so-called boundary condition. Common choices are:
(1) The mask is truncated at the border (free boundary).
For one dimension
'
0
) (
) (
~
x f
x f
N x < 0
0 1 ) 2 / ( < + x L
1 ) 2 / ( + < L N x N
MATLAB option is P
05/25/13 108
(2)The image is extended by appending extra rows/columns at the boundaries. The
extension is done by repeating the first/last row/column or by setting them to some
constant (fixed boundary).
(3)The boundaries wrap around (periodic boundary).
For one dimension
'
) 1 (
) (
) 0 (
) (
~
N f
x f
f
x f
1 ) 2 / ( + < L N x N
0 1 ) 2 / ( < + x L
N x < 0
'
) mod (
) (
) mod ) ((
) (
~
N x f
x f
N N x f
x f
1 ) 2 / ( + < L N x N
0 1 ) 2 / ( < + x L
N x < 0
For one dimension
MATLAB option is replicate
MATLAB option is symmetric
05/25/13 109
In any case, the final output g(m, n) is restricted to the support of the original
image f(m, n).
The mask operation can be implemented in matlab using the filter2
command, which is based on the conv2 command.
05/25/13 110
The Spatial Filtering
Process
j k l
m n o
p q r
Origin x
y
Image f (x, y)
e
processed
= n*e +
j*a + k*b + l*c +
m*d + o*f +
p*g + q*h + r*i
Filter (w)
Simple 3*3
Neighbourhood
e 3*3 Filter
a b c
d e f
g h i
Original Image
Pixels
*
The above is repeated for every pixel in the
original image to generate the filtered image
05/25/13 111
Spatial Filtering:
Equation Form
+ +
a
a s
b
b t
t y s x f t s w y x g ) , ( ) , ( ) , (
Filtering can be given
in equation form as
shown above
Notations are based
on the image shown
to the left
05/25/13 112
Smoothing Filters
Image smoothing refers to any image-to-image transformation designed to
smooth or flatten the image by reducing the rapid pixel-to-pixel variation in
gray values.
Smoothing filters are used for:
(1) Blurring: This is usually a preprocessing step for removing small
(unwanted) details before extracting the relevant (large) object, bridging gaps
in lines/curves,
(2)Noise reduction: Mitigate the effect of noise by linear or nonlinear
operations.
Image smoothing by averaging (lowpass spatial filtering)
05/25/13 113
Smoothing is accomplished by applying an averaging mask.
An averaging mask is a mask with positive weights, which sum to 1. It
computes a weighted average of the pixel values in a neighborhood. This
operation is sometimes called neighborhood averaging.
Some 3 x 3 averaging masks:
1
1
1
]
1
0 1 0
1 1 1
0 1 0
5
1
1
1
1
]
1
0 1 0
1 4 1
0 1 0
8
1
1
1
1
]
1
1 1 1
1 1 1
1 1 1
9
1
1
1
1
]
1
1 3 1
3 16 3
1 3 1
32
1
This operation is equivalent to lowpass filtering.
05/25/13 114
Smoothing Spatial Filters
One of the simplest spatial filtering
operations we can perform is a
smoothing operation
Especially useful
in removing noise
from images
3, 5, 9, 15 and 35
Notice how detail begins
to disappear
05/25/13 117
Image Smoothing Example
05/25/13 118
Image Smoothing Example
05/25/13 119
Image Smoothing Example
05/25/13 120
Image Smoothing Example
05/25/13 121
Image Smoothing Example
05/25/13 122
Image Smoothing Example
05/25/13 123
Weighted Smoothing
Filters
More effective smoothing filters can be
generated by allowing different pixels
in the neighbourhood different weights
in the averaging function
Often referred to as a
weighted averaging
1
/
16
2
/
16
1
/
16
2
/
16
4
/
16
2
/
16
1
/
16
2
/
16
1
/
16
Weighted
averaging filter
05/25/13 124
Another Smoothing Example
By smoothing the original image we
get rid of lots of the finer detail which
leaves only the gross features for
thresholding
Original Image Smoothed Image Thresholded Image
* Image taken from Hubble Space Telescope
05/25/13 125
Averaging Filter Vs. Median
Filter Example
Filtering is often used to remove noise
from images
Sometimes a median filter works
better than an averaging filter
Original Image
With Noise
Image After
Averaging Filter
Image After
Median Filter
05/25/13 126
Averaging Filter Vs. Median Filter
Example
Original
05/25/13 127
Averaging Filter Vs. Median Filter
Example
Averaging
Filter
05/25/13 128
Averaging Filter Vs. Median Filter
Example
Median
Filter
05/25/13 129
Strange Things Happen At The
Edges!
Origin x
y
Image f (x, y)
e
e
e
e
At the edges of an image we are missing
pixels to form a neighbourhood
e e
e
05/25/13 130
Strange Things Happen At The
Edges! (cont)
There are a few approaches to dealing
with missing edge pixels:
Highlight edges
Sharpening filters are based on spatial
differentiation
05/25/13 133
Image Sharpening
This involves highlighting fine details or
enhancing details that have been blurred.
Basic highpass spatial filtering
This can be accomplished by a linear shift-
invariant operator, implemented by means
of a mask, with positive and negative
coefficients.
This is called a sharpening mask, since it
tends to enhance abrupt gray level
changes in the image.
05/25/13 134
The mask should have a positive coefficient at the
center and negative coefficients at the periphery.
The coefficients should sum to zero. Example:
1
1
1
]
1
1 1 1
1 8 1
1 1 1
9
1
This is equivalent to highpass filtering.
A highpass filtered image g can be thought of as
the difference between the original image f and a
lowpass filtered version of f :
g(m,n) = f(m,n) lowpass(f(m,n))
05/25/13 135
Example:
05/25/13 136
High-boost filtering
This is a filter whose output g is produced by
subtracting a lowpass (blurred) version of f from
an amplified version of f
g(m,n) = A f(m,n) lowpass(f(m,n))
This is also referred to as unsharp masking.
Observe that
g(m,n) = A f(m,n) lowpass(f(m,n))
= (A-1) f(m,n) + f(m,n) lowpass(f(m,n))
= (A-1) f(m,n) + highpass(f(m,n))
For A > 1, part of the original image is added back to the highpass filtered
version of f.
05/25/13 137
The result is the original image with the edges enhanced relative to the original
image.
Example:
05/25/13 138
Spatial Differentiation
Differentiation measures the rate of
change of a function
Lets consider a simple 1 dimensional
example
05/25/13 139
Spatial Differentiation
A B
05/25/13 140
1
st
Derivative
The formula for the 1
st
derivative of a
function is as follows:
Its just the difference between
subsequent values and measures the
rate of change of the function
) ( ) 1 ( x f x f
x
f
+
05/25/13 141
1
st
Derivative (cont)
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
0 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
f(x)
f(x)
05/25/13 142
2
nd
Derivative
The formula for the 2
nd
derivative of a
function is as follows:
Simply takes into account the values
both before and after the current value
) ( 2 ) 1 ( ) 1 (
2
2
x f x f x f
x
f
+ +
05/25/13 143
2
nd
Derivative (cont)
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6
-12
6 0 0 1 1 -4 1 1 0 0 7 -7 0 0
f(x)
f(x)
05/25/13 144
05/25/13 145
1
st
and 2
nd
Derivative
f(x)
f(x)
f(x)
146
Using Second Derivatives For
Image Enhancement
The 2
nd
derivative is more useful for
image enhancement than the 1
st
derivative
Simpler implementation
Isotropic
) , ( 2 ) , 1 ( ) , 1 (
2
2
y x f y x f y x f
x
f
+ +
) , ( 2 ) 1 , ( ) 1 , (
2
2
y x f y x f y x f
y
f
+ +
05/25/13 148
The Laplacian (cont)
So, the Laplacian can be given as
follows:
We can easily build a filter based on
this
) , 1 ( ) , 1 ( [
2
y x f y x f f + +
)] 1 , ( ) 1 , ( + + + y x f y x f
) , ( 4 y x f
0 1 0
1 -4 1
0 1 0
05/25/13 149
Laplacian Mask
05/25/13 150
The Laplacian (cont)
Applying the Laplacian to an image we
get a new image that highlights edges
and other discontinuities
Original
Image
Laplacian
Filtered Image
Laplacian
Filtered Image
Scaled for Display
05/25/13 151
But That Is Not Very
Enhanced!
The result of a Laplacian
filtering is not an enhanced
image
We have to do more work in
order to get our final image
Subtract the Laplacian result
from the original image to
generate our final sharpened
enhanced image
Laplacian
Filtered Image
Scaled for Display
f y x f y x g
2
) , ( ) , (
05/25/13 152
Unsharp masking
Sharpen images consists of subtracting an
unsharp (smoothed) version of an image from the
original image
1
]
1
y
f
x
f
G
G
y
x
f
05/25/13 166
1
st
Derivative Filtering
(cont)
The magnitude of this vector is given by:
For practical reasons this can be
simplified as:
) f ( mag f
[ ]
2
1
2 2
y x
G G +
2
1
2
2
1
1
]
1
,
_
,
_
y
f
x
f
y x
G G f +
05/25/13 167
1
st
Derivative Filtering
(cont)
There is some debate as to how best to
calculate these gradients but we will use:
which is based on these coordinates
( ) ( )
3 2 1 9 8 7
2 2 z z z z z z f + + + +
( ) ( )
7 4 1 9 6 3
2 2 z z z z z z + + + + +
z
1
z
2
z
3
z
4
z
5
z
6
z
7
z
8
z
9
05/25/13 168
Sobel Operators
Based on the previous equations we can
derive the Sobel Operators
To filter an image it is filtered using both
operators the results of which are added
together
-1 -2 -1
0 0 0
1 2 1
-1 0 1
-2 0 2
-1 0 1
05/25/13 169
Sobel Example
Sobel filters are typically used for edge
detection
An image of a
contact lens which
is enhanced in
order to make
defects (at four
and five oclock in
the image) more
obvious
05/25/13 170
1
st
& 2
nd
Derivatives
Comparing the 1
st
and 2
nd
derivatives
we can conclude the following:
1
st
order derivatives generally produce
thicker edges
2
nd
order derivatives have a stronger
response to fine detail e.g. thin lines
1
st
order derivatives have stronger
response to grey level step
2
nd
order derivatives produce a double
response at step changes in grey level
05/25/13 171
Combining Spatial
Enhancement Methods
Successful image
enhancement is typically
not achieved using a
single operation
Rather we combine a
range of techniques in
order to achieve a final
result
This example will focus
on enhancing the bone
scan to the right
05/25/13 172
Combining Spatial
Enhancement Methods
(cont)
Laplacian filter of
bone scan (a)
Sharpened version of
bone scan achieved
by subtracting (a)
and (b) Sobel filter of bone
scan (a)
(a)
(b)
(c)
(d) 05/25/13 173
Combining Spatial
Enhancement Methods
(cont)
The product of (c)
and (e) which will be
used as a mask
Sharpened image
which is sum of (a)
and (f)
Result of applying a
power-law trans. to
(g)
(e)
(f)
(g)
(h)
Image (d) smoothed with
a 5*5 averaging filter
05/25/13 174
Combining Spatial
Enhancement Methods
(cont)
Compare the original and final images
05/25/13 175
Filtering in Frequency
Domain
05/25/13 176
Notch Filter
( , ) 0 ( , ) ( / 2, / 2)
1 otherwise
H u v if u v M N
05/25/13 177
Transfer Function of Ideal
Lowpass Filter
0
0
0
1
2 2
2
( , ) 1 ( , )
0 ( , )
is the cutoff frequency
( , )
2 2
H u v if D u v D
if D u v D
D
M N
D u v u v
_
_ _
+
, ,
,
f
05/25/13 178
2
2 2
1 1
0 0
( , ) ( , ) ( , ) ( , ) ( , )
( , )
( , )
100
M N
T
u v
u v
T
P u v F u v P u v R u v I u v
P P u v
P u v
P
1
1
1
1
]
05/25/13 179
Ideal Lowpass Filter
05/25/13 180
05/25/13 181
05/25/13 182
Butterworth Low pass Filter
[ ]
2
0
1
( , )
1 ( , ) /
n
H u v
D u v D
+
05/25/13 183
Results of Filtering with
BLPF
05/25/13 184
05/25/13 185
Gaussian Lowpass Filter
2 2
0
( , )/ 2
( , )
D u v D
H u v e
05/25/13 186
High Pass Filter
05/25/13 187
Transfer function of HPF
[ ]
2 2
0
0
0
0
2
0
( , )/ 2
HPF
( , ) 0 ( , )
1 ( , )
is the cutoff frequency
HPF
1
( , )
1 ( , ) /
HPF
( , ) 1
n
D u v D
Ideal
H u v if D u v D
if D u v D
D
Butterworth
H u v
D u v D
Gaussian
H u v e
+
f
05/25/13 188
Results of HPF using
Butterworth HPF
05/25/13 189
Homomorphic Filtering
Approach
05/25/13 190
Homomorphic Filtering
{ } { } { }
{ } { }
{ } { }
( , ) ( , ) ( , )
( , ) ( , ) ( , )
( , ) ln ( , )
= ln ( , ) ln ( , )
( , ) ln ( , )
= ln ( , ) ln ( , )
( , ) ( , ) ( , )
i r
f x y i x y r x y
F f x y F i x y F r x y
z x y f x y
i x y r x y
F z x y F f x y
F i x y F r x y
Z u v F u v F u v
+
+
05/25/13 191
{ }
{ }
1
1 1
we process ( , ) by means of a filter function H(u,v)
( , ) ( , ) ( , )
= ( , ) ( , ) ( , ) ( , )
the spatial domain
( , ) ( , )
( , ) ( , ) ( , ) (
i r
i r
If Z u v
S u v H u v Z u v
H u v F u v H u v F u v
In
s x y F S u v
F H u v F u v F H u v F u
+
{ }
, )
v
{ }
{ }
1
1
( , )
'( , ) '( , )
0 0
'( , ) ( , ) ( , )
'( , ) ( , ) ( , )
( , ) '( , ) '( , )
( , )
= .
= ( , ) ( , )
i
r
s x y
i x y r x y
i x y F H u v F u v
r x y F H u v F u v
s x y i x y r x y
g x y e
e e
i x y r x y
05/25/13 192
Filter Function H(u,v)
The filter function tends to decrease the contribution made by the low
frequencies (illumination) and amplify the contributions made by the
high frequencies (reflectance)
05/25/13 193
Thank You
05/25/13 194