ab_dip_5_spatial_filters
ab_dip_5_spatial_filters
(Spatial Filtering)
Image Enhancement Revisited
(x, y)
Neighbourhood
x
Processing of pixels at the edges
y
Origin e e
Image f (x, y)
e e e
x
Approaches to process pixels at the edges
Filtered Image:
Zeroes added
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
1 1 1
Averaging 1 1 1
A=(1/9)
filter
1 1 1
Smoothing Spatial Filtering
Origin x 1 1
54 100 208 1
1 1 1
49 106 198
45 90 185
* 1/9
1 1 1
23 42 86
54 100 208
Original Image Filter
Pixels 3*3 Smoothing
49 106 198
45 90 185
Filter
e = 1/9[106 + 54 +100 + 208 +
49 + 198 +45 + 90 + 185]
= 115
y Image f (x, y)
Smoothing Spatial Filtering
Origin x 1 1
23 42 86 1
1 1 1
54 100 208
49 106 198
* 1/9
1 1 1
23 42 86
54 100 208
Original Image Filter
49 106 198 Pixels 3*3 Smoothing
45 90 185 Filter
e = 1/9[23+42+86+54+100+208
+49+106+198+]
= 94.77 95
y Image f (x, y)
Smoothing Spatial Filtering
Origin x
95
115
y Filtered Image
Original Image
Image filtered with 3x3 mask
Image filtered with 5x5 mask
Image filtered with 9x9 mask
Image filtered with 15x15 mask
Image filtered with 35x35 mask
Image Smoothing Example
Original image
Sharpness/details begin
to disappear with increase 3x3
in size of mask
5x5
9x9
15x15
35x35
Limitations of averaging filter
Original Image
Application of average filter
(smoothening & thresholding)
2 3 6
1 1 8 Image after
2 3 6 minimum filter
7 4 5
1 2 8
7 4 5 2 3 6
Image after
Image Before filter
1 8 8 Maximum filter
7 4 5
Median filter
2 3 6
[2 3 6 1 2 8 7 4 5] sort in ascending
1 2 8
[1 2 2 3 4 5 6 7 8]
7 4 5
Image Before filter 2 3 6
1 4 8 After filter
7 4 5
Image with salt and pepper /impulse noise
After Averaging Filter (blurs)
After Median Filter
Averaging Filter Vs. Median Filter
45 56 42 63 54
20 47 56 28 53
63 59 26 38 47
67 36 27 48 51
43 36 42 65 43
Example: Spatial filters
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 56 28 53
63 59 26 38 47 63 59 26 38 47
67 36 27 48 51 67 36 27 48 51
43 36 42 65 43 43 36 42 65 43
First location of filter for 3x3 filter Next location of mask for 3x3 filter
Example: Spatial filters
45 56 42 63 54 1 1 1 1 1 45 56 42 63 54
20 47 56 28 53 1 1 1 1 1 20 47 56 28 53
63 59 26 38 47 *(1/25) 1 1 1 1 1 = 63 59 46 38 47
67 36 27 48 51 1 1 1 1 1 67 36 27 48 51
43 36 42 65 43 1 1 1 1 1 43 36 42 65 43
Example: Spatial filters
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 20 26 26 53
min(3x3) =
63 59 26 38 47 63 20 26 26 47
67 36 27 48 51 67 26 26 26 51
43 36 42 65 43 43 36 42 65 43
Example: Spatial filters
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 47 47 53
median(3x3) =
63 59 26 38 47 63 47 38 47 47
67 36 27 48 51 67 42 38 43 51
43 36 42 65 43 43 36 42 65 43
Sharpening Spatial Filters
Remove blurring in images
Highlight transition in intensity (edges)
Used in electronic printing, medical
imaging, industrial inspection etc.
Uses spatial differentiation
Differentiation measures the rate of
change of a function
The Laplacian operator
a b d 0 1 0 0 -1 0
e f g 1 -4 1 -1 4 -1
h i j 0 1 0 0 -1 0
0 -1 0
or -1 4 -1
0 -1 0
Example of Laplacian
0 0 4 0 0 0 -1 0
0 0 4 0 0
4 4 4 4 4 -1 4 -1
0 0 4 0 0
*
0 0 4 0 0 0 -1 0
0 0 4 0 0
0 0
4 4
= 0 0
0 0 4 0 0
The Laplacian
Highlights edges and other discontinuities
- =
Original Positive Laplacian Sharpened
Image Filtered Image Image
0 -1 0
-1 5 -1
0 -1 0
Simplified Image Enhancement
original enhanced
Variants of Laplacian
Simple Laplacian
Variant of Laplacian Considers
Considers horizontal
diagonals of edges
and vertical edges
0 1 0 1 1 1
1 -4 1 1 -8 1
0 1 0 1 1 1
-1 -1 -1
-1 8 -1
-1 -1 -1
Example Variant of Laplacian
1 4 5 2 7 -1 -1 -1
0 4 0 6 2
3 2 1 0 2 -1 8 -1
7 5 2 3 1
*
4 3 2 5 1 -1 -1 -1
1 4 5 2 7
0 16 -24 29 2
3 -6 -14 -17 2
=
7 -16 -5 10 1
4 3 2 5 1
Prewitt Operators
Gx Gy
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1
Gx Gy
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
4 4 4 4 4 1 1 1
4 4 4 4 4
0 0 0 0 0 0 0 0
0 0 0 0 0
*
0 0 0 0 0 -1 -1 -1
4 4 4 4 4
4 12 12 12 4
0 12 12 12 0
= 0 0 0 0 0
0 0 0 0 0
Unsharp (smoothed) Masking and
Highboost Filtering
• Apply averaging filter to blur the original
image
• Subtract the blurred image from the original
image
• Difference is called the mask
• Add weighted mask to the original
Steps for image sharpening
• gmask(x,y) = f(x,y) - fb(x,y)
fb represents blurring
• g(x,y) = f(x,y) + k*gmask(x,y), where, k ≥ 0
k=1, unsharp masking
k>1 , highboost filtering
k<1 , reduces effect of unsharp mask
• g(x,y) can be <0 or >255
• Apply contrast stretching (point processing)
to cover the range 0 to 255
Highboost Filtering
Intensity along a row of image with M rows and N columns
255
edges
20
0 N-1
Highboost Filtering
Intensity along a row of image with M rows and N columns
255
edges
20
0 N-1
edges
20
0 N-1
edges
20
0 N-1
f(x,y)
k=1
k=4.5
Highboost Filtering
f(x,y)
fb(x,y) =
f(x,y)*
h(x,y)
k=1
k=4.5
Highboost Filtering
f(x,y)
fb(x,y) =
f(x,y)*
h(x,y)
gmask(x,y)=
f(x,y)- fb(x,y)
k=1
k=4.5
Highboost Filtering
f(x,y)
fb(x,y) =
f(x,y)*
h(x,y)
gmask(x,y)=
f(x,y)- fb(x,y)
f(x,y) +
k*gmask(x,y),
k=1
k=4.5
Highboost Filtering
f(x,y)
fb(x,y) =
f(x,y)*
h(x,y)
f(x,y)- fb(x,y)
f(x,y) +
k*gmask(x,y),
k=1
f(x,y) +
k*gmask(x,y),
k=4.5