0% found this document useful (0 votes)
5 views

lecture_5

Uploaded by

bariskaya28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

lecture_5

Uploaded by

bariskaya28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Digital Image Processing

Spatial Domain Filtering

Dr. LavdieRADA
([email protected])
• Spatial domain operation or filtering is the processed
value for the current pixel depending on both itself
and surrounding pixels.
• Type of filters
– Linear filtering
– Non-linear filtering ( Rank order filtering including median;
Morphological filtering)
– Adaptive filtering
Spatial Domain Filtering and Application in Noise
Removal and Edge Detection

• Noise removal using low-pass filters


• Sharpening by edge enhancement
• Edge detection – First order gradient – Second
order gradient
Spatial Filtering

w(-1,-1) w(-1,0) w(-1,1)


Mask coefficients showing
w(0,-1) w(0,0) w(0,1)
coordinate arrangement
w(1,-1) w(1,0) w(1,1)
Correlation

a b
g( x, y )    ω( s,t ) f ( x  s, y  t )
s  a t  b

g  ω f

R   (1, 1) f ( x  1, y  1)   (1, 0) f ( x  1, y)  ...


  (0, 0) f ( x, y)  ...   (1, 0) f ( x  1, y)  (1,1) f ( x  1, y  1)
Correlation
correlation kernel, ω

1 -1 -1
Input Image f
1 2 -1
2 2 2 3
1 1 1
2 1 3 3
Don’t rotate use it directly
2 2 1 2
1 3 2 2
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
1 2 -2
4 2 2 3 5
1 2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 -2
4 2 3 5 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 -3
4 3 5 10 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 3
6 -1 5 10 10 15
2 1 3 3 1 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2

1 -2
2 -2
2 2 3 5 10 10 15
1 4
2 -1
1 3 3 3 output
Image, g
1 2 2 1 2
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2

2 -2
2 -2
2 3 5 10 10 15
2 2
1 -3
3 3 3 4 output
Image, g
2 2 1 2
1 3 2 2

Input Image, f
Correlation

5 10 10 15
3 4 6 11
7 11 4 9
-5 4 4 5
Final output Image, g
Convolution

a b
g( x, y )    ω( s,t ) f ( x  s, y  t )
s  a t  b

g  ω f
Convolution
Convolution kernel, ω Input Image, f

1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
Rotate 180o 1 3 2 2
1 1 1
-1 2 1
-1 -1 1
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2
-1 4 2 2 3 5
Output
2 1
-1 -2 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 4
-2 2 2 3 5 4
Output
2 -1
-2 1 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 -2
2 4
2 3 5 4 4
Output
2 -1
1 -3
3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 2 2 3
-2 6 1 5 4 4 -2
Output
2 1 3 -3
-3 3 1 Image, g
2 2 1 2
1 3 2 2
Input Image, f
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2

1 2 2 2 3 5 4 4 -2
Output
-1 4
2 1 3 3 9 Image, g
-1 -2
2 2 1 2
1 3 2 2
Input Image, f
1 1 1 Convolution 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2

2 2 2 3 5 4 4 -2
Output
-2
2 2
1 3 3 9 6 Image, g

2 -2
-2 2 1 2
1 3 2 2
Input Image, f
Convolution
5 4 4 -2
9 6 14 5
11 7 6 5
9 12 8 5
Final output Image, g
Smoothing Spatial Filters

Types of Smoothing Filters : linear and nonlinear

Smoothing Linear Filters : known as averaging filter or low-


pass filters (such filter retains low frequency and suppresses high
frequency = low-pass filter).
Smoothing Linear Filters

Box filter Weighted average


(Barlett filter) filter

Replace each pixel by the average of pixels in a square window


surrounding this pixel

Trade-off between noise removal and detail preserving:


– Larger window -> can remove noise more effectively, but also blur the
details/edges
Smoothing Linear Filters
Original 3x3

5x5 9x9

15x15 35x35

© 2002 R. C. Gonzalez & R. E. Woods


Smoothing Linear Filters

original blurred thresholded

© 2002 R. C. Gonzalez & R. E. Woods


Order-Statistics Filters

Median filter
a1 < a2 < … < a n then median is a(1+n)/2

Given
18 22 33
34 128 24
22 19 32

Ascending order is 18 19 22 22 24 32 33 34 128


18 22 33
34 24 24
22 19 32
Median filters

Corrupted by salt Averaging Median


and pepper noise filter filter

© 2002 R. C. Gonzalez & R. E. Woods


Sharpening Spatial Filters

f
 f ( x  1)  f ( x)
x
2 f
 f ( x  1)  f ( x)  ( f ( x)  f ( x  1))
x 2

 f ( x  1)  f ( x  1)  2 f ( x)
Sharpening Spatial Filters
The Laplacian
 2
f  2
f
 f  2  2
2

x y
2 f
 f ( x  1, y)  f ( x  1, y)  2 f ( x, y)
x 2

2 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y)
y 2
Sharpening Spatial Filters
The 2D Laplacian

2 f   f ( x  1, y )  f ( x  1, y )  f ( x, y  1)  f ( x, y  1)  4 f ( x, y )
Sharpening Spatial Filters
The 2D Laplacian
Sharpening Spatial Filters
The 2D Laplacian
If the center coefficient of
 f ( x, y )   f ( x, y )
2
the Laplacian mask is
 negative

g ( x, y )  
 If the center coefficient of
 f ( x, y )  2 f ( x, y ) the Laplacian mask is
positive

It reinforces line and edges detail.


Sharpening Spatial Filters
The 2D Laplacian
The First Derivatives for Enhancement
The Gradient
 f 
Gx   x 
f      f 
G y   
 y 

 
2
 f   f 
2
2 1/ 2
f  mag (f )  Gx  G y      
2

 x   y 
The First Derivatives for Enhancement
The Gradient
f  Gx  Gy

f  Gx  G y  ( z7  2 z8  z9 )  ( z1  2 z2  z3 )
 ( z3  2 z6  z9 )  ( z1  2 z4  z7 )
The First Derivatives for Enhancement
The Sobel Operator
The First Derivatives for Enhancement
The Sobel Operator

Horizontal Vertical
Summary
•We have looked at:
– What are statistical filters.
– What are Laplacian and Gradient.
– What is Sobel operator.

You might also like