Hough Transform 16-385 Computer Vision (Kris Kitani) Carnegie Mellon University
motivation Original image Edge detection Thresholding How do we find image boundaries (lines)?
Hough Transform • Generic framework for detecting a shape/object • Edges don’t have to be connected • Lines can be occluded • Key idea: edges vote for the possible models
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes a point -5 -4 -3 -2 -1 0 1 2 3 4 -5 -4 -3 -2 -1 0 1 2 3 4 x m -1 -1 -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 3 3 2 2 (1 , 1) a point 1 1 becomes a line -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 m -1 -1 -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) two points 1 1 become ? -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 m -1 -1 -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) two points 1 1 become ? -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 m -1 -1 -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) three points 1 1 become -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 ? m -1 -1 ( − 2 , − 2) -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) four points 1 1 become -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 ? m -1 -1 ( − 2 , − 2) (1 , − 1) -2 -2 -3 -3 -4 -4 Parameter space Image space
Image and parameter space variables variables y = mx + b y − mx = b parameters parameters b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) four points 1 1 become -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 ? m -1 -1 ( − 2 , − 2) (1 , − 1) -2 -2 -3 -3 -4 -4 Parameter space Image space
How would you find the best fitting line? b y 4 4 (3 , 3) 3 3 2 2 (1 , 1) 1 1 -5 -4 -3 -2 -1 0 1 2 3 4 x -5 -4 -3 -2 -1 0 1 2 3 4 m -1 -1 ( − 2 , − 2) (1 , − 1) -2 -2 -3 -3 -4 -4 Image space Parameter space Is your method robust to measurement noise? Is your method robust to outliers?
Line Detection by Hough Transform y Algorithm: ( m , c ) 1.Quantize Parameter Space ( m , c ) x 2.Create Accumulator Array Parameter Space A ( m , c ) A ( m , c ) A ( m , c ) 0 m , c 3.Set = ∀ 1 1 1 1 ( x i y , ) 4. For each image edge 1 1 i A ( m , c ) For each element in 2 1 1 ( m , c ) c x m y If lies on the line: = − + 1 1 i i A ( m , c ) A ( m , c ) 1 1 1 Increment = + A ( m , c ) 5. Find local maxima in
Problems with parameterization ( m , c ) What’s wrong with the parameterization ? How big does the accumulator need to be? 1 1 1 1 1 1 2 A ( m , c ) 1 1 1 1 1 1
Problems with parameterization ( m , c ) What’s wrong with the parameterization ? How big does the accumulator need to be? 1 1 1 1 1 1 2 A ( m , c ) 1 1 1 1 1 1 The space of m is huge! The space of c is huge!
Problems with parameterization ( m , c ) What’s wrong with the parameterization ? How big does the accumulator need to be? 1 1 1 1 1 1 2 A ( m , c ) 1 1 1 1 1 1 The space of m is huge! The space of c is huge! m − ∞ ≤ ≤ ∞
Better Parameterization y Use normal form: x cos θ + y sin θ = ρ ( x i y , ) i ( , ) ( x i y , ) ρ θ Given points find i x Image Space Hough Space Sinusoid ρ 0 2 ≤ θ ≤ π ? 0 ≤ ρ ≤ ρ max (Finite Accumulator Array Size) θ Hough Space
Image and parameter space variables parameters y = mx + b x cos θ + y sin θ = ρ parameters variables y ρ 4 4 3 3 2 2 (1 , 1) a point 1 1 becomes 0 a wave -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 θ 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters Wait …why is rho negative? y 4 4 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 same line 4 through the point 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
y There are two ways to 4 3 write the same line: 2 (1 , 1) 1 ρ θ -5 -4 -3 -2 -1 0 1 2 3 4 x Positive rho version: -1 -2 x cos θ + y sin θ = ρ -3 -4 y Negative rho version: 4 3 2 x cos( θ + π ) + y sin( θ + π ) = − ρ (1 , 1) 1 θ + π -5 -4 -3 -2 -1 0 1 2 3 4 x − ρ -1 Recall: -2 sin( θ ) = − sin( θ + π ) -3 -4 cos( θ ) = − cos( θ + π )
Image and parameter space variables y = mx + b x cos θ + y sin θ = ρ parameters y 4 same line 4 through the point 3 3 2 2 (1 , 1) a line 1 1 becomes 0 a point -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b parameters y 4 4 (3 , 3) 3 3 2 2 (1 , 1) two points 1 1 become 0 ? -5 -4 -3 -2 -1 0 1 2 3 4 x -1 -1 -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b parameters y 4 4 (3 , 3) 3 3 2 2 (1 , 1) three points 1 1 become 0 -5 -4 -3 -2 -1 0 1 2 3 4 x ? -1 -1 ( − 2 , − 2) -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
Image and parameter space variables y = mx + b parameters y 4 4 (3 , 3) 3 3 2 2 (1 , 1) four points 1 1 become 0 -5 -4 -3 -2 -1 0 1 2 3 4 x ? -1 -1 ( − 2 , − 2) (1 , − 1) -2 -2 -3 -3 -4 -4 0.25 π 0.5 π 0.75 π Parameter space Image space
implementation 1. Initialize accumulator H to all zeros 2. For each edge point (x,y) in the image For θ = 0 to 180 ρ = x cos θ + y sin θ H( θ , ρ ) = H( θ , ρ ) + 1 end end 3. Find the value(s) of ( θ , ρ ) where H( θ , ρ ) is a local maximum 4. The detected line in the image is given by ρ = x cos θ + y sin θ NOTE: Watch your coordinates. Image origin is top left!
Image space Votes
Basic shapes (in polar parameter space) can you guess the shape?
Basic shapes (in polar parameter space) line rectangle circle
Basic Shapes
More complex image
In practice, measurements are noisy… Image space Votes
Too much noise … Image space Votes
Recommend
More recommend