Image Enhancement-Spatial Filtering From: Digital Image Processing, Chapter 3
Image Enhancement-Spatial Filtering From: Digital Image Processing, Chapter 3
of
19
Image Enhancement-
Spatial Filtering
From:
Digital Image Processing, Chapter 3
Refael C. Gonzalez & Richard E. Woods
2
of
19
Contents
Next, we will look at spatial filtering
techniques:
Neighbourhoods are
mostly a rectangle
around a central pixel
(x, y)
Any size rectangle Neighbourhood
(x, y)
Neighbourhood
y Image f (x, y)
5
of
19
Simple Neighbourhood Operations
Simple neighbourhood operations example:
w(s, t ) f ( x s, y t )
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
g ( x, y )
s at b
* /9 /9 /9
1 1 1
99 106 98
95 90 85 1
/9 1
/9 1
/9
1
/9 100
104 1
/9 108
1
/9
Original Image Filter
Simple 3*3 /9 106
1
99 1
/9 198
/9
3*3 Smoothing Pixels
Neighbourhood /9 190
1
95 /9 185
/9 Filter
e = 1/9*106 +
1
/9*104 + 1/9*100 + 1/9*108 +
1
/9*99 + 1/9*98 +
y Image f (x, y) 1
/9*95 + 1/9*90 + 1/9*85
= 98.3333
The above is repeated for every pixel in the
original image to generate the smoothed image
10
of
19
Image Smoothing Example
The image at the top left
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
is an original image of
size 500*500 pixels
The subsequent images
show the image after
filtering with an averaging
filter of increasing sizes
3, 5, 9, 15 and 35
Notice how detail begins
to disappear
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
11
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
12
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
13
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
14
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
15
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
16
Image Smoothing Example
17
of
19
Weighted Smoothing Filters
More effective smoothing filters can be
generated by allowing different pixels in the
neighbourhood different weights in the
averaging function
Pixels closer to the
1
/16 /16
2
/16
1
Often referred to as a 1
/16 /16
2
/16
1
weighted averaging
Weighted
averaging filter
18
of
19
Another Smoothing Example
By smoothing the original image we get rid
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
20
Original
Averaging Filter Vs. Median Filter
Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
21
Filter
Averaging
Averaging Filter Vs. Median Filter
Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
22
Filter
Median
Averaging Filter Vs. Median Filter
Example
23
of
19
Strange Things Happen At The Edges!
e e e
y Image f (x, y)
24
of
Strange Things Happen At The Edges!
19 (cont)
There are a few approaches to dealing with
missing edge pixels:
Omit missing pixels
Only works with some filters
Can add extra code and slow down processing
Pad the image
Typically with either all white or all black pixels
Replicate border pixels
Truncate the image
25
of
19
Correlation & Convolution
The filtering we have been talking about so
far is referred to as correlation with the filter
itself referred to as the correlation kernel
Convolution is a similar operation, with just
one subtle difference
a b c r s t eprocessed = v*e +
d
f
e
g h
e
* u
x
v
y
w
z
z*a + y*b + x*c +
w*d + u*e +
t*f + s*g + r*h
Original Image Filter
Pixels
a function
Lets consider a simple 1 dimensional
example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
28
A
B
Spatial Differentiation
29
of
19
1st Derivative
The formula for the 1st derivative of a
function is as follows:
f
f ( x 1) f ( x)
x
Its just the difference between subsequent
values and measures the rate of change of
the function
30
of
19
1st Derivative (cont)
f(x)
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)
31
of
19
2nd Derivative
The formula for the 2nd derivative of a
function is as follows:
f
2
f ( x 1) f ( x 1) 2 f ( x)
x
2
f(x)
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)
33
of
19
1st and 2nd Derivative
f(x)
f(x)
f(x)
34
of
Using Second Derivatives For Image
19 Enhancement
The 2nd derivative is more useful for image
enhancement than the 1st derivative
Stronger response to fine detail
Simpler implementation
We will come back to the 1st order derivative
later on
The first sharpening filter we will look at is
the Laplacian
Isotropic
One of the simplest sharpening filters
We will look at a digital implementation
35
of
19
The Laplacian
The Laplacian is defined as follows:
f f
2 2
f 2 2
2
x y
where the partial 1st order derivative in the x
direction is defined as follows:
f
2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2
f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
We can easily build a filter based on this
0 1 0
1 -4 1
0 1 0
37
of
19
The Laplacian (cont)
Applying the Laplacian to an image we get a
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
- =
Original Laplacian Sharpened
Image Filtered Image Image
of
19
40
Laplacian Image Enhancement
41
of
19
Simplified Image Enhancement
The entire enhancement can be combined
into a single filtering operation
g ( x, y ) f ( x, y ) f
2
f ( x, y ) [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)
4 f ( x, y )]
5 f ( x, y ) f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)
42
of
19
Simplified Image Enhancement (cont)
0 -1 0
-1 5 -1
0 -1 0
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
19
43
Simplified Image Enhancement (cont)
44
of
19
Variants On The Simple Laplacian
There are lots of slightly different versions of
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
-1 -1 -1
-1 9 -1
-1 -1 -1
45
of
19
Unsharp Mask & Highboost Filtering
Using sequence of linear spatial filters in
order to get Sharpening effect.
-Blur
- Subtract from original image
- add resulting mask to original image
46
of
19
Highboost Filtering
47
of
19
1st Derivative Filtering
Implementing 1st derivative filters is difficult in
practice
For a function f(x, y) the gradient of f at
coordinates (x, y) is given as the column
vector:
f
Gx x
f f
Gy
y
48
of
19
1st Derivative Filtering (cont)
The magnitude of this vector is given by:
f mag (f )
G G 2
x
2
y 1
2
1
f 2
f
2 2
x y
z4 z5 z6
z7 z8 z9
50
of
19
Sobel Operators
Based on the previous equations we can
derive the Sobel Operators
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
An image of a
contact lens which
is enhanced in
order to make
defects (at four
and five oclock in
the image) more
obvious
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
54
of
Combining Spatial Enhancement
19 Methods (cont)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
(a)
Laplacian filter of
bone scan (a)
(b)
Sharpened version of
bone scan achieved (c)
by subtracting (a)
and (b) Sobel filter of bone
scan (a) (d)
55
of
Combining Spatial Enhancement
19 Methods (cont)
Result of applying a (h)
power-law trans. to
Images taken from Gonzalez & Woods, Digital Image Processing (2002)