Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 5 Mask/Filter Transformation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Lecture 5 Mask/Filter Transformation

1. Math foundation of filtering


2 Smoother filters
2.
3. Filter transformation with MatLab
Foundation of image acquisition and filtering
• Point light source => image acquisition (lens) => Point spread (sensor)

y y
x x
Lens (passive)

Point light source unit energy Point spread

• Intensity distribution of the unit light energy


y
n y
h(x)
x L

1 1 x
2n 2n

⎧ 1 h( x) = L[ Pn ( x)]
⎪⎪ n , | x |≤ 2n ∞
Pn ( x ) = ⎨ ,E = ∫ Pn ( x ) dx = 1 ∞
⎪ 0, | x |>
⎪⎩
1
2n
−∞
∫−∞
h( x)dx = 1
Foundation of Image Acquisition
• Ideal unit energy point intensity function
y
δ(x) y
h(x)
x L
x

h( x) = L[δ( x)]
⎧∞, x = 0 ∞
δ(x) = ⎨ , ∫ δ(x)dx = 1 ∞
⎩ 0, x ≠ 0 −∞ ∫−∞
h( x)dx = 1
Properties of Lens Transformation
• Lens transformation system
in p u t ⎯ L⎯
→ o u tp u t
δ ( x ) ⎯ L⎯
→ h(x)
f ( x ) ⎯ L⎯
→ g (x)
• Linear Shift-Invariant System (LSI): If the system L has the properties
(a) Homogeneity: Af ( x ) ⎯ L⎯ → Ag ( x )
(b) Shift-invariant: δ ( x − s ) ⎯⎯ L
→ h( x − s)
(c) Superposition: f1 ( x ) + f 2 ( x ) ⎯ L⎯
→ g1 ( x ) + g 2 ( x )

y
δ( x − s) h( x − s)
x L
x
s s
δ ( x − s1 ) δ ( x − s2 ) h(x − s2 )
y h( x − s )1

x L
s1 s2 x
s1 s2
Signals in LSI

• By homogeneity and shift-invariant:

f ( s )δ( x − s ) ⎯ ⎯
→ f ( s)h( x − s)
L

• Then by superposition
1 K
f ( x ) = L im ∑ f ( si ) Pn ( x − si )
n→∞ n
i=0
∞ ∞
= ∫
−∞
f ( s ) δ ( x − s ) ds
f ( x )
⎯⎯
→ g ( x) =
L

−∞
f ( s ) h ( x − s ) ds
y g ( x )

x L
s1 s2 s3 s4 s x

δ(x − s)
Convolution

• Definition: ∞
f ( x) ∗ h( x) = ∫
−∞
f ( s ) h ( x − s ) ds

f(x) convoluted with h(x), or convolution of f(x) with h(x)

• IIn a LSI system,


t signal
i l received
i d g(x)
( ) th
the convolution
l ti off iinputt f(
f(x)) with
ith
impulse response h(x). As long as we know f(x) and h(x), we can
compute the output signal by their convolution
Example of Convolution

Given
⎧ 1
⎧ 1, x≥0 ⎪ 1,
, | x |≤
f ( x) = ⎨ , h( x) = ⎨ 2
⎩ 0, x<0 ⎪⎩ 0, else
Compute f(x)
f(x)*h(x)
h(x)
Sol: See the next slide for the case analysis ∞ ∞
Case 1: x < -1/2, g ( x ) = f ( x ) ∗ h ( x ) = ∫−∞ f ( s ) h ( x − s ) ds = ∫ −∞
0 ds = 0
1
∞ x+ 1
Case 2: |x|<1/2, g ( x ) = f ( x ) ∗ h ( x ) = ∫
−∞
f ( s ) h ( x − s ) ds = ∫0
2
1ds = x +
2
1
∞ x+
Case 3. x> ½, g ( x ) = f ( x ) ∗ h ( x ) = ∫ −∞
f ( s ) h ( x − s ) ds = ∫ x−
1
2
2
1ds =1

⎧ 0, x <≤ − 1 / 2

g ( x ) = ⎨ x + 1 / 2, | x |< 1 / 2 g ( x )
⎪ 1, x ≥ 1/ 2
⎩ x
Case analysis for convolution computing
• f(x) and h(x) f (x)
1 h(x)
1

x x
1 1

2 2

• Case 1: x<-1/2 Case 2: |x|<1/2


h( x − s ) f (s) h( x − s) f (s)

f ( s ) h( x − s ) x
s s
x 1 1 1 1
f ( s )h( x − s) − 2 − x +
1
2 f (s) 2 2 2

Case 3: x>1/2 f ( s)h( x − s) h( x − s)


x s
1 1

2 2
Categories of Spatial filters
• Linear filters
– Correlation
– Convolution
• Nonlinear filters

• Smooth filters

• Sharpening filters
Mechanics of linear spatial filter
• Move the mask over the image, calculate the pixel value
using correlation or convolution
1-D Correlation and Convolution
• Correlation of two functions
a
g ( x) = w( x) o f ( x) = ∑ w(s) f ( x + s)
s =− a

