Hough Transform
Download
Report
Transcript Hough Transform
3-D Computer Vision
CSc 83020
Feature Detection and Grouping
Finding Corners
CSc 83020 3-D Computer Vision – Ioannis Stamos
What Is a Corner?
Large gradients in more than one direction.
CSc 83020 3-D Computer Vision – Ioannis Stamos
A Simple Corner Detector
I x2
C
I x I y
I I
I
Find eigenvalues of C
x y
2
y
1
2
If the smaller eigenvalue is above a threshold then we have a corner.
CSc 83020 3-D Computer Vision – Ioannis Stamos
A Simple Corner Detector
I x2
C
I x I y
I I
I
Iy 0
a 0
C
0
0
a 0
C
0
a
Find eigenvalues of C
x y
2
y
1
2
If the smaller eigenvalue is above a threshold then we have a corner.
CSc 83020 3-D Computer Vision – Ioannis Stamos
A Simple Corner Detector
CSc 83020 3-D Computer Vision – Ioannis Stamos
Sobel Operator
-1 -2 -1
S1= 0 0 0
1 2 1
Edge Magnitude =
-1
-2
-1
S2 =
2
0
0
0
1
2
1
2
S1 + S2
Edge Direction = tan-1
S1
S2
CSc 83020 3-D Computer Vision – Ioannis Stamos
Sobel in Matlab
CSc 83020 3-D Computer Vision – Ioannis Stamos
Canny Edge Detector
CSc 83020 3-D Computer Vision – Ioannis Stamos
Comparison
Sobel
CSc 83020 3-D Computer Vision – Ioannis Stamos
Canny
Canny Edge Detection
Steps:
1.
2.
Apply derivative of Gaussian
Non-maximum suppression
3.
Thin multi-pixel wide “ridges” down to single
pixel width
Linking and thresholding
Low, high edge-strength thresholds
Accept all edges over low threshold that are
connected to edge over high threshold
CSc 83020 3-D Computer Vision – Ioannis Stamos
Non-Maximum Supression
Non-maximum suppression:
Select the single maximum point across the width
of an edge.
CSc 83020 3-D Computer Vision – Ioannis Stamos
Linking to the Next Edge Point
Assume the marked
point q is an edge
point.
Take the normal to
the gradient at that
point and use this to
predict continuation
points (either r or p).
CSc 83020 3-D Computer Vision – Ioannis Stamos
Edge Hysteresis
Hysteresis: A lag or momentum factor
Idea: Maintain two thresholds khigh and klow
Use khigh to find strong edges to start edge
chain
Use klow to find weak edges which continue
edge chain
Typical ratio of thresholds is roughly
khigh / klow = 2
CSc 83020 3-D Computer Vision – Ioannis Stamos
Canny Edge Detection (Example)
gap is gone
Strong +
connected
weak edges
Original
image
Strong
edges
only
Weak
edges
courtesy of G. Loy
CSc 83020 3-D Computer Vision – Ioannis Stamos
Canny Edge Detection (Example)
Using Matlab with default thresholds
CSc 83020 3-D Computer Vision – Ioannis Stamos
Bridge Example Again
edge(im,’canny’)
CSc 83020 3-D Computer Vision – Ioannis Stamos
Summary: Canny Edge
Detection
Most commonly used method
Traces edges, accommodates variations in
contrast
Not a linear filter!
Problems with corners
CSc 83020 3-D Computer Vision – Ioannis Stamos
Towards Global Features
Local versus global
CSc 83020 3-D Computer Vision – Ioannis Stamos
From Edges to Lines
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Lines
Assume edge
detection
Each pixel is either
edge or not
How do we find the
line?
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Lines
Assume edge
detection
Each pixel is either
edge or not
How do we find the
line?
CSc 83020 3-D Computer Vision – Ioannis Stamos
Least Squares Fitting of Lines
y mx c
E
yi mxi c2
i
N
xi , yi
Minimize E
E
0
m
E
0
c
yi mxi c
CSc 83020 3-D Computer Vision – Ioannis Stamos
Least Squares Fitting of Lines
E
yi mxi c2
i
N
Minimize E
E
0
m
E
0
c
Problem: E must be formulated carefully!
CSc 83020 3-D Computer Vision – Ioannis Stamos
Least Squares Fitting of Lines
x sin y cos 0
E
xi sin yi cos 2
N
i
xi , yi
Minimize E
E
0
E
0
xi sin yi cos
CSc 83020 3-D Computer Vision – Ioannis Stamos
Hough Transform
b m x y
y
x
CSc 83020 3-D Computer Vision – Ioannis Stamos
Hough Transform: Quantization
y
b
x
Detecting Lines by finding maxima / clustering in parameter space
CSc 83020 3-D Computer Vision – Ioannis Stamos
m
m
Hough Transform: Algorithm
For each image point, determine
most likely line parameters b,m (direction of
gradient)
strength (magnitude of gradient)
Increment parameter counter by strength
value
Cluster in parameter space, pick local maxima
CSc 83020 3-D Computer Vision – Ioannis Stamos
Hough Transform: Results
Image
Edge detection
Hough Transform
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Lines Using the Hough
Transform
xi , yi
xi cos yi sin
CSc 83020 3-D Computer Vision – Ioannis Stamos
Algorithm
Discretize the parameter spaces ρ and θ.
Create Accumulator array A(1..R,1..T).
Set A(k,h)=0 for all k and h.
For each image edge E(i,j)=1
For h=1…T
ρ =i cosθd(h)+j sinθd (h)
Find index k: ρd is closest to ρ
Increment A(h,k) by one.
Find all local maxima (kp, hp) such that A (kp, hp)>τ
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Lines Using the Hough
Transform
Strong local peaks
correspond to lines.
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Lines Using the Hough
Transform
Resolution Issues
…
CSc 83020 3-D Computer Vision – Ioannis Stamos
From
Forsyth and
Ponce
CSc 83020 3-D Computer Vision – Ioannis Stamos
Summary Hough Transform
Smart counting
Local evidence for global features
Organized in a table
Careful with parameterization!
Problem: Curse of dimensionality
Works great for simple features with 3
unknowns
Will fail for complex objects
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Circles by Hough Transform
y
b0
r
a0
Equation of Circle:
(xi,yi)
x
( xi a0 )2 ( yi b0 )2 r 2
CSc 83020 3-D Computer Vision – Ioannis Stamos
Finding Circles by Hough Transform
y
b0
r
a0
(xi,yi)
x
( xi a0 )2 ( yi b0 )2 r 2
Equation of Circle:
If radius r is known:
Circles!
b
y
(xi,yi)
x
83020 3-D
Computer Vision – Ioannis Stamos
AccumulatorCSc
array
A(a,b)
a
Finding Circles by Hough Transform
y
b0
r
(xi,yi)
a0
x
If r is not known
Use accumulator array A(a,b,r)
For each (xi,yi) increment A(a,b,r) such that
( xi a )2 ( yi b )2 r2
CSc 83020 3-D Computer Vision – Ioannis Stamos
Using Gradient Information
Can save lot of computations!
Given: location (xi,yi)
y
Edge direction φi
x
CSc 83020 3-D Computer Vision – Ioannis Stamos
Using Gradient Information
Can save lot of computations!
Given: location (xi,yi)
y
Edge direction φi
x
Assume r is known:
(xi,yi)
y
φi
a=x-rcosφ
b=y-rsinφ
Need to increment
(a,b)
only one point
CSc 83020 3-D Computer Vision
– Ioannis
Stamos
x in
Accumulator
Array.
Hough Transform for Curves
Curve y=f(x,a)
a=[a1, … , ap] the parameters of the curve.
Limitation: size of parameter space wrt # of
parameters.
Solution: variable-resolution parameter space.
CSc 83020 3-D Computer Vision – Ioannis Stamos
Hough Transform
Pattern Matching.
More efficient than template matching.
Handles occlusion.
Finds all instances of pattern.
Handling inaccurate edge locations?
Drawbacks?
CSc 83020 3-D Computer Vision – Ioannis Stamos