34
Alper Yilmaz, Mubarak Shah, Fall 2011 UCF CAP 5415 Computer Vision Fall 2013 Hough Transform Lecture-17 Sections 4.2, 4.3 Fundamentals of Computer Vision

CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Embed Size (px)

Citation preview

Page 1: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

CAP 5415 Computer VisionFall 2013

Hough TransformLecture-17Sections 4.2, 4.3 Fundamentals of Computer Vision

Page 2: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Image Feature Extraction

Edges (edge pixels)– Sobel, Roberts, Prewit– Laplacian of Gaussian– Canny

Interest Points– Harris– SIFT

Descriptors– SIFT– HOG

Alper Yilmaz, Fall 2004 UCF

Page 3: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Shape Features

Straight Lines Circles and Ellipses Arbitrary Shapes

Alper Yilmaz, Fall 2004 UCF

Page 4: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

How to Fit A Line?

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

cmxy

Page 5: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

How to Fit A Line?

Least squares Fit (over constraint) RANSAC (constraint) Hough Transform (under constraint)

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 6: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Least Squares Fit

Standard linear solution to estimating unknowns.– If we know which points belong to which line– Or if there is only one line

cmxfcmxy ,,

i

ii cmxfyE 2,, Minimize

Take derivatives wrt m and c set them to 0Alper Yilmaz, Mubarak Shah, Fall 2011

UCF

Page 7: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting

cmxy

cmxy

cmxycmxy

nn

22

11

D

A

n

B

n

cm

x

xx

y

yy

1111

2

1

2

1

ADB

BAAAD

DAAAABAAA

ADABA

TT

TTTT

TT

1

11

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 8: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

RANSAC: Random Sampling and Consensus

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

1. Randomly select two points to fit a line2. Find the error between the estimated solution and all

other points. • If the error is less than tolerance, then quit, else go

to step (1).

Page 9: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting: Segmentation

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

• Several Lines• How do we Know which points belong to

which lines?

Page 10: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Hough Transform

METHOD AND MEANS FOR RECOGNIZING COMPLEX PATTERNS, Paul V. C. Hough et al– Inventors: Paul V. C. Hough, Paul V. C. Hough

Current U.S. Classification: 382/281; 342/176; 342/190; 382/202

– http://www.google.com/patents?vid=3069654

Alper Yilmaz, Fall 2004 UCF

Page 11: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting: Hough Transform

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Line equation

Rewrite this equation

For particular edge point i this becomes

This is an equation of a line in (c,m) space.

intercept- is slope, is ycmcmxy

ymxc )(

ii ymxc )(

Page 12: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting: Hough Transform

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

ii ymxc )(

Page 13: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Hough Transform Algorithm for Fitting Straight Lines

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 14: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Polar Form of Equation of Line

sincos yxp

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Problematic for vertical linesm and c grow to infinity

ymxc ji )(

Use from gradient

Page 15: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Image Gradient

Alper Yilmaz, Fall 2004 UCF

x

y

yx

yx

SS

SS

SS

1

22

tan

)(

),(

direction

magnitude

VectorGradient yx ,

yx ,

yx ,

Page 16: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Hough Transform for Polar Form of Equation of Line

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 17: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting

p

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 18: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 19: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Line Fitting Examples

noisy

ideal

very noisy

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 20: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Noise Factor

This is the number of votes that the real lineof 20 points gets with increasing noise

Page 21: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Noise Factor

as the noise increases in a picture without a line, the number of points in the max cell goes up, too

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 22: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Difficulties

What is the increments for and p.– too large? We cannot distinguish between

different lines– too small? noise causes lines to be missed

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 23: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Circle Fitting

Similar to line fitting– Three unknowns

Construct a 3D accumulator array A– Dimensions: x0, y0, r

Fix one of the parameters and loop for the others Increment corresponding entry in A. Find the local maxima in A

0)()( 222 ryyxx oo

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 24: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

More Practical Circle Fitting

Use the tangent direction at the edge point

Compute x0, y0 given x, y, r

sincos

0

0

ryyrxx

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 25: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 26: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Alper Yilmaz, Fall 2004 UCF

Examples

Page 27: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Generalized Hough Transform

Used for shapes with no analytical expression Requires training

– Object of known shape– Generate model

R-table

Similar approach to line and circle fitting during detection

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 28: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Generating R-table

Compute centroid For each edge compute its distance

to centroid

Find edge orientation (gradient angle) Construct a table of angles and r

values

(xo,yo)

(x,y)

0

0

yyxx

yx

r

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 29: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Generating R-table

(xo,yo)

(x,y)

(x,y)

Ф1

Ф2Ф1Ф2

Ф3

Ф4

r1, r2, r3 …r14, r21, r23 …r41, r42, r33 …r10, r12, r13 …

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

r1

Page 30: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Detecting shape

known – Edge points (x,y)– Gradient angle at every edge point – R-table of the shape needs to be determined

For each edge point find store it in corresponding row of R-table

Create an accumulator array of 2D (x,y)

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 31: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 32: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Rotation and Scale Invariance

Rotation around Z-axis

Scaling

Rotation+scaling

cossinsincos

yxyyxx

syysxx

cossinsincos

yxsyyxsx

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 33: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Rotation and Scale Invariance

Replace equations 4.13 and 4.14 in Algorithm 4.8 by following and loop for scale and rotation angles.

Alpr Yilmaz, Mubarak Shah, Fall 2011 UCF

Page 34: CAP 5415 Computer Vision Fall 2013 - crcv.ucf.edu · the max cell goes up, too Alper Yilmaz, Mubarak Shah, Fall 2011 UCF. Difficulties What is the increments for and p. – too large?

Alper Yilmaz, Mubarak Shah, Fall 2011 UCF