Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting...

20
4/28/20 1 Fitting a transformation: Feature-based alignment April 28 th , 2020 Yong Jae Lee UC Davis Generalized Hough Transform Model image Vote space Novel image x x x x x Now suppose those colors encode gradient directions… • What if we want to detect arbitrary shapes? Intuition: Ref. point Displacement vectors Kristen Grauman 2 Define a model shape by its boundary points and a reference point. [Dana H. Ballard, Generalizing the Hough Transform to Detect Arbitrary Shapes, 1980] x a p 1 θ p 2 θ At each boundary point, compute displacement vector: r = a – p i . Store these vectors in a table indexed by gradient orientation θ. Generalized Hough Transform Offline procedure: Model shape θ θ 3

Transcript of Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting...

Page 1: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

1

Fittingatransformation:Feature-basedalignment

April28th,2020

YongJaeLeeUCDavis

GeneralizedHoughTransform

Modelimage VotespaceNovelimage

xxx

xx

Nowsupposethosecolorsencodegradientdirections…

•  Whatifwewanttodetectarbitraryshapes?

Intuition:

Ref.point

Displacementvectors

KristenGrauman2

•  Defineamodelshapebyitsboundarypointsandareferencepoint.

[Dana H. Ballard, Generalizing the Hough Transform to Detect Arbitrary Shapes, 1980]

x

a

p1

θ p2 θ

At each boundary point, compute displacement vector: r = a – pi. Store these vectors in a table indexed by gradient orientation θ.

GeneralizedHoughTransform

Offlineprocedure:

Modelshape

θ

θ

3

Page 2: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

2

p1

θ θ

Foreachedgepoint:•  Useitsgradientorientationθto

indexintostoredtable

•  Useretrievedrvectorstovoteforreferencepoint

GeneralizedHoughTransform

Detectionprocedure:

Assuming translation is the only transformation here, i.e., orientation and scale are fixed.

x

θ θ

Novelimage

θ

θ

θ

xx

xx

4

GeneralizedHoughforobjectdetection

•  Insteadofindexingdisplacementsbygradientorientation,indexbymatchedlocalpatterns.

B. Leibe, A. Leonardis, and B. Schiele, Combined Object Categorization and Segmentation with an Implicit Shape Model, ECCV Workshop on Statistical Learning in Computer Vision 2004

training image

“visual codeword” with displacement vectors

Source: L. Lazebnik 5

•  Insteadofindexingdisplacementsbygradientorientation,indexby“visualcodeword”

B. Leibe, A. Leonardis, and B. Schiele, Combined Object Categorization and Segmentation with an Implicit Shape Model, ECCV Workshop on Statistical Learning in Computer Vision 2004

test image

Source: L. Lazebnik

GeneralizedHoughforobjectdetection

6

Page 3: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

3

Summary•  Fittingproblemsrequirefindinganysupportingevidencefora

model,evenwithinclutterandmissingfeatures–  associatefeatureswithanexplicitmodel

•  Votingapproaches,suchastheHoughtransform,makeitpossibletofindlikelymodelparameterswithoutsearchingallcombinationsoffeatures–  Houghtransformapproachforlines,circles,…,arbitraryshapes

definedbyasetofboundarypoints,recognitionfrompatches

7

Today

•  Feature-based alignment – 2D transformations – Affine fit – RANSAC

8

Motivation: Recognition

Figures from David Lowe 9

Page 4: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

4

Motivation: medical image registration

10

Slide credit: Kristen Grauman

Motivation: mosaics

Image from http://graphics.cs.cmu.edu/courses/15-463/2010_fall/

(In detail next week)

11

Alignment problem •  We have previously considered how to fit a model to

image evidence –  e.g., a line to edge points

•  In alignment, we will fit the parameters of some transformation according to a set of matching feature pairs (“correspondences”).

T

xi

xi '

12

Slide credit: Kristen Grauman

Page 5: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

5

Parametric (global) warping Examples of parametric warps:

translation rotation aspect

affine perspective

Source: Alyosha Efros 13

Parametric (global) warping

Transformation T is a coordinate-changing machine: p’ = T(p)

What does it mean that T is global? •  Is the same for any point p •  can be described by just a few numbers (parameters)

Let’s represent T as a matrix: p’ = Mp

T

p = (x,y) p’ = (x’,y’)

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

yx

yx

M''

Source: Alyosha Efros 14

Scaling Scaling a coordinate means multiplying each of its components by

a scalar Uniform scaling means this scalar is the same for all components:

× 2

Source: Alyosha Efros

15

Page 6: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

6

Non-uniform scaling: different scalars per component:

Scaling

X × 2, Y × 0.5

Source: Alyosha Efros

16

Scaling

Scaling operation: Or, in matrix form:

byyaxx

=

=

''

⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

yx

ba

yx

00

''

scaling matrix S

Source: Alyosha Efros

17

What transformations can be represented with a 2x2 matrix?

2D Rotate around (0,0)?

yxyyxx*cos*sin'*sin*cos'

Θ+Θ=Θ−Θ=

⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

