Lecture 5 Mask/Filter Transformation
Lecture 5 Mask/Filter Transformation
Lecture 5 Mask/Filter Transformation
y y
x x
Lens (passive)
⎧ 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
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
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
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
• 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
a
g ( x) = w( x) ∗ f ( x) = ∑ w(s) f ( x − s)
s =− a
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 )
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
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
• Examples
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)
23
Example : Median Filters
24