Lec_09 SIP CIS-322 Spatial Fil (2)
Lec_09 SIP CIS-322 Spatial Fil (2)
•NOT
•AND
•OR
Arithmetic and Logic Operation
• Arithmetic and logic operation involving
images are performed on a pixel-by-pixel
basis between two or more images.
• NOT operation is performed on single image.
Negative transformation is performed by this
operation.
• AND & OR operation are used for masking
purpose. (For selecting sub-images in an
image). Some time masking is called Region
of Interest (ROI) processing.
Logic Operation
Arithmetic and Logic Operation
• Addition and subtraction are the most useful
operation for image enhancement.
d. Averaging
c. Averaging of of 16 images
8 images
f. Averaging of
e. Averaging of 128 images
64 images
Image averaging
a-c
a-d
a-e
a-f
Spatial Filtering
Background
• Filter term in “Digital image processing” is
referred to the sub-image
• There are others term to call sub-image
such as mask, kernel, template, or window
• The values in a filter sub-image are referred
as coefficients, rather than pixels.
Basics of Spatial Filtering
• The concept of filtering has its roots in the use
of the Fourier transform for signal processing in
the so-called frequency domain.
a b
g ( x, y ) w(s, t ) f ( x s, y t )
s at b
where
x = 0, 1, 2, 3…..M-1
y = 0, 1, 2, 3…..N-1
Discussion
• The process of linear filtering similar to a
frequency domain concept called
“convolution”
Simplify expression mn
R w1 z1 w2 z2 ... wmn zmn wi zi w1 w2 w3
i 1
9 w4 w5 w6
R w1 z1 w2 z2 ... w9 z9 wi zi w7 w8 w9
i 1
Where the w’s are mask coefficients, the z’s are the value of
the image gray levels corresponding to those coefficients
Nonlinear spatial filtering
• Nonlinear spatial filters also operate on
neighborhoods, and the mechanics of sliding
a mask past an image are the same as was
just outlined.
2. Order-Statistics Filters
Smoothing Linear Filters
• Linear spatial filter is simply the average of
the pixels contained in the neighborhood of
the filter mask.
1 1 1 1 2 1
1 1
1 1 1 2 4 2
9 16
1 1 1 1 2 1
1 1 1 1 1
1 1 1 1 1
11
1 1 1 1 1
25
?
1 1 1 1 1
1 1 1 1 1
Smoothing Linear Filters
• The general implementation for filtering an
MxN image with a weighted averaging filter
of size mxn is given by the expression
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s at b
a b
w(s, t )
s at b where
x = 0, 1, 2, 3…..M-1
y = 0, 1, 2, 3…..N-1
Result of Smoothing Linear Filters
Original Image
5th
Result of median filter
f
f ( x 1) f ( x)
x
Definition of the 2nd-order derivative
• We define a second-order derivative as the
difference
2 f
f ( x 1) f ( x 1) 2 f ( x).
x 2
Gray-level profile
000123200226332233000000776553
7
6
5
4
3
2
1
0
Derivative of image profile
0 0 0 1 2 3 2 0 0 2 2 6 3 3 2 2 3 3 0 0 0 0 0 0 7 7 6 5 5 3
second 0-1 0 0-2-1 2 2-2 4-7 3-1 1 1-1-3 3 0 0 0 0-7 7-1 0 1-2
Analyze
• The 1st-order derivative is nonzero along the
entire ramp, while the 2nd-order derivative is
nonzero only at the onset and end of the
ramp.
2
f 2
f
f 2 2
2
x y
f(x,y) 2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
f(x+1,y)
2 f
f(x,y-1) f(x,y) f(x,y+1) f ( x, y 1) f ( x, y 1) 2 f ( x, y)
y 2
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )
f(x-1,y)
0 1 0
f(x,y-1) f(x,y) f(x,y+1) 1 -4 1
0 1 0
f(x+1,y)
2-Dimentional Laplacian
• The digital implementation of the 2-Dimensional
Laplacian is obtained by summing 2 components
2
f 2
f
2 f 2 2
x x
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )
0 1 0
It gives an isotropic result for
1 -4 1
rotations in increments of 90°.
0 1 0
Incorporation of diagonal directions
2 f
f ( x 1, y 1) f ( x 1, y 1) 2 f ( x, y )
x 2
2 f
f ( x 1, y 1) f ( x 1, y 1) 2 f ( x, y)
y 2
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)
f ( x 1, y 1) ( x 1, y 1) f ( x 1, y 1) f ( x 1, y 1)
8 f ( x, y )
Laplacian
This mask yields isotropic results for increments of 45°.
0 1 0 1 1 1
1 -4 1 1 -8 1
0 1 0 1 1 1
1 0 1
0 -4 0
1 0 1
Laplacian
This mask yields isotropic results for increments of 45°.
0 -1 0 -1 -1 -1
-1 4 -1 -1 8 -1
0 -1 0 -1 -1 -1
-1 0 -1
0 4 0
-1 0 -1
Implementation
f ( x, y ) 2 f ( x, y ) If the center coefficient is negative
g ( x, y )
f ( x , y ) 2
f ( x, y ) If the center coefficient is positive
g ( x, y) f ( x, y) f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1) 4 f ( x, y)
g ( x, y) 5 f ( x, y) f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1)
0 -1 0 -1 -1 -1
-1 5 -1 -1 9 -1
0 -1 0 -1 -1 -1
Unsharp masking
• A process to sharpen images consists of subtracting a
blurred version of an image from the image itself.
This process, called unsharp masking, is expressed as
f s ( x, y) f ( x, y) f ( x, y)
f s ( x, y )
Where denotes the sharpened image obtained by
unsharp masking, and f ( x, y ) is a blurred version of f ( x, y)
High-boost filtering
• A high-boost filtered image, fhb is defined at any point
(x,y) as
f hb ( x, y) Af ( x, y) f ( x, y) where A 1
f hb ( x, y) ( A 1) f ( x, y) f ( x, y) f ( x, y)
f hb ( x, y ) ( A 1) f ( x, y ) f s ( x, y )
Af ( x, y ) 2 f ( x, y )
f hb If the center coefficient is negative
Af ( x, y ) f ( x, y ) If the center coefficient is positive
2
0 -1 0 -1 -1 -1
-1 A+4 -1 -1 A+8 -1
0 -1 0 -1 -1 -1
The Gradient (1st order derivative)
f
Gx x
f f
G y
y
Gradient
• The magnitude of this vector is given by
Gy 1
-1
Robert’s Method
• The simplest approximations to a first-order
derivative that satisfy the conditions stated in that
section are
z4 z5 z6 f ( z9 z5 ) 2 ( z8 z6 )2
z7 z8 z9 f z9 z5 z8 z6
Robert’s Method
• These mask are referred to as the Roberts
cross-gradient operators.
-1 0 0 -1
0 1 1 0
Sobel’s Method
• Mask of even size are awkward to apply.
• The smallest filter mask should be 3x3.
• The difference between the third and first
rows of the 3x3 mage region approximate
derivative in x-direction, and the difference
between the third and first column
approximate derivative in y-direction.
Sobel’s Method
• Using this equation
f ( z7 2 z8 z9 ) ( z1 2 z2 z3 ) ( z3 2 z6 z9 ) ( z1 2 z4 z7 )
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
Homework
• Implement the following filters with MATLAB
– Laplacian
– High-boost with laplacian
– Gradient
– Robert
-1 -2 -1 -1 -2 -1
– Sobel
-2 12 -2 -2 -12 -2
– my mask
-1 -2 -1 -1 -2 -1
Questions?
Questions?
Questions?
Questions?
Questions?
Questions?