ΘΘ

Θ−Θ=⎥

⎤⎢⎣

yx

yx

cossinsincos

''

2D Shear?

yxshyyshxx

y

x

+=

+=

*'*'

⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

yx

shsh

yx

y

x

11

''

Source: Alyosha Efros

2D Scaling?

ysyxsx

y

x

*'

*'

=

=⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

yx

ss

yx

y

x

00

''

18

Page 7: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

7

What transformations can be represented with a 2x2 matrix?

Source: Alyosha Efros

2D Mirror about Y axis?

yyxx

=−=

''

⎥⎦⎤

⎢⎣⎡⎥⎦⎤

⎢⎣⎡−=⎥⎦

⎤⎢⎣⎡

yx

yx

1001

''

2D Mirror over (0,0)?

yyxx−=−=

''

⎥⎦⎤

⎢⎣⎡⎥⎦⎤

⎢⎣⎡

−−=⎥⎦

⎤⎢⎣⎡

yx

yx

1001

''

2D Translation?

y

x

tyytxx

+=

+=

''

NO! 19

2D Linear Transformations

Only linear 2D transformations can be represented with a 2x2 matrix.

Linear transformations are combinations of … •  Scale, •  Rotation, •  Shear, and •  Mirror

⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

yx

dcba

yx''

Source: Alyosha Efros 20

Homogeneous coordinates

Converting from homogeneous coordinates:

homogeneous image coordinates

To convert to homogeneous coordinates:

21

Slide credit: Kristen Grauman

Convenient coordinate system to represent many useful transformations

Page 8: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

8

Homogeneous Coordinates Q: How can we represent 2d translation as a 3x3 matrix

using homogeneous coordinates? A: Using the rightmost column:

⎥⎥⎥

⎢⎢⎢

=

1001001

y

x

tt

ranslationT

y

x

tyytxx

+=

+=

''

Source: Alyosha Efros 22

Translation

⎥⎥⎥

⎢⎢⎢

+

+

=

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

111001001

1''

y

x

y

x

tytx

yx

tt

yx

tx = 2 ty = 1

Homogeneous Coordinates

Source: Alyosha Efros

23

Basic 2D Transformations Basic 2D transformations as 3x3 matrices

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

ΘΘ

Θ−Θ

=

⎥⎥⎥

⎢⎢⎢

11000cossin0sincos

1''

yx

yx

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

11001001

1''

yx

tt

yx

y

x

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

11000101

1''

yx

shsh

yx

y

x

Translate

Rotate Shear

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

11000000

1''

yx

ss

yx

y

x

Scale

Source: Alyosha Efros 24

Page 9: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

9

2D Affine Transformations

Affine transformations are combinations of … •  Linear transformations, and •  Translations

Parallel lines remain parallel

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

wyx

fedcba

wyx

