Computer Vision Lec-1
Computer Vision Lec-1
Lecture # 4
Image Filtering & Its Applications
Today: Image Filters Review
Source: S. Seitz
Images as functions
• We can think of an image as a function, f, from
R2 to R:
• f( x, y ) gives the intensity at position ( x, y )
• Realistically, we expect the image only to be defined over a
rectangle, with a finite range:
– f: [a,b] x [c,d] [0, 1.0]
2D
1D
Source: S. Seitz
Gaussian noise
Image shows
the noise
values
themselves.
Effect of
sigma on
Gaussian
noise:
Image shows
the noise
values
themselves.
Effect of
sigma on
Gaussian
noise:
Image shows
the noise
values
themselves.
Effect of
sigma on
Gaussian
noise:
Source: S. Marschner
Weighted Moving Average
• Can add weights to our moving average
• Weights [1, 1, 1, 1, 1] / 5
Source: S. Marschner
Weighted Moving Average
• Non-uniform weights [1, 4, 6, 4, 1] / 16
Source: S. Marschner
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Moving Average In 2D
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Correlation filtering
Say the averaging window size is 2k+1 x 2k+1:
Non-uniform weights
Correlation filtering
0 0 0 0 0 0 0 0 0 0
0
0
0
0
0
0
90
0
90
0
90
0
90
0
90
0
0
0
0
1 1 1 0 10 20 30 30
0
0
0
0
0
90
90
90
90
90
90
90
90
90
90
0
0
0
0
1 ?1 1
0 0 0 90 0 90 90 90 0 0
1 1 1
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
“box filter”
0 0 0 0 0 0 0 0 0 0
Smoothing by averaging
depicts box filter:
white = high value, black = low value
original filtered
Gaussian filter
• What if we want nearest neighboring pixels to have the
most influence on the output?
0 0 0 0 0 0 0 0 0 0
This kernel is an
0 0 0 0 0 0 0 0 0 0
approximation of a
0 0 0 90 90 90 90 90 0 0
Gaussian function:
0 0 0 90 90 90 90 90 0 0 1 2 1
0 0 0 90 90 90 90 90 0 0
2 4 2
0 0 0 90 0 90 90 90 0 0
1 2 1
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Source: S. Seitz
Smoothing with a Gaussian
Gaussian filters
• What parameters matter here?
• Size of kernel or mask
– Note, Gaussian function has infinite support, but discrete filters
use finite kernels
σ = 5 with 10 σ = 5 with 30
x 10 kernel x 30 kernel
Gaussian filters
• What parameters matter here?
• Variance of Gaussian: determines extent of
smoothing
σ = 2 with 30 σ = 5 with 30
x 30 kernel x 30 kernel
Filtering an impulse signal
What is the result of filtering the impulse signal (image) F
with the arbitrary kernel H?
0 0 0 0 0 0 0
0 0 0 0 0 0 0
a b c
?
0 0 0 0 0 0 0
d e f
0 0 0 1 0 0 0
g h i
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Filtering an impulse signal
What is the result of filtering the impulse signal (image) F
with the arbitrary kernel H?
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
a b c
0 0 0 0 0 0 0 0 0 0a 0b 0c 0 0
d e f
0 0 0 1 0 0 0 0 0 0d 1e 0f 0 0
g h i
0 0 0 0 0 0 0 0 0 0g 0h 0i 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
Practice with linear filters
?
0 0 0
0 1 0
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 1 0
0 0 0
Original Filtered
(no change)
Source: D. Lowe
Practice with linear filters
?
0 0 0
0 0 1
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 0 1
0 0 0
Source: D. Lowe
Practice with linear filters
-
0 0 0 1 1 1
0
0
2
0
0
0
1
1
1
1
1
1
?
(Note that filter sums to 1)
Original
Source: D. Lowe
Practice with linear filters
-
0 0 0 1 1 1
0 2 0 1 1 1
0 0 0 1 1 1
Source: D. Lowe
Denoising
Gaussian
Filter
Slide: Hoiem
Reducing Gaussian noise
Smoothing with larger standard deviations suppresses noise, but also blurs the
image
Source: S. Lazebnik
Reducing salt-and-pepper noise by
Gaussian smoothing
Source: K. Grauman
Median filter
Salt-and-pepper noise Median filtered
Gaussian
Median
Edge detection
• Goal: map image from 2d array of pixels to a set of curves
or line segments or contours.
• Why?
Depth discontinuity:
Reflectance change: object boundary
appearance
information, texture
Cast shadows
Change in surface
orientation: shape
Contrast and invariance
Recall : Images as functions
Source: L. Lazebnik
Differentiation and convolution
For 2D function, f(x,y), the partial derivative is:
f ( x, y) f ( x , y) f ( x, y)
lim
x 0
For discrete data, we can approximate using finite differences:
f ( x, y) f ( x 1, y) f ( x, y)
x 1
To implement above as convolution, what would be the associated
filter?
Partial derivatives of an image
f ( x, y ) f ( x, y )
x y
-1 ? 1
or
-1 1 1 -1
Which shows changes with respect to x?
(showing flipped filters)
Assorted finite difference filters
>> My = fspecial(‘sobel’);
>> outim = imfilter(double(im), My);
>> imagesc(outim);
>> colormap gray;
Image gradient
The gradient of an image:
thresholding
The Canny edge detector
Problem:
pixels along
this edge
didn’t survive
the
thresholding
thinning
(non-maximum suppression)
Hysteresis thresholding
• Check that maximum value of gradient value is
sufficiently large
– drop-outs? use hysteresis
• use a high threshold to start edge curves and a low
threshold to continue them.
Source: S. Seitz
Hysteresis thresholding
original image
Template (mask)
Scene
A toy example
Template matching
Template
Detected template
Template matching
Template
Scene
Where’s Waldo?
Template
Scene
Where’s Waldo?
Template
Scene
Template
Detected template
Slide: Hoiem
Matching with filters
• Goal: find in image
• Method 0: filter the image with eye patch
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l
f = image
g = filter
True detections
False
detections
( g[k , l ] g )( f [m k , n l ] f m ,n )
h[ m, n] k ,l
0.5
2
( g[ k , l ] g ) ( f [ m k , n l ] f m,n )
2
k ,l k ,l
True detections
True detections
A: Image Pyramid
Review of Sampling
Gaussian
Filter Sample
Low-Pass Low-Res
Image
Filtered Image Image
Slide: Hoiem
Gaussian pyramid
Source: Forsyth
Template Matching with Image Pyramids
2. Downsample image
Slide: Hoiem
Coarse-to-fine Image Registration
1. Compute Gaussian pyramid
2. Align with coarse pyramid
3. Successively align with finer
pyramids
– Search smaller range
Slide: Hoiem
Laplacian filter
unit impulse
Gaussian Laplacian of Gaussian
Source: Lazebnik
2D edge detection filters
Laplacian of Gaussian
Source: Forsyth
Computing Gaussian/Laplacian Pyramid
http://sepwww.stanford.edu/~morgan/texturematch/paper_html/node3.html
The simplest wavelet transform:
the Haar transform
1 1 0.5 0.5
U= U-1=
1 -1 0.5 -0.5
96
Haar transform
The simplest set of functions:
1 1 0.5 0.5
U= U-1=
1 -1 0.5 -0.5
1 1 1 1
1 -1 1 -1
1 1 1 1
1 -1 1 -1
U= U-1= ½ 1 1
1 1
1 -1 1 -1
1 1 1 1
1 -1 1 -1
97
Recursive matrix construction of Haar transform
A3 A2 A1
A3 A2 A1 (A3 A2 A1)-1
98
2D Haar transform
1 1
Basic elements: 1 1 1 -1
1 -1
99
2D Haar transform
1 1
Basic elements: 1 1 1 -1
1 -1
1 1 1 Low pass
1 1 = 2
1 1 1
100
2D Haar transform
1 1
Basic elements: 1 1 1 -1
1 -1
1 1 1 Low pass
1 1 = 2
1 1 1
1
1 -1 =
1
1
1 1 =
-1
1
1 -1 =
-1
101
2D Haar transform
1 1
Basic elements: 1 1 1 -1
1 -1
1 1 1 Low pass
1 1 = 2
1 1 1
1 1 -1
1 -1 = 2
1 1 -1
1 1 1 2
1 1 =
-1 -1 -1
1 1 -1
1 -1 = 2
-1 -1 1
102
2D Haar transform
1 1
Basic elements: 1 1 1 -1
1 -1
1 1 1 Low pass
1 1 = 2
1 1 1
High pass
1 1 -1
1 -1 = 2 vertical
1 1 -1
High pass
1 1 1 2 horizontal
1 1 =
-1 -1 -1
1 1 -1
1 -1 = 2 High pass
-1 -1 1 diagonal
103 103
2D Haar transform
Sketch of the Fourier transform
1 1 2
1 1
1 -1
2
1 -1
1 1 2
-1 -1
1 -1
2
-1 1
104
2D Haar transform
Sketch of the Fourier transform
Horizontal low pass,
Vertical low-pass
1 1 2
1 1
Horizontal high
1 -1 pass, vertical low-
2 pass
1 -1
Horizontal low
1 1 2 pass, vertical
high-pass
-1 -1
1 -1 Horizontal high
2 pass, vertical high
-1 1 pass
105 105
Simoncelli and Adelson, in “Subband coding”, Kluwer, 1990.
Pyramid cascade
106 106
Wavelet/QMF representation
1 -1
1 -1
1 1 1 -1
-1 -1 -1 1
Slide: Hoiem
Major uses of image pyramids
• Compression
• Object detection
– Scale search
– Features
• Registration
– Course-to-fine
Slide: Hoiem
Acknowledgements
Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
Pattern Recognition and Analysis Course – A.K. Jain, MSU
Pattern Classification” by Duda et al., John Wiley & Sons.
Digital Image Processing”, Rafael C. Gonzalez & Richard E. Woods, Addison-Wesley, 2002
Machine Vision: Automated Visual Inspection and Robot Vision”, David Vernon, Prentice Hall,
1991
www.eu.aibo.com/
Advances in Human Computer Interaction, Shane Pinder, InTech, Austria, October 2008
Computer Vision A modern Approach by Frosyth
110