Professional Documents
Culture Documents
Spatial Domain Linear Spatial Domain Linear Filtering
Spatial Domain Linear Spatial Domain Linear Filtering
Filtering
Yao Wang
Polytechnic University, Brooklyn, NY 11201
1 1 1 1 2 1
1
1 1 1 1
2 4 2
9 16
1 1 1 1 2 1
100 100 100 100 100 100 100 100 100 100
100 144 167 145 100 100 156 176 158 100
100 167 200 168 100 100 174 201 175 100
100 144 166 144 100 100 156 175 156 100
100 100 100 100 100 100 100 100 100 100
• Simplified calculation. Hh
k1 l1 k=0
0
g (m, n) h(k , l ) f (m k , n l ) f (m, n) * h(m, n)
k k 0 l l0
W
-W l=0 W
k1 k0 l1 l0 W
g(m, n) h(0,0) f (m, n)
W
h(0,l)( f (m, n l) f (m, n l) f (m l, n) f (m l, n))
l 1
W W
h(k,l)( f (m k, n l) f (m k, n l) f (m k, n l) f (m k, n l))
k 1 l 1
• Symmetrical filter
– 1+W+W2 ~=(W+1)
(W+1)2 multiplications
• Saving
– W = 2,
2 and 512x512 image
– Saving 512*512*(52-32)=222
– More savings for larger W
1 1 1 1 2 1 1 b 1
1 ; 1 2 4 2 ; b b 2 b , with b 1.
1
1 2 1
10 16 (b 2) 2
1 1 1 1 2 1 1 b 1
• Image signal usually varies slowly, and noise is usually a wide band
signal.
• A l i a llow pass filt
Applying filter removes th
the hi
high-frequency
hf partt off the
th
noise.
• Image edges and other details are blurred
Filter response
Noise spectrum
0 f
1 1 1 1 1 b 1 1
H 1 1 1 11 1 1;
1 1 b b 2 b b 1 b 1;
1 1
H
9 9 ( 2 b) 2 ( 2 b) 2
1 1 1 1 b 1 1
1
H (u , v) 1 2 cos(2u ) 1 2 cos(2v) / 9 H (u , v) b 2 cos(2u ) b 2 cos(2v) /( 2 b) 2
1
1
0.8
0.5
0.6
0 0.4
0.2
-0.5
30 0
30
25
20
20 25
15 20
20
10 10 15
5 10 10
0 0 5
0 0
b=2
D3
• Usuallyy 4 or 8 directions
• 3 core steps
– Find σi2, the variance in Di D1
– Find i0, so that σi02 ≤σi2
– Filtering in i01direction
g (m, n)
N io
( k ,l )Dio
f (m k , n l )
y x n , where n ~ N (0, 2 / N )
1 1 1
h
1 1 1
Non-Edge
Non Edge
No
g Yes
f H |g|>T Edge
fx
g Edge
Hx fx2+fy2 |g|>T
Hy tan-1(fx/fy) theta
fy
|Hx(u)| |Hy(v)|
Band-pass
Low-pass
Yao Wang, NYU-Poly EL5123: Spatial Filtering 28
Spectrum of the Sobel Filter
10
5
Hx
0
40
40
20 20
0 0
10
5
Hy
0
40
40
20 20
0 0
L
Low pass along
l th
the edge,
d b
band
d pass cross th
the edge
d
2000
1500
1000
500
0
0 100 200
x y
f
f
f ( x 1, y ) f ( x, y )
x
2 f
f ( x 1, y ) 2 f ( x, y ) f ( x 1, y )
x 2
2 f
f ( x, y 1) 2 f ( x, y ) f ( x, y 1)
y 2
2f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )
0 1 0 0 1 0
1 4 1; 1 4 1;
0 1 0 0 1 0
0 1 0 1 1 1
1 4 1 1 8 1
0 1 0 1 1 1
6 12
10
4
8
2 6
4
0
30 2
0
20 30
25
10 20
25 20
20 15
15 10
10 10
0 5 5
0
0 0
More isotropic
x2 y2
2G 2G x 2 y 2 2 2
2 2
G ( x, y )
2
e
2x 2 y 4
0 f
f s f f h
all pass
high pass
0 f
h(k , l ) 0
k k 0 l l0
6 12
10
4
8
2 6
4
0
30 2
0
20 30
25
10 20
25 20
20 15
15 10
10 10
0 5 5
0
0 0
More isotropic
x x x
0 1 0 0 1 0
H h 1 4 1 H s 1 8 1 with 1.
1 1
4 4
0 1 0 0 1 0
1 1 1 1 1 1
H h 1 8 1 H s 1 16 1 with 1.
1 1
8 8
1 1 1 1 1 1
0 1 0
H h 1 8 1
1
4
0 1 0
4
8
• Sharpening filter
hs (m, n)
1
(m, n) hl (m, n)
1
all pass
low pass
0 f
x x x
1 2 1 1 2 1
1 1 1
H l 2 4 2 H s 2 60 2 with .
16 48 4
1 2 1 1 2 1
Criteria for designing sharpening filters: There are both positive and negative
Coefficients h(0
Coefficients, h(0,0)
0) > 0
0, and ∑h(k,
∑h(k l)=1
l) 1 (to keep the same mean value)
value).
Taking an image without injecting a contrast agent first. Then take the image again after
the organ is injected some special contrast agent (which go into the bloodstreams only).
Then subtract the two images --- A popular technique in medical imaging
1 2 1 1 1 1 0 1 0
H 1 2 4 2 H 2 1 8 1;
1
H 3 1 5 1
16
1 2 1 1 1 1 0 1 0
G ( x, y ) e 2 2
2. Write a Matlab or C-program for implementing the following simple edge detection algorithm:
For every pixel: i) find the horizontal and vertical gradients, gx and gy, using the Sobel operator;
ii) calculate the magnitude of the gradient using g m g x g y ; and iii) For a chosen
2 2
threshold T, consider the pixel to be an edge pixel if gm ≥ T. Save the resulting edge map (Use
a gray level of 255 to indicate an edge pixel, and a gray level of 0 for a non-edge pixel). Apply
this program to your test image, and observe the resulting edge map with different T values,
until
u t you find
d a T tthat
at gives
g es you a good result.
esu t Hand
a d in you
your p
program
og a aand
d tthe
e edge maps
aps
generated by two different threshold values. Write down your observation. Hint: one automatic
way to determine T is by sorting the pixels based on the gradient magnitudes, and choose T
such that a certain percentage (say 5%) of pixels will be edge pixels. You can use either the
matlab conv2( ) function or write your own code for the filtering part.
For problems 2 and 3, try to use an image that has a lot of edges. A good set of test
images can be found under the matlab directory …./toolbox/images/imdemos