- Dr. Iyad Jafar
Digital Image Analysis and Processing CPE 0907544
Image Enhancement –Part II Spatial Filtering
Chapter 3 Sections : 3.4-3.7
Digital Image Analysis and Processing CPE 0907544 Image Enhancement - - PowerPoint PPT Presentation
Digital Image Analysis and Processing CPE 0907544 Image Enhancement Part II Spatial Filtering Chapter 3 Sections : 3.4-3.7 Dr. Iyad Jafar Outline Introduction Mechanics of Spatial Filtering Correlation and Convolution
Chapter 3 Sections : 3.4-3.7
2
3
A spatial filter is characterized by
A rectangular neighborhood of size mxn (usually m and n are odd) A predefined operation that is specified by the mask values at each
position.
3x3 filter mask example
Spatial filtering Operation
The filter mask is centered at each pixel in the image and the output
pixel value is computed based on the operation specified by the mask
4
w(-1,-1) w(-1,0) w(-1,1) w(0,-1) w(0,0) w(0,1) w(1,-1) w(1,0) w(1,1)
Origin
x y
Image f (x, y) (x, y) Neighbourhood
5
Origin x y Image f (x, y)
3x3 Filter
Filter Original Image Pixels
a b s a t b
g( x,y ) w( s,t ) f ( x s,y t )
w(-1,-1) w(-1,0) w(-1,1) w(0,-1) w(0,0) w(0,1) w(1,-1) w(1,0) w(1,1) f(x-1,y-1) f(x-1,y) f(x-1,y+1) f(x,y-1) f(x,y) f(x,y+1) f(x+1,y-1) f(x+1,y) f(x+1,y+11)
The previous filtering equation can be written as If we represent the coefficients of the filter mask as a
6
w1 w2 w3 w4 w5 w6 w7 w8 w9
T
1 1 2 2 1 mn mn mn k k k
R w z w z ... w z = w z
The
In 1-D
7
0 0 0 1 0 0 0 0 1 2 3 2 8 f w
Origin
0 0 0 1 0 0 0 0 1 2 3 2 8 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 3 2 8 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 3 2 8
1) Function and mask 2) Initial Alignment 3) Zero Padding for f by m-1 4) Position after one shift
8
1 2 3 2 8 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
5) Position after 4 shifts Full correlation result Cropped correlation result
0 0 0 8 2 3 2 1 0 0 0 0
6) Repeat
1 2 3 2 8 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
Final Position
0 8 2 3 2 1 0 0
9
10
0 0 0 1 0 0 0 0 8 2 3 2 1 f w
Origin
0 0 0 1 0 0 0 0 8 2 3 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 8 2 3 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 3 2 8
1) Function and mask 2) Initial Alignment after rotation of mask 3) Zero Padding for f by m-1 4) Position after one shift
11
8 2 3 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
5) Position after 4 shifts Full convolution result Cropped convolution result
0 0 0 1 2 3 2 8 0 0 0 0
6) Repeat
8 2 3 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
Final Position
0 1 2 3 2 8 0 0
12
Extension to 2D is straight forward
Zero padding is done in both directions by m-1 and n-1 In convolution, the mask is flipped vertically and
1 1 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 f
Zero padding by m-1 and n-1
w
Mask rotation
13
9 8 7 6 5 4 3 2 1 1
Initial position in convolution
1 2 3 4 5 6 7 8 9 1
Initial position in correlation
14
9 8 7 6 5 4 3 2 1
Full convolution result
1 2 3 4 5 6 7 8 9
Full correlation result
15 Cropped convolution result
1 2 3 4 5 6 7 8 9
Cropped correlation result
9 8 7 6 5 4 3 2 1
a b s a t b
Correaltion g( x,y ) w( s,t ) f ( x s,y t )
a b s a t b
Convolution g( x,y ) w( s,t ) f ( x s,y t )
In the previous slides, we padded the image with zeros
Other approaches
Replicate edge pixels Consider only available
Allow pixels to wrap
16
x y Image f (x, y)
e e e e e e e
The result depends on the used approach Example 3.6
17
Original Image Filtered Image: Zero Padding Filtered Image: Replicate Edge Pixels Filtered Image: Wrap Around Edge Pixels
A smoothing (averaging, blurring) filter replaces each
Uses of smoothing filters
The smoothed image correspond to the gross details
Can be used to reduce noise as it is characterized with
However, smoothing usually results in degradation of
18
Common smoothing masks
Notes
The weighted average filter gives more weight to pixels
near the center
It is hard to see the visual difference between the
processing results of the two filters; however, the weighted average filter coefficients sum up to 16, which makes it more attractive for computers
19
1 1 1 1 1 1 1 1 1 X 1/9 1 2 1 2 4 2 1 2 1 X 1/16 Standard averaging mask Weighted average mask
Example: 3.7 Smoothing with different mask sizes. Notice the
loss of details as the mask size increases
20
Original Smoothing by 3x3 Mask Smoothing by 5x5 Mask Smoothing by 9x9 Mask Smoothing by 15x15 Mask Smoothing by 35x35 Mask
21
Original Image Smoothed Image Thresholded Image
22
Original Smoothed
The principle objective of sharpening is to highlight
If we examine the smoothing operation we can think
Thus to perform sharpening in the spatial domain, it is
In
23
Lets discuss differentiation for the1-D case We are concerned about the behavior of 1st and 2nd
Constant intensity Onset and end of discontinuities (ramps and steps discontinuities) Intensity ramps
Properties of 1st derivative
Zero in areas of constant intensity Nonzero at the onset of a step and intensity ramp Nonzero along intensity ramp
Properties 2nd derivative
Zero in areas of constant intensity Nonzero at the onset and end of a step and intensity ramp Zero along intensity ramp
24
Derivatives can be approximated as differences 1st derivative at x 2nd derivative at x
25
2 2
Investigation of the derivatives behavior
26
Notes Examining the 1st and 2nd derivatives plots shows
1st derivative produces thicker edges than 2nd
2nd derivative produces double edge separated by a
2nd derivative is commonly used in sharpening since
27
The second derivative (Laplacian) in 2-D is defined as
2 2 2 2 2
2 2
1 1 2 f f ( x ,y ) f ( x ,y ) f ( x,y ) x
2 2
1 1 2 f f ( x,y ) f ( x,y ) f ( x,y ) y
2
28
The Laplacian can be implemented as a filter mask Or
1 1
1 1 1 1 1 1
1 1 1 1
29
Computing the Laplacian doesn’t produce a sharpened
It is common practice to scale the Laplacian image to [0,255] for better display
30
Alternatively,
31
2
Original Image Laplacian Filtered Image Sharpened Image
The two steps required to achieve sharpening can be
2
32
As a filter mask, the previous equation can be represented
33
The first derivative in 2-D is implemented as a gradient
The gradient points in the direction of greatest rate of
The magnitude of the gradient is defined as
34
y x
1 2 2 2
x y
Computation of the gradient using Roberts
Roberts operators for computing Gx and Gy are shown
35
2 9 5 9 5 2 8 6 8 6 9 5 8 6 x y
1
1 Horizontal Operator Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9 Pixel z5 and its neighbours Vertical Operator
Computation of the gradient using Sobel
Sobel operators for computing Gx and Gy are shown
1
2
1
1 2 1
36
7 8 9 1 2 3 3 6 9 1 4 7
x y x y
Mask to Compute Gx Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9 Pixel z5 and its neighbours Mask to Compute Gy
Example 3.10
Gradient is widely used in industrial inspection as it
37
Optical Image for a contact lens Gradient Image
Examples
minimum filter, maximum filter, median filter
popular and useful in removing impulse or salt-and-pepper noise
with less blurring than linear smoothing
38
Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9
New value
Example 3.11
39
It is very common to combine
Example 3.12
We want to enhance/sharpen the
Direct application of the
40
41
Processed by a combination of methods Sharpened by Laplacian Histogram Equalization
Power-Law with gamma = 0.5
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)
42
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
43
44
45
46