100'''

25

Slide credit: Kristen Grauman

Today

•  Feature-based alignment – 2D transformations – Affine fit – RANSAC

26

Alignment problem •  We have previously considered how to fit a model to

image evidence –  e.g., a line to edge points

•  In alignment, we will fit the parameters of some transformation according to a set of matching feature pairs (“correspondences”).

T

xi

xi '

Kristen Grauman

27

Page 10: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

10

Image alignment

•  Two broad approaches: –  Direct (pixel-based) alignment

•  Search for alignment where most pixels agree –  Feature-based alignment

•  Search for alignment where extracted features agree •  Can be verified using pixel-based alignment 28

Slide credit: Kristen Grauman

Fitting an affine transformation •  Assuming we know the correspondences, how do we

get the transformation?

),( ii yx ʹʹ),( ii yx

⎥⎦

⎤⎢⎣

⎡+⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡ʹ

ʹ

2

1

43

21

tt

yx

mmmm

yx

i

i

i

i

29

Slide credit: Kristen Grauman

An aside: Least Squares Example Say we have a set of data points (X1,X1’), (X2,X2’),

(X3,X3’), etc. (e.g. person’s height vs. weight) We want a nice compact formula (a line) to predict X’s

from Xs: Xa + b = X’ We want to find a and b How many (X,X’) pairs do we need?

What if the data is noisy?

'22

'11

XbaXXbaX

=+

=+⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡'2

'1

2

1

11

XX

ba

XX

Ax=B

⎥⎥⎥⎥

⎢⎢⎢⎢

=⎥⎦

⎤⎢⎣

⎥⎥⎥⎥

⎢⎢⎢⎢

.........111

'3

'2

'1

3

2

1

XXX

ba

XXX

overconstrained

2min BAx −

Source: Alyosha Efros

30

Page 11: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

11

Fitting an affine transformation •  Assuming we know the correspondences, how do we

get the transformation?

),( ii yx ʹʹ),( ii yx

⎥⎦

⎤⎢⎣

⎡+⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡ʹ

ʹ

2

1

43

21

tt

yx

mmmm

yx

i

i

i

i

⎥⎥⎥⎥

⎢⎢⎢⎢

ʹ

ʹ=

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

!

!

!

!

i

i

ii

ii

yx

ttmmmm

yxyx

2

1

4

3

2

1

10000100

31

Slide credit: Kristen Grauman

Fitting an affine transformation

•  How many matches (correspondence pairs) do we need to solve for the transformation parameters?

⎥⎥⎥⎥

⎢⎢⎢⎢

ʹ

ʹ=

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

!

!

!

!

i

i

ii

ii

yx

ttmmmm

yxyx

2

1

4

3

2

1

10000100

Kristen Grauman

32

Affine: # correspondences?

How many correspondences needed for affine?

x x’

T(x,y) y y’

?

Alyosha Efros

Page 12: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

12

Fitting an affine transformation

•  How many matches (correspondence pairs) do we need to solve for the transformation parameters?

•  Once we have solved for the parameters, how do we compute the coordinates of the corresponding point for ?

•  Where do the matches come from?

⎥⎥⎥⎥

⎢⎢⎢⎢

ʹ

ʹ=

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

!

!

!

!

i

i

ii

ii

yx

ttmmmm

yxyx

2

1

4

3

2

1

10000100

),( newnew yx

Kristen Grauman

34

What are the correspondences?

?

•  Compare content in local patches, find best matches. e.g., simplest approach: scan with template, and compute SSD or correlation between list of pixel intensities in the patch

•  Later in the course: how to select regions using more robust descriptors.

Kristen Grauman

35

Fitting an affine transformation

Figures from David Lowe, ICCV 1999 36

Page 13: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

13

37

Fitting an affine transformation

38

Fitting an affine transformation

Fitting an affine transformation

Figures from David Lowe, ICCV 1999 39

Page 14: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

14

Today

•  Feature-based alignment – 2D transformations – Affine fit – RANSAC

40

Outliers •  Outliers can hurt the quality of our parameter

estimates, e.g., –  an erroneous pair of matching points from two images –  an edge point that is noise, or doesn’t belong to the

line we are fitting.

Kristen Grauman

41

Outliers affect least squares fit

42

Slide credit: Kristen Grauman

Page 15: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

15

Outliers affect least squares fit

43

Slide credit: Kristen Grauman

RANSAC

•  RANdom Sample Consensus

•  Approach: we want to avoid the impact of outliers, so let’s look for “inliers”, and use those only.

•  Intuition: if an outlier is chosen to compute the current fit, then the resulting line won’t have much support from rest of the points.

44

Slide credit: Kristen Grauman

RANSAC: General form •  RANSAC loop: 1.  Randomly select a seed group of points on which to

base transformation estimate

2.  Compute transformation from seed group

3.  Find inliers to this transformation

4.  If the number of inliers is sufficiently large, re-compute estimate of transformation on all of the inliers

•  Keep the transformation with the largest number of inliers

45

Slide credit: Kristen Grauman

Page 16: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

16

RANSAC for line fitting example

Source: R. Raguram Lana Lazebnik

46

RANSAC for line fitting example

Least-squaresfit

Source: R. Raguram Lana Lazebnik

47

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

Source: R. Raguram Lana Lazebnik

48

Page 17: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

17

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

Source: R. Raguram Lana Lazebnik

49

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

Source: R. Raguram Lana Lazebnik

50

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

4.  Selectpointsconsistentwithmodel

Source: R. Raguram Lana Lazebnik

51

Page 18: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

18

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

4.  Selectpointsconsistentwithmodel

5.  Repeathypothesize-and-verifyloop

Source: R. Raguram Lana Lazebnik

52

53

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

4.  Selectpointsconsistentwithmodel

5.  Repeathypothesize-and-verifyloop

Source: R. Raguram Lana Lazebnik

54

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

4.  Selectpointsconsistentwithmodel

5.  Repeathypothesize-and-verifyloop

Source: R. Raguram Lana Lazebnik

Page 19: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

19

RANSAC for line fitting example

1.  Randomlyselectminimalsubsetofpoints

2.  Hypothesizeamodel

3.  Computeerrorfunction

4.  Selectpointsconsistentwithmodel

5.  Repeathypothesize-and-verifyloop

Source: R. Raguram Lana Lazebnik

55

RANSAC for line fitting Repeat N times: •  Draw s points uniformly at random •  Fit line to these s points •  Find inliers to this line among the remaining

points (i.e., points whose distance from the line is less than t)

•  If there are d or more inliers, accept the line and refit using all inliers

Lana Lazebnik

56

RANSAC pros and cons •  Pros

•  Simple and general •  Applicable to many different problems •  Often works well in practice

•  Cons •  Lots of parameters to tune •  Doesn’t work well for low inlier ratios (too many iterations,

or can fail completely)

Lana Lazebnik

57

Page 20: Fitting a transformation Feature-based alignmentyjlee/teaching/ecs174-spring2020/lee... · Fitting a transformation: Feature-based alignment April 28th, 2020 Yong Jae Lee UC Davis

4/28/20

20

Today

•  Feature-based alignment – 2D transformations – Affine fit – RANSAC

58

Comingup:alignmentandimagestitching

59

Questions?

SeeyouThursday!

60