Spatial Filtering
Spatial Filtering
Background
Filter term in Digital image
processing is referred to the
subimage
There are others term to call
subimage such as mask, kernel,
template, or window
The value in a filter subimage are
referred as coefficients, rather than
pixels.
Linear spatial
filtering
Pixels of image
w(-1,-1) w(-1,0) w(-1,1)
f(x-1,y-1)
f(x-1,y)
f(x-1,y+1)
w(0,-1)
w(0,0)
w(0,1)
w(1,-1)
w(1,0)
w(1,1)
w(0,-1)
w(0,0)
w(0,1)
Linear filtering
In general, linear filtering of an
image f of size MxN with a filter
mask of size mxn is given by the
expression: a b
g ( x, y )
w(s, t ) f ( x s, y t )
s at b
Discussion
The process of linear filtering
similar to a frequency domain
concept called convolution
Simplify expression
mn
R w1 z1 w2 z 2 ... wmn z mn wi zi
9
i 1
R w1 z1 w2 z 2 ... w9 z9 wi zi
i 1
w1 w2 w3
w4 w5 w6
w7 w8 w9
Standard average
16
Weighted average
25
?
g ( x, y )
w(s, t ) f ( x s, y t )
s at b
w(s, t )
s at b
[3x3]
[5x5]
[7x7]
Order-Statistics Filters
Order-statistics filters are nonlinear
spatial filters whose response is based
on ordering (ranking) the pixels
contained in the image area
encompassed by the filter, and then
replacing the value of the center pixel
with the value determined by the
ranking result.
Best-known median filter
5th
Homework
smoothing filter
mask standard 3x3, 5x5, 7x7, 9x9
source code
median filter mask 3x3,
5x5,7x7,9x9 source code
100x100
filter
Introduction
The image blurring is accomplished
in the spatial domain by pixel
averaging in a neighborhood.
Since averaging is analogous to
integration.
Sharpening could be accomplished
by spatial differentiation.
Foundation
We are interested in the behavior of
these derivatives in areas of constant
gray level(flat segments), at the
onset and end of discontinuities(step
and ramp discontinuities), and along
gray-level ramps.
These types of discontinuities can be
noise points, lines, and edges.
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x).
2
x
Gray-level profile
000123200226332233000000776553
7
6
5
4
3
2
1
0
first
second
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.
1st make thick edge and 2nd make thin edge
f
2
f 2 2
x
y
f(x,y)
f(x+1,y)
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
2
x
f(x,y-1)
f(x,y)
f(x,y+1)
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
2
y
2-Dimentional Laplacian
The digital implementation of the 2Dimensional Laplacian is obtained by
2
2components
summing
2
f
2
f
x 2
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )
1
1
-4
1
Laplacian
0
-4
-8
-4
Laplacian
0
-1
-1 -1 -1
-1
-1
-1
-1
-1 -1 -1
-1
-1
-1
-1
-1
Implementation
f ( x, y ) 2 f ( x, y ) If the center coefficient is negative
g ( x, y )
2
f
(
x
,
y
)
Implementation
Implementation
Filtered = Conv(image,mask)
Implementation
filtered = filtered - Min(filtered)
filtered = filtered * (255.0/Max(filtered))
Implementation
sharpened = image + filtered
sharpened = sharpened - Min(sharpened )
sharpened = sharpened * (255.0/Max(sharpened ))
Algorithm
Using Laplacian filter to original
image
And then add the image result
from step 1 and the original image
Simplification
We will apply two step to be one mask
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)
-1
-1 -1 -1
-1
-1
-1
-1
-1 -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 )
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 )
-1
-1
-1
-1
-1 A+4 -1
-1 A+8 -1
-1
-1
-1
-1
Gy
Gradient
The magnitude of this vector is given by
mag (f ) Gx2 G y2 Gx G y
Gx
-1
Gy
1
-1
Roberts Method
The simplest approximations to a firstorder derivative that satisfy the
conditions stated in that section are
z1
z2
z3
z4
z5
z6
f ( z 9 z 5 ) 2 ( z 8 z 6 ) 2
z7
z8
z9
f z 9 z 5 z8 z 6
Roberts Method
These mask are referred to as the
Roberts cross-gradient operators.
-1
-1
Sobels 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.
Sobels Method
Using this
equation
f ( z7 2 z8 z9 ) ( z1 2 z 2 z3 ) ( z3 2 z6 z9 ) ( z1 2 z 4 z7 )
-1
-2
-1
-1
-2
-1
Homework
sharpening
filter
Laplacian
High-boost with laplacian
-1 -2 -1
-1 -2 -1
Gradient
-2 12 -2
-2 -12 -2
Robert
-1 -2 -1
-1 -2 -1
Sobel
my mask