• Convolution of two functions ((like rotate w for 180 degree)


g )

a
g ( x) = w( x) ∗ f ( x) = ∑ w(s) f ( x − s)
s =− a

with image of size M and mask size m, a = (m-1)/2, x = 0, …, M-1


1-D Correlation and Convolution
Spatial Filtering
• Spatial filter: also called mask/kernel/template or window)
– Consist of a neighbourhood with coefficients on pixels
– Example: masks of odd sizes, e.g. 3x3, 5x5,…
• Apply a filter to an image: simply move the filter mask from
point to point in an image
image. At each point (x(x, y)
y), the
response of the filter at that point is calculated using a
predefined relationship.
• Example
Linear filter

R = w1 z1 + w2 z 2 + ... + wmn z mn
mn
= ∑ wi zi
i =i
13
2-D Correlation and Convolution
• Correlation of two functions

a b
g ( x, y ) = w( x, y ) o f ( x, y ) = ∑∑
s =− a t =− b
w( s, t ) f ( x + s, y + t )

• Convolution of two functions (like rotate w for 180 degree)

a b
g ( x, y ) = w( x, y ) ∗ f ( x, y ) = ∑∑
s =− a t =− b
w( s, t ) f ( x − s, y − t )

• Linear Filtering of an image f of size MxN filter mask of size mxn is given by
the expression, a = (m-1)/2, b = (n-1)/2,
x = 0, 1, 2, … , M-1 and y = 0, 1, 2, … , N-1
Example of 2-D correlation and convolution
Smoothing Spatial Filters
• Used for blurring and for noise reduction
• Blurring is used in preprocessing steps, such as
– removall off smallll d
details
t il ffrom an iimage prior
i tto object
bj t extraction
t ti
– bridging of small gaps in lines or curves

• Noise
N i reduction
d ti can be b accomplished
li h d b by bl
blurring
i with
ith a
linear filter and also by a nonlinear filter
• General form of smooth filter ((size mxn,, m and n are odd))

a b

∑ ∑ w(s, t ) f ( x + s, y + t )
g ( x, y ) = s = − at = − b
a b

∑ ∑ w(s, t )
s = − at = − b
16
Smoothing Linear Filters
• Output is simply the average of the pixels contained in the neighborhood of
the filter mask. Also called averaging filters or low pass filters

• Replacing the value of every pixel in an image by the average of the gray
levels in the neighborhood will reduce the “sharp” transitions in gray levels.

• Sharp transitions
– random noise in the image
– edges
g of objects
j in the image
g
– Smoothing can reduce noises (desirable) and blur edges (undesirable)

17
Example: 3x3 Smoothing Linear Filters

box filter weighted average

18
Example
• a). original image 500x500
pixel
• b). - f). results of smoothing
with square averaging filter
masks of size n = 3, 3 5,
5 9,
9 15
and 35, respectively.
• Note:
– big mask is used to eliminate
small objects from an image.
– the size of the mask
a b establishes the relative size of
the objects that will be
c d blended with the background.
ef
19
Gauss function filter
• Use Gauss function to generate a mask of m x m matrix
w

x2 + y 2

h ( x, y ) = e 2σ 2

E.g. m = 3

⎡ h ( − 1, − 1) h ( − 1,0 ) h ( − 1,1) ⎤
w = ⎢⎢ h ( 0, − 1) h ( 0,0 ) h ( 0,1) ⎥⎥
⎢⎣ h (1, − 1) h (1,0 ) h (1,1) ⎥⎦
Example

original image result after smoothing result of thresholding


with
ith 15x15
15 15 averaging
i mask k

we can see that the result after smoothing and thresholding,


the remains are the largest and brightest objects in the image.
21
Nonlinear Filters
• Order-Statistics Filters
– The response is based on ordering (ranking) the pixels
contained in the image area encompassed by the filter

• Examples

– median filter : R = median{zk |k = 1,2,…,n x n}


– max filter : R = max{zk |k = 1,2,…,n x n}
– min filter : R = min{zk |k = 1,2,…,n
12 n x n}

note: n x n is the size of the mask

22
Median Filters
• Median filters
– replaces the value of a pixel by the median of the gray levels in the neighborhood
of that pixel (the original value of the pixel is included in the computation of the
median)

impulse noise > salt


– quite popular because for certain types of random noise (impulse
and ppepper
pp noise)
noise) , theyy p
provide excellent noise-
noise-reduction capabilities,
capabilities
p , with
considering less blurring than linear smoothing filters of similar size.
– forces the points with distinct gray levels to be more like their
neighbors.
– isolated clusters of pixels that are light or dark with respect to
their neighbors, and whose area is less than n2/2 (one-half the
filter area), are eliminated by an n x n median filter.
– eliminated = forced to have the value equal the median intensity
of the neighbors. larger clusters are affected considerably less

23
Example : Median Filters

24

You might also like