Beruflich Dokumente
Kultur Dokumente
Spatial filtering
fundamentals
by Gleb V. Tcheslavski: gleb@ee.lamar.edu
http://ee.lamar.edu/gleb/dip/index.htm
1
4/28/2008
In general:
a b
g ( x, y ) = ∑ ∑ w(s, t ) f ( x + s, y + t )
s =− a t =− b
For a 3 x 3 mask
2
4/28/2008
3
4/28/2008
4
4/28/2008
For example,
p , for a 3 x 3 filter:
9
R = ∑ wk zk = w T z
k =1
5
4/28/2008
∑ ∑ w(s, t ) f ( x + s, y + t )
g ( x, y ) = s =− a t =− b
a b
∑ ∑ w(s, t )
s =− a t =− b
6
4/28/2008
Smoothing spatial
filters
The effect of filter size.
The original 500x500 image
7
4/28/2008
8
4/28/2008
9
4/28/2008
∂x ∂y
Therefore:
∇ 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
The Laplacian is a linear operator since derivatives are linear
operators.
10
4/28/2008
g ( x, y ) = f ( x, y ) + c ⎡⎣∇ 2 f ( x, y ) ⎤⎦
Output Input -1 – if the center is negative; +1 -
intensity intensity otherwise
11
4/28/2008
The image
sharpened
with mask 2
The image sharpened
with mask 1
g ( x, y ) = f ( x, y ) + k ⋅ g mask ( x, y )
Here k is a weight.
12
4/28/2008
Unsharp mask
13
4/28/2008
Gradient method
First derivatives can be implemented for nonlinear image
sharpening using the magnitude of the gradient:
⎡ ∂f ⎤
⎡ x ⎤ ⎢ ∂x ⎥
g
∇f ≡ grad ( f ) ≡ ⎢ ⎥ = ⎢ ⎥
⎣ g y ⎦ ⎢ ∂f ⎥
⎢⎣ ∂y ⎥⎦
The gradient vector points in the direction of the greatest rate of
g of f at location ((x,y).
change y) The magnitude
g ((length)
g ) of g
gradient
M ( x, y ) = ∇f = g x2 + g y2
Gradient method
M(x,y) is an image of the same size as the original and is called
the gradient image. Magnitude makes M(x,y) non-linear. It is
more ssuitable
itable in some applications to use:
se
M ( x, y ) ≈ g x + g y
For an image where z5 represent the pixel f(x,y) and z1 represent the
pixel f(x-1,y-1), the simplest (Roberts) definitions for gradients are:
M ( x, y ) = ( z9 − z5 ) + ( z8 − z6 )
2 2
M ( x, y ) ≈ z9 − z5 + z8 − z6
However, Roberts cross-gradient operators lead to
masks of even sizes, which is inconvenient.
14
4/28/2008
Gradient method
The smallest masks with central symmetry (ones we are
interested in) are 3x3. The gradient can be approximated for
such masks as following:
∂f
gx = = ( z7 + 2 z8 + z9 ) − ( z1 + 2 z2 + z3 ) Roberts operators
∂x
∂f
gy = = ( z3 + 2 z6 + z9 ) − ( z1 + 2 z4 + z7 )
∂y
Therefore, the mask could be:
M ( x, y ) ≈ ( z7 + 2 z8 + z9 ) − ( z1 + 2 z2 + z3 )
+ ( z3 + 2 z6 + z9 ) − ( z1 + 2 z4 + z7 )
Gradient method
The coefficients in all masks shown sum to zero. This indicates
that mask will give a zero response in an area of constant
intensity as expected of a derivative operator
operator.
Defect
Spring 2008 ELEN 4304/5365 DIP 30
15
4/28/2008
16