ME5286 Lecture9 PDF
ME5286 Lecture9 PDF
Lecture 9:
Hough Transform and Thresholding
Saad Bedros
[email protected]
ME5286 – Lecture 9
Hough Transform
#2
• Robust method to find a shape in an image
• Shape can be described in parametric form
• A voting scheme is used to determine the correct
parameters
ME5286 – Lecture 9
Example: Line fitting
• Why fit lines?
Many objects characterized by presence of straight lines
• Noise & clutter features will cast votes too, but typically their
votes should be inconsistent with the majority of “good”
features.
ME5286 – Lecture 9
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?
ME5286 – Lecture 9
Finding lines in an image: Hough space
y b
b0
x m0 m
image space Hough (parameter) space
x0 x 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
– What does a point (x0, y0) in the image space map to?
b = –x1m + y1
x0 x m
image space Hough (parameter) space
x m
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.
ME5286 – Lecture 9
Hough Transform for Line Detection
#11
ME5286 – Lecture 9
Polar representation for lines
Issues with usual (m,b) parameter space: can take on
infinite values, undefined for vertical lines.
Image columns
x d : perpendicular distance
[0,0]
from line to origin
Image rows
x cos y sin d
ME5286 – Lecture 9
Hough transform algorithm
Using the polar parameterization: H: accumulator array (votes)
x cos y sin d
Basic Hough transform algorithm d
1. Initialize H[d, ]=0
2. for each edge point I[x,y] in the image
for = [min to max ] // some quantization
d x cos y sin
H[d, ] += 1
3. Find the value(s) of (d, ) where H[d, ] is maximum
4. The detected line in the image is given by d x cos y sin
r0 ( x0 , y0 ) (r , )
0 0
0
ME5286 – Lecture 9
x
Hough Transform for Lines
r 4
#16
y
-3 -2 -1 1 2 3
( x , y
( x3 , y3 )
1 1 )
-2
( x4 , y4 )
( x1 , y1 ) -4
r1 ( x3 , y3 ) ( x , y )
4 4 (r1 , 1 )
1
ME5286 – Lecture 9
x
#17
ME5286 – Lecture 9
Hough Transform for Lines
#18
y d
x
Image space Votes
edge coordinates
What difficulty does this present for an implementation?
ME5286 – Lecture 9
Impact
Impact of
of noise onHough
noise on Hough
Extension 2
– give more votes for stronger edges
Extension 3
– –change
ME5286 the sampling
Lecture 9 of (d, ) to give more/less resolution
Extensions
Extension 1: Use the image gradient
1. same
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
4. same
(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…
Intersection:
most votes
for center
occur here.
b
a
Image space Hough space
b
a
Image space Hough space
( xi a) 2 ( yi b) 2 r 2
ME5286 – Lecture 9
31
ME5286 – Lecture 9
HT for Circles: Search with unknown R
Equation of Circle:
( xi a) 2 ( yi b) 2 r 2
ME5286 – Lecture 9
Hough transform for circles
For every edge pixel (x,y) :
For each possible radius value r:
For each possible gradient direction θ:
// or use estimated gradient at (x,y)
a = x – r cos(θ) // column
b = y + r sin(θ) // row
H[a,b,r] += 1
end
end
ME5286 – Lecture 9
Example: detecting circles with Hough
Original Edges Votes: Penny
Combined detections
ME5286 – Lecture 9
Example: iris detection
ME5286 – Lecture 9
Generalized Hough Transform
• Define a model shape by its boundary points and a reference
point.
Offline procedure:
x
a At each boundary point,
compute displacement
θ
p1
θ
p2 vector: r = a – pi.
ME5286 – Lecture 9
[Dana H. Ballard, Generalizing the Hough Transform to Detect Arbitrary Shapes, 1980]
Generalized Hough Transform
R-Table
ME5286 – Lecture 9
Generalized Hough Transform
Detection procedure:
x
For each edge point:
θ xx
• Use its gradient orientation θ to xx
index into stored table θ θ
p1
θ
• Use retrieved r vectors to vote θ
Assuming translation is the only transformation here, i.e., orientation and scale are fixed.
ME5286 – Lecture 9
Generalized Hough Transform
ME5286 – Lecture 9
Generalized Hough Transform
ME5286 – Lecture 9
Rotation and Scale Solution
ME5286 – Lecture 9
Rotation and Scale Solution
ME5286 – Lecture 9
#47
Segmentation of Objects
Using Thresholding Method
ME5286 – Lecture 9
Thresholding based Segmentation
#48
• Goal is to identify an object based on uniform
intensity
• Use the Histogram to compute the best threshold that
can separate the object intensity
ME5286 – Lecture 9
Thresholding Methods
#49
ME5286 – Lecture 9
Thresholding Principles
#50
ME5286 – Lecture 9
Thresholding Example
#51
ME5286 – Lecture 9
Thresholding Examples
#52
ME5286 – Lecture 9
Histogram Calculation
#53
ME5286 – Lecture 9
Histogram Profiles
#54
ME5286 – Lecture 9
Good and Bad Histograms
#55
ME5286 – Lecture 9
Maximum Separation
#56
ME5286 – Lecture 9
Adaptive Thresholding
#57
ME5286 – Lecture 9
Two Types of Variance
#58
ME5286 – Lecture 9
Threshold selection via optimization
#59
ME5286 – Lecture 9
Recursive Procedure
#60
ME5286 – Lecture 9
Properties
#61
ME5286 – Lecture 9
Gaussian Mixture Modeling of Histograms
#62
ME5286 – Lecture 9
Fitting Model Distribution
#63
ME5286 – Lecture 9
Fitting Model Distribution - 2
#64
ME5286 – Lecture 9
Derivation of Optimal Threshold
#65
ME5286 – Lecture 9
Derivation of Optimal Threshold - 2
#66
ME5286 – Lecture 9
Cases for Optimal Threshold
#67
ME5286 – Lecture 9
Algorithm for Gaussian Threshold Detection
#68
ME5286 – Lecture 9
Properties of Gaussian Mixture Approach
#69
ME5286 – Lecture 9
Examples
#70
ME5286 – Lecture 9
Otsu vs Gaussian Approach
#71
ME5286 – Lecture 9
Gaussian Gives Poor Results
#72
ME5286 – Lecture 9
Gaussian Mixture – a Fail Case
#73
ME5286 – Lecture 9
Issues with Thresholding
#74
• Histogram based thresholding is very effective
• Even with low noise, if one class is much smaller
than the other we might still be in trouble.
• Remember also that both these images have the same
histogram:
ME5286 – Lecture 9