DIP04-Image Enhancement-Spatial Filtering
DIP04-Image Enhancement-Spatial Filtering
Image Filtering 2
What is filtering
Image Filtering 3
What is image filtering
f(x,y) g(x,y)
filtering
filtering
Image Filtering 4
Image filtering methods
Spatial domain
Frequency domain
Image Filtering 5
Spatial domain methods
Image Filtering 6
Point processing methods
Image Filtering 7
Point processing methods-Example
Thresholding
Histogram
Equalization
Image Filtering 8
Limitations of Point Operations
Image Filtering 9
What Point Operations Can’t Do
Blurring/Smoothing
Image Filtering 10
What Point Operations Can’t Do
Sharpening
Image Filtering 11
Spatial Filters
Image Filtering 12
Spatial Filters
Image f(x,y)
(x-1,y+1) (x,y+1) (x+1,y+1)
y
Image Filtering 13
Spatial Filters
x
Image Filtering 14
Operation
Image Filtering 15
Example
10 5 3 0 0 0
4 6 1 0 0.5 0 8
1 1 8 0 1 0.5
Local image mask Modified image data
neighborhood
Image Filtering 16
Correlation
g(i,j)
f(i,j)
filtered
image
Image Filtering 17
Handling pixels close to boundaries
or
Image Filtering 18
Geometric interpretation of correlation
x ( x1 , x2 ,..., xn ) y ( y1 , y2 ,..., yn )
Image Filtering 19
Geometric interpretation of correlation
h(k , l ) f (i k , j l )
n n
k l
N (i, j ) n n
2 2
n n
2 2 2 2
[ h 2 (k , l )]1/ 2 [ f 2 (i k , j l )]1/ 2
n n n n
k l k l
2 2 2 2
Image Filtering 20
Normalized correlation
mask
Image Filtering 21
Application example
Image Filtering 22
Convolution
Image Filtering 23
Convolution example
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
Image Filtering 24
Convolution example
1 1 1 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
Image Filtering 25
Convolution example
2 2 2 3
1 1 1
2 1 3 3
-1 2 1
2 2 1 2
-1 -1 1
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
Image Filtering 26
Convolution example
1 1 1 2 2 2 3
Same
-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
Image Filtering 27
Convolution example
1 1 1 2 2 2 3
Same
-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
Image Filtering 28
Convolution example
2 2 2 3
1 1 1
2 1 3 3
-1 2 1
2 2 1 2
-1 -1 1
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
Image Filtering 29
Convolution example
5 4 4 -2
9 6 14 5
11 7 6 5
9 12 8 5
Final output Image, g
Image Filtering 30
Linear spatial filtering
5x5 9x9
15x15 35x35
Image Filtering 32
Smoothing linear filters
Image Filtering 33
Spatial Filters – smoothing, linear
Mean filters 1 1 1
• example: 1
1 1 1
9
1 1 1
Gaussian noise
Original 5×5
3×3 mean
mean filter
filter
Image Filters 34
Spatial Filters – smoothing, linear
Mean filters 1 1 1
• example: 1
1 1 1
9
1 1 1
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s at b
a b
w(s, t )
s at b
Image Filters 36
Spatial Filters – smoothing, nonlinear
Order-statistic filters
Image Filters 37
Spatial Filters – smoothing, nonlinear
Median filters
• replace a pixel value with the median of its neighboring
pixel values
• example:
23 25 26 30 40
Neighborhood values: 22 24 26 27 35
15, 19, 20, 23, 18 20 50 25 34
24, 25, 26, 27, 50 19 15 19 23 33
Median value: 24 11 16 10 20 30
Image Filters 38
Spatial Filters – smoothing, nonlinear
Median filters
• have excellent noise-reduction capabilities
V.S.
Image Filters 39
Spatial Filters – smoothing, nonlinear
Median filters
• are particularly effective in salt & pepper
V.S.
Max filters
• maximum of neighboring pixel values
• useful for finding the brightest points in an image
Min filters
• minimum of neighboring pixel values
• useful for finding the darkest points in an image
Image Filters 41
Spatial Filters – sharpening
Principal objective
• highlight fine detail in an image
• enhance detail that has been blurred
Sharpening can be accomplished by spatial
differentiation
For one dimensional function f(x)
• first order derivative
f
f ( x 1) f ( x)
x
• second order derivative
2 f
f ( x 1) f ( x 1) 2 f ( x)
x 2
Image Filters 42
Spatial Filters – sharpening
• A sample
Image Filters 43
Spatial Filters – sharpening
x y
= [f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)] -4f(x,y)
Use a convolution mask to approximate
0 1 0 1 1 1 -1 2 -1
1 -4 1 1 -8 1 2 -4 2
0 1 0 1 1 1 -1 2 -1
Image Filters 44
Spatial Filters – sharpening
Image Filters 45
Spatial Filters – sharpening
The Laplacian
• example:
Image Filters 46
Summary
Image Filtering 47