Hough Transform 16-385 Computer Vision (Kris Kitani) Carnegie - - PowerPoint PPT Presentation

hough transform
SMART_READER_LITE
LIVE PREVIEW

Hough Transform 16-385 Computer Vision (Kris Kitani) Carnegie - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Hough Transform

16-385 Computer Vision (Kris Kitani)

Carnegie Mellon University

slide-2
SLIDE 2

motivation

Edge detection Thresholding Original image

How do we find image boundaries (lines)?

slide-3
SLIDE 3

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
slide-4
SLIDE 4

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

a line becomes a point Image space Parameter space

slide-5
SLIDE 5

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

a point becomes a line Image space Parameter space

slide-6
SLIDE 6

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

Image space Parameter space

(3, 3)

two points become ?

slide-7
SLIDE 7

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

Image space Parameter space

(3, 3)

two points become ?

slide-8
SLIDE 8

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

Image space Parameter space

(3, 3) (−2, −2)

three points become ?

slide-9
SLIDE 9

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

Image space Parameter space

(3, 3) (−2, −2)

four points become ?

(1, −1)

slide-10
SLIDE 10

Image and parameter space

y = mx + b y − mx = b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

variables parameters parameters variables

(1, 1)

Image space Parameter space

(3, 3) (−2, −2)

four points become ?

(1, −1)

slide-11
SLIDE 11

How would you find the best fitting line?

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y m b

(1, 1)

Image space Parameter space

(3, 3) (−2, −2) (1, −1)

Is your method robust to measurement noise? Is your method robust to outliers?

slide-12
SLIDE 12

Line Detection by Hough Transform

y x ) , ( c m

Parameter Space

1 1 1 1 1 1 2 1 1 1 1 1 1

) , ( c m A

Algorithm: 1.Quantize Parameter Space 2.Create Accumulator Array 3.Set

  • 4. For each image edge 


For each element in 
 If lies on the line:
 Increment

  • 5. Find local maxima in

) , ( c m ) , ( c m A c m c m A , ) , ( ∀ = ) , (

i i y

x 1 ) , ( ) , ( + = c m A c m A ) , ( c m ) , ( c m A

i i

y m x c + − = ) , ( c m A

slide-13
SLIDE 13

Problems with parameterization

1 1 1 1 1 1 2 1 1 1 1 1 1

) , ( c m A

What’s wrong with the parameterization ?

) , ( c m

How big does the accumulator need to be?

slide-14
SLIDE 14

Problems with parameterization

1 1 1 1 1 1 2 1 1 1 1 1 1

) , ( c m A

What’s wrong with the parameterization ?

) , ( c m

How big does the accumulator need to be?

The space of m is huge! The space of c is huge!

slide-15
SLIDE 15

Problems with parameterization

1 1 1 1 1 1 2 1 1 1 1 1 1

) , ( c m A

What’s wrong with the parameterization ?

) , ( c m

How big does the accumulator need to be?

The space of m is huge! The space of c is huge!

∞ ≤ ≤ ∞ − m

slide-16
SLIDE 16

Given points find

Better Parameterization

max

2 ρ ρ π θ ≤ ≤ ≤ ≤

(Finite Accumulator Array Size)

) , (

i i y

x ) , ( θ ρ ) , (

i i y

x

y

x

Image Space

ρ θ

Hough Space

?

Hough Space Sinusoid

Use normal form:

x cos θ + y sin θ = ρ

slide-17
SLIDE 17

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

a point becomes a wave Image space Parameter space

x cos θ + y sin θ = ρ

parameters variables

ρ θ

slide-18
SLIDE 18

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-19
SLIDE 19

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-20
SLIDE 20

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-21
SLIDE 21

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-22
SLIDE 22
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-23
SLIDE 23
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

slide-24
SLIDE 24
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space

x cos θ + y sin θ = ρ

Wait …why is rho negative?

slide-25
SLIDE 25
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space same line through the point

x cos θ + y sin θ = ρ

slide-26
SLIDE 26

There are two ways to write the same line: Positive rho version: x cos θ + y sin θ = ρ x cos(θ + π) + y sin(θ + π) = −ρ Negative rho version:

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x

y

(1, 1)

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x

y

(1, 1)

θ

θ + π

ρ

−ρ

sin(θ) = − sin(θ + π) cos(θ) = − cos(θ + π)

Recall:

slide-27
SLIDE 27
  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b x y

variables parameters

(1, 1)

a line becomes a point Image space Parameter space same line through the point

x cos θ + y sin θ = ρ

slide-28
SLIDE 28

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

Image space Parameter space

(3, 3)

two points become ?

slide-29
SLIDE 29

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

Image space Parameter space

(3, 3) (−2, −2)

three points become ?

slide-30
SLIDE 30

0.25π 0.5π 0.75π

  • 4
  • 3
  • 2
  • 1

1 2 3 4

Image and parameter space

y = mx + b

  • 5
  • 4
  • 3
  • 2
  • 1
1 2 3 4
  • 4
  • 3
  • 2
  • 1
1 2 3 4

x y

variables parameters

(1, 1)

Image space Parameter space

(3, 3) (−2, −2)

four points become ?

(1, −1)

slide-31
SLIDE 31

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!

slide-32
SLIDE 32

Image space Votes

slide-33
SLIDE 33

Basic shapes

(in polar parameter space)

can you guess the shape?

slide-34
SLIDE 34

line rectangle circle

Basic shapes

(in polar parameter space)

slide-35
SLIDE 35

Basic Shapes

slide-36
SLIDE 36

More complex image

slide-37
SLIDE 37

In practice, measurements are noisy…

Image space Votes

slide-38
SLIDE 38

Image space Votes

Too much noise …

slide-39
SLIDE 39

Effects of noise level

More noise, less votes (in the right bin)

Maximum number of votes 5 10 15 Noise level 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09

Number of votes for a line of 20 points with increasing noise

slide-40
SLIDE 40

Effect of noise points

Maximum number of votes 3 6 9 12 Number of noise points 20 40 60 80 100 120 140 160 180 200

More noise, more votes (in the wrong bin)

slide-41
SLIDE 41

Real-world example

Original Edges Hough Lines parameter space