[06-30213][06-30241][06-25024]
Computer Vision and Imaging &
Robot Vision
Dr Hyung Jin Chang Dr Yixing Gao
h.j.chang@bham.ac.uk y.gao.8@bham.ac.uk
School of Computer Science
FITTING: VOTING AND THE HOUGH TRANSFORM (SZELISKI 4.3.2)
Now: Fitting
• Want to associate a model with multiple observed features
[Fig from Marszalek & Schmid, 2007]
For example, the model could be a line, a circle, or an arbitrary shape.
3
Fitting: Main idea
• Choose a parametric model that best represents a set of features
• Membership criterion is not local
• Can’t tell whether a point belongs to a given model just by looking at that point
• Three main questions:
• What model represents this set of features best?
• Which of several model instances gets which feature?
• How many model instances are there?
• Computational complexity is important
• It is infeasible to examine every possible set of parameters and every possible combination of features
4
Slide credit: L. Lazebnik
•
Example: Line fitting
Why should we fit lines?
Many objects characterized by presence of straight lines
•
Wait, why aren’t we done just by running edge detection? 5
Kristen Grauman
Difficulty of line fitting
• Extra edge points (clutter), multiple models:
– which points go with which line, if any?
• Only some parts of each line detected, and some parts are missing:
– how to find a line that bridges missing evidence?
• Noise in measured edge points, orientations:
– how to detect true underlying parameters?
6 Kristen Grauman
Voting
• It’s not feasible to check all combinations of features by fitting a model to each possible subset.
• Voting is a general technique where we let each feature vote for all models that are compatible with it.
– Cycle through features, cast votes for model parameters. – Look for model parameters that receive a lot of votes.
• Noise & clutter features will cast votes too, but typically their votes should be inconsistent with the majority of “good” features.
7 Kristen Grauman
Fitting lines: Hough transform
• Given points that belong to a line, what is the line?
• How many lines are there?
• Which points belong to which lines?
• Hough Transform is a voting technique that can be used to answer all of these questions.
Main idea:
1. For each edge point compute all possible lines that pass through that point.
• Each point casts a vote for parameter values. 2. Select the lines that gets enough votes.
8 Kristen Grauman
Finding lines in an image: Hough space
Equation of a line? y b y = mx + b
b0
x m0 m
image space Hough (parameter) space
Connection between image (x,y) and Hough (m,b) spaces
• A line in the image corresponds to a point in Hough space
• To go from image space to Hough space:
– given a set of points (x,y), find all (m,b) such that y = mx + b
9
Slide credit: Steve Seitz
Finding lines in an image: Hough space yb
y0
x0
xm
image space Hough (parameter) space
Connection between image (x,y) and Hough (m,b) spaces
• A line in the image corresponds to a point in Hough space
• To go from image space to Hough space:
– given a set of points (x,y), find all (m,b) such that y = mx + b
• What does a point (x0, y0) in the image space map to?
– Answer: the solutions of b = -x0m + y0 – this is a line in Hough space
10
Slide credit: Steve Seitz
Finding lines in an image: Hough space yb
(x1, y1) (x0, y0)
y0
x0
b = –x1m + y1 xm
image space Hough (parameter) space
What are the line parameters for the line that contains both (x0, y0) and (x1, y1)?
• It is the intersection of the lines b = –x0m + y0 and b = –x1m + y1
Slide credit: Kristen Grauman
11
Finding lines in an image: Hough algorithm yb
xm
image space Hough (parameter) space
How can we use this to find the most likely parameters (m,b) for the most prominent line in the image space?
• Let each edge point in image space vote for a set of possible parameters in Hough space
• Accumulate votes in discrete set of bins; parameters with the most votes indicate line in image space.
Slide credit: Kristen Grauman
12
Polar representation for lines Issues with usual (m,b) parameter space: can take on
infinite values, undefined for vertical lines.
d : perpendicular distance
d
from line to origin
: angle the perpendicular makes with the x-axis
xcos + ysin = d Point in image space→sinusoid segment in Hough space
13 Adapted from Kristen Grauman
Hough transform algorithm Using the polar parameterization:
xcos + ysin = d
H: accumulator array (votes)
d
for = [min to max ] // some quantization
d = xcos + ysin H[d, ] += 1
Basic Hough transform algorithm
1. InitializeH[d,]=0
2. foreachedgepointI[x,y]intheimage
3. Find the value(s) of (d, ) where H[d, ] is maximum
4. The detected line in the image is given by d = xcos + ysin
Time complexity (in terms of number of votes per pt)?
14
Source: Steve Seitz
Num_edge_pts * num_theta
• Hough Transform Demo
https://www.aber.ac.uk/~dcswww/Dept/Teaching/Course Notes/current/CS34110/hough.html
15
1. Image→Canny
Derek Hoiem
2. Canny→Hough votes
Derek Hoiem
3. Hough votes→Edges Find peaks
Derek Hoiem
Hough transform example
Derek Hoiem http://ostatic.com/files/images/ss_hough.jpg
Original image
Canny edges
Vote space and top peaks
Showing longest segments found 20
Kristen Grauman
Impact of noise on Hough
y
d
x
Image space edge coordinates
Votes
What difficulty does this present for an implementation?
Impact of noise on Hough
Image space edge coordinates
Votes
Here, everything appears to be “noise”, or random
edge points, but we still see peaks in the vote space. Slide credit: Kristen Grauman
22
Extensions
Recall: when we detect an edge point, we also know its
gradient direction
Extension 1: Use the image gradient
1. Same as standard HT
2. for each edge point I[x,y] in the image
= gradient at (x,y)
d = xcos + ysin H[d, ] += 1
3. Same as standard HT
4. Same as standard HT
(Reduces degrees of freedom)
Extension 2
• give more votes for stronger edges
Extension 3
23
Slide credit: Kristen Grauman
• change the sampling of (d, ) to give more/less resolution
Extensions
Extension 1: Use the image gradient
1. Same as standard HT
2. for each edge point I[x,y] in the image
compute unique (d, ) based on image gradient at (x,y) H[d, ] += 1
3. Same as standard HT
4. Same as standard HT
(Reduces degrees of freedom)
Extension 2
• give more votes for stronger edges (use magnitude of gradient)
Extension 3
• change the sampling of (d, ) to give more/less resolution
Extension 4
• The same procedure can be used with circles, squares, or any other shape…
24
Source: Steve Seitz
Hough transform for circles
• Circle: center (a,b) and radius r
(x −a)2 +(y −b)2 =r2 ii
Equation of circle?
Equation of set of circles that all pass through a point?
• For a fixed radius r
b
Image space Adapted by Devi Parikh from: Kristen Grauman
Hough space
a
25
Hough transform for circles • Circle: center (a,b) and radius r
(x −a)2 +(y −b)2 =r2 ii
• For a fixed radius r
Image space
Intersection:
most votes for center occur here.
Hough space
26 Kristen Grauman
Hough transform for circles • Circle: center (a,b) and radius r
(x −a)2 +(y −b)2 =r2 ii
• For an unknown radius r
r
?
Image space
a
Hough space
b
27 Kristen Grauman
Hough transform for circles • Circle: center (a,b) and radius r
(x −a)2 +(y −b)2 =r2 ii
• For an unknown radius r
a
Image space
The equation has three parameters: a, b ,r
r
Hough space
b
28 Kristen Grauman
Hough transform for circles
• Circle: center (a,b) and radius r
(x −a)2 +(y −b)2 =r2 ii
• For an unknown radius r, known gradient direction
x
θ
Image space Hough space
29 Kristen Grauman
Hough transform for circles
We are looking for circles of a particular radius r, then the equation of each circle is:
𝑥 = 𝑎 + 𝑟𝑐𝑜𝑠𝜃 𝑦 = 𝑏 + 𝑟𝑠𝑖𝑛𝜃
Every point in the (x,y) space will be equivalent to a circle in the (a,b) space.
By rearranging the equations, we get the line on which the
center will lie:
𝑎 = 𝑥𝑖 − 𝑟𝑐𝑜𝑠𝜃 𝑏 = 𝑦𝑖 − 𝑟𝑠𝑖𝑛𝜃
for a particular point (xi, yi). And Θ sweeps from 0 to 2pi
If the radius is also known then center of the circle can be located
30 Kristen Grauman
Hough transform for circles
31 Kristen Grauman
Hough transform for circles
For each edge pixel (x,y) :
For each possible radius value r:
For each possible gradient direction θ: // or use estimated gradient at (x,y)
end end
a = x – r cos(θ) // column b = y – r sin(θ) // row H[a,b,r] += 1 // voting
Time complexity per edge pixel?
32
• Check out online demo : http://www.markschulze.net/java/hough/
Kristen Grauman
r*theta
Example: detecting circles with Hough
Original
Edges
Votes: Penny
Note: a different Hough transform (with separate accumulators) was used for each circle radius (quarters vs. penny).
33 Coin finding sample images from: Vivek Kwatra
Example: detecting circles with Hough
Original
Combined detections Edges
Votes: Quarter
34 Coin finding sample images from: Vivek Kwatra
Example: iris detection
Gradient+threshold Hough space Max detections (fixed radius)
• Hemerson Pistori and Eduardo Rocha Costa http://rsbweb.nih.gov/ij/plugins/hough-circles.html
35 Kristen Grauman
Example: iris detection
• An Iris Detection Method Using the Hough Transform and Its Evaluation for
Facial and Eye Movement, by Hideki Kashima, Hitoshi Hongo, Kunihito Kato, Kazuhiko Yamamoto, ACCV 2002.
36
Parameters for analytic curves
37
Voting: practical tips
• First minimize irrelevant responses
(use only edges with significant magnitude of gradient)
• Appropriately discretize the parametric space
• Too coarse: votes from different lines fall into the same accumulator
• Too fine: losing lines – due to noise, collinear points cast votes into nearby (BUT DIFFERENT) accumulators.
• Vote for neighbors as well (smoothing accumulator)
• Use the gradient direction to reduce DOF by 1.
38 Kristen Grauman
Hough transform: pros and cons Pros
• All points are processed independently, so can cope with occlusion, gaps
• Some robustness to noise: noise points unlikely to contribute consistently to any single bin
• Can detect multiple instances of a model in a single pass Cons
• Complexity of search time increases exponentially with the number of model parameters
• Non-target shapes can produce spurious peaks in parameter space
• Quantization: can be tricky to pick a good grid size
39 Kristen Grauman
Generalized Hough Transform
• What if we want to detect arbitrary shapes?
Intuition:
x
x x
x
Displacement vectors
Ref. point
Model image Novel image Vote space
Now suppose those colors encode gradient directions…
40 Kristen Grauman
x
Generalized Hough Transform
• Define a model shape by its boundary points and a reference point.
xa
θ
θ
p2
p1
Model shape
Offline procedure:
At each boundary point, compute displacement vector: r = a – pi.
Store these vectors in a table indexed by gradient orientation θ.
θ
…
θ
…
[Dana H. Ballard, Generalizing the Hough Transform to Detect Arbitrary Shapes, 1980]
41
…
Generalized Hough Transform
Detection procedure:
For each edge point:
• Use its gradient orientation θ
to index into stored table
• Use retrieved r vectors to
vote for reference point
x
xx xx
θ
p1
θ
Novel image
θ
θ
θ
θ
…
θ
…
Assuming translation is the only transformation here, i.e., orientation and scale are fixed.
42
…
Generalized Hough transform
Building the model – intuition:
• Assume we know how to detect parts (recognize+localize), i.e., eyes and beak of an howl.
• Encode parts by displacements to the neck center. The owl head model:
Given a part, where is the neck center?
eye beak
Image from: http://www.exposureguide.com/
Generalized Hough transform
• Detection–intuition
Image from: http://pugetsoundbirds.org/projects/owl-project/
Generalized Hough transform
• Detection–intuition
Image from: http://pugetsoundbirds.org/projects/owl-project/
Generalized Hough for object detection
• Instead of indexing displacements by gradient orientation, index by matched local patterns.
“visual codeword” with displacement vectors
training image
B. Leibe, A. Leonardis, and B. Schiele, Combined Object Categorization and Segmentation with an Implicit Shape Model, ECCV Workshop on Statistical
Learning in Computer Vision 2004
46
Source: L. Lazebnik
Generalized Hough for object detection
• Instead of indexing displacements by gradient orientation, index by “visual codeword”
test image
B. Leibe, A. Leonardis, and B. Schiele, Combined Object Categorization and Segmentation with an Implicit Shape Model, ECCV Workshop on Statistical
Learning in Computer Vision 2004
47
Source: L. Lazebnik
Summary
• Fitting problems require finding any supporting evidence for a model, even within clutter and missing features
– associate features with an explicit model
• Voting approaches, such as the Hough transform, make it possible to find likely model parameters without searching all combinations of features
– Hough transform approach for lines, circles, …, arbitrary shapes defined by a set of boundary points, recognition from patches
48