Download as pdf or txt
Download as pdf or txt
You are on page 1of 125

Computer Vision: Image Alignment

Raquel Urtasun
TTI Chicago

Jan 24, 2013

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

1 / 44

Readings

Chapter 2.1, 3.6, 4.3 and 6.1 of Szeliskis book


Chapter 1 of Forsyth & Ponce

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

2 / 44

What did we see in class last week?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

3 / 44

What is the geometric relationship between these images?

!"

[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

4 / 44

What is the geometric relationship between these images?

Very important for creating mosaics!


[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

4 / 44

Image Warping
Image filtering: change range of image
g (x) = h(f (x))
!"

%"
$"
#"

#"

Image warping: change domain of image


g (x) = f (h(x))
!"

%"
$"
#"

#"

[Source: R. Szeliski]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

5 / 44

Parametric (global) warping

!"
!!"!#$%&'!

!"!"!#$(%&('!

Transformation T is a coordinate-changing machine:


p 0 = 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)
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

6 / 44

Forward and Inverse Warping


Forward Warping: Send each pixel f (x) to its corresponding location
(x 0 , y 0 ) = T (x, y ) in g (x 0 , y 0 )

Inverse Warping: Each pixel at the destination is sampled from the original
image

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

7 / 44

All 2D Linear Transformations

Linear transformations are combinations of


Scale,
Rotation
Shear
Mirror
 0 
x
a
=
y0
c

b
d

 
x
y

[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

8 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

9 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines
Parallel lines remain parallel

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

9 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

9 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
 0 
x
a
=
c
y0

Raquel Urtasun (TTI-C)

b
d



e
g

f
h



Computer Vision

i
k

j
l

 
x
y

Jan 24, 2013

9 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
 0 
x
a
=
c
y0

b
d



e
g

f
h



i
k

j
l

 
x
y

What about the translation?


[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

9 / 44

All 2D Linear Transformations


Properties of linear transformations:
Origin maps to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
 0 
x
a
=
c
y0

b
d



e
g

f
h



i
k

j
l

 
x
y

What about the translation?


[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

9 / 44

Affine Transformations
Affine transformations are combinations of
Linear transformations, and
Translations

0
a
x
y 0 = d
w
0

b
e
0


c
x
f y
1
w

Properties of affine transformations:


Origin does not necessarily map to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

10 / 44

Projective Transformations
Affine transformations and Projective
0
a
x
y 0 = d
w0
g

warps
b
e
h


c
x
f y
i
w

Properties of affine transformations:


Origin does not necessarily map to origin
Lines map to lines
Parallel lines do not necessarily remain parallel
Ratios are not preserved
Closed under composition
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

11 / 44

2D Image Tranformations

These transformations are a nested set of groups


Closed under composition and inverse is a member
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

12 / 44

Computing transformations
Given a set of matches between images A and B
How can we compute the transform T from A to B?
Find transform T that best agrees with the matches

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

13 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0
Goal: minimize sum of squared residuals
C (xt , yt ) =

n
X

(rxi (xt )2 + ryi (yt )2 )

i=1

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0
Goal: minimize sum of squared residuals
C (xt , yt ) =

n
X

(rxi (xt )2 + ryi (yt )2 )

i=1

The solution is called the least squares solution

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0
Goal: minimize sum of squared residuals
C (xt , yt ) =

n
X

(rxi (xt )2 + ryi (yt )2 )

i=1

The solution is called the least squares solution


For translations, is equal to mean displacement

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0
Goal: minimize sum of squared residuals
C (xt , yt ) =

n
X

(rxi (xt )2 + ryi (yt )2 )

i=1

The solution is called the least squares solution


For translations, is equal to mean displacement
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Least squares formulation


For each point (xi , yi ) we have
xi + xt
yi + yt

=
=

xi0
yi0

We define the residuals as


rxi (xt ) = xi + xt xi0
ryi (yt ) = yi + yt yi0
Goal: minimize sum of squared residuals
C (xt , yt ) =

n
X

(rxi (xt )2 + ryi (yt )2 )

i=1

The solution is called the least squares solution


For translations, is equal to mean displacement
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

14 / 44

Matrix Formulation
We can also write as a matrix equation

!!""#!#

!""#$#

!!""#$#

Solve for t by looking at the fixed-point equation

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

15 / 44

Affine Transformations

When we are dealing with an affine transformation



0
a b c
x
x
y 0 = d e f y
w0
0 0 1
w
How many unknowns?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

16 / 44

Affine Transformations

When we are dealing with an affine transformation



0
a b c
x
x
y 0 = d e f y
w0
0 0 1
w
How many unknowns?
How many equations per match?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

16 / 44

Affine Transformations

When we are dealing with an affine transformation



0
a b c
x
x
y 0 = d e f y
w0
0 0 1
w
How many unknowns?
How many equations per match?
How many matches do we need?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

16 / 44

Affine Transformations

When we are dealing with an affine transformation



0
a b c
x
x
y 0 = d e f y
w0
0 0 1
w
How many unknowns?
How many equations per match?
How many matches do we need?
Why to use more?
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

16 / 44

Affine Transformations

When we are dealing with an affine transformation



0
a b c
x
x
y 0 = d e f y
w0
0 0 1
w
How many unknowns?
How many equations per match?
How many matches do we need?
Why to use more?
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

16 / 44

Affine Transformation Cost Function

We can write the residuals as


rxi (a, b, c, d, e, f ) =
ryi (a, b, c, d, e, f ) =

(axi + byi + c) xi0


(dxi + eyi + f ) yi0

Cost function
C (a, b, c, d, e, f ) =

N
X

rxi (a, b, c, d, e, f )2 + ryi (a, b, c, d, e, f )2

i=1

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

17 / 44

Affine Transformation Cost Function

We can write the residuals as


rxi (a, b, c, d, e, f ) =
ryi (a, b, c, d, e, f ) =

(axi + byi + c) xi0


(dxi + eyi + f ) yi0

Cost function
C (a, b, c, d, e, f ) =

N
X

rxi (a, b, c, d, e, f )2 + ryi (a, b, c, d, e, f )2

i=1

And in matrix form ...


[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

17 / 44

Affine Transformation Cost Function

We can write the residuals as


rxi (a, b, c, d, e, f ) =
ryi (a, b, c, d, e, f ) =

(axi + byi + c) xi0


(dxi + eyi + f ) yi0

Cost function
C (a, b, c, d, e, f ) =

N
X

rxi (a, b, c, d, e, f )2 + ryi (a, b, c, d, e, f )2

i=1

And in matrix form ...


[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

17 / 44

Matrix form

$""#%#

!!""#$#

!!""#%#

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

18 / 44

General Formulation

Let x 0 = f (x; p) be a parametric transformation


In the case of translation, similarity and affine, there is a linear relationship
between the amount of motion x = x 0 x and the unknown parameters
x = x 0 x = J(x)p
f
is the Jacobian of the transformation f with respect to the
with J = p
motion parameters p

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

19 / 44

General Formulation

Let x 0 = f (x; p) be a parametric transformation


In the case of translation, similarity and affine, there is a linear relationship
between the amount of motion x = x 0 x and the unknown parameters
x = x 0 x = J(x)p
f
is the Jacobian of the transformation f with respect to the
with J = p
motion parameters p

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

19 / 44

General Formulation

Lets do a couple on the board!

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

20 / 44

General Formulation

The sum of square residuals is then


X
ELLS =
||J(xi )p xi ||22
i

X
X
X
p [
JT (xi )J(xi )]p 2pT [
JT (xi )xi )] +
||xi ||2
T

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

21 / 44

General Formulation

The sum of square residuals is then


X
ELLS =
||J(xi )p xi ||22
i

X
X
X
p [
JT (xi )J(xi )]p 2pT [
JT (xi )xi )] +
||xi ||2

pT Ap 2pT b + c

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

21 / 44

General Formulation

The sum of square residuals is then


X
ELLS =
||J(xi )p xi ||22
i

X
X
X
p [
JT (xi )J(xi )]p 2pT [
JT (xi )xi )] +
||xi ||2

pT Ap 2pT b + c

We can compute the solution by looking for a fixed point, yielding


Ap = b
with A =

JT (xi )J(xi ) the Hessian and b =

Raquel Urtasun (TTI-C)

Computer Vision

JT (xi )xi

Jan 24, 2013

21 / 44

General Formulation

The sum of square residuals is then


X
ELLS =
||J(xi )p xi ||22
i

X
X
X
p [
JT (xi )J(xi )]p 2pT [
JT (xi )xi )] +
||xi ||2

pT Ap 2pT b + c

We can compute the solution by looking for a fixed point, yielding


Ap = b
with A =

JT (xi )J(xi ) the Hessian and b =

Raquel Urtasun (TTI-C)

Computer Vision

JT (xi )xi

Jan 24, 2013

21 / 44

Uncertainty Weighting
The above solution assumes that all feature points are matched with same
accuracy.
If we associate a scalar variance i2 with each correspondence, we can
minimize the weighted least squares problem
X
i2 ||ri ||22
EWLS =
i

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

22 / 44

Uncertainty Weighting
The above solution assumes that all feature points are matched with same
accuracy.
If we associate a scalar variance i2 with each correspondence, we can
minimize the weighted least squares problem
X
i2 ||ri ||22
EWLS =
i

If the i2 are fixed, then the solution is simply


p = (T AT A)1 T Ab
with , the matrix containing for each observation the noise level

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

22 / 44

Uncertainty Weighting
The above solution assumes that all feature points are matched with same
accuracy.
If we associate a scalar variance i2 with each correspondence, we can
minimize the weighted least squares problem
X
i2 ||ri ||22
EWLS =
i

If the i2 are fixed, then the solution is simply


p = (T AT A)1 T Ab
with , the matrix containing for each observation the noise level
What if we dont know ?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

22 / 44

Uncertainty Weighting
The above solution assumes that all feature points are matched with same
accuracy.
If we associate a scalar variance i2 with each correspondence, we can
minimize the weighted least squares problem
X
i2 ||ri ||22
EWLS =
i

If the i2 are fixed, then the solution is simply


p = (T AT A)1 T Ab
with , the matrix containing for each observation the noise level
What if we dont know ?
Solve using iteratively reweighted least squares (IRLS)
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

22 / 44

Uncertainty Weighting
The above solution assumes that all feature points are matched with same
accuracy.
If we associate a scalar variance i2 with each correspondence, we can
minimize the weighted least squares problem
X
i2 ||ri ||22
EWLS =
i

If the i2 are fixed, then the solution is simply


p = (T AT A)1 T Ab
with , the matrix containing for each observation the noise level
What if we dont know ?
Solve using iteratively reweighted least squares (IRLS)
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

22 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0
solve equations of the form: wp0 = Hp

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0
solve equations of the form: wp0 = Hp
linear in unknowns: w and coefficients of H

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0
solve equations of the form: wp0 = Hp
linear in unknowns: w and coefficients of H
H is defined up to an arbitrary scale factor

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0
solve equations of the form: wp0 = Hp
linear in unknowns: w and coefficients of H
H is defined up to an arbitrary scale factor
how many points are necessary to solve for H?
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Homographies

!#"

!"

To unwarp (rectify) and image


solve for homography H given p and p 0
solve equations of the form: wp0 = Hp
linear in unknowns: w and coefficients of H
H is defined up to an arbitrary scale factor
how many points are necessary to solve for H?
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

23 / 44

Solving for Homographies


0
axi
h00
ayi0 = h10
a
h20

h01
h11
h21


h02
xi
h12 yi
h22
1

To get to non-homogenous coordinates

Raquel Urtasun (TTI-C)

xi0

yi0

h00 xi
h20 xi
h10 xi
h20 xi

+ h01 yi
+ h21 yi
+ h11 yi
+ h21 yi

Computer Vision

+ h02
+ h22
+ h12
+ h22

Jan 24, 2013

24 / 44

Solving for Homographies


0
axi
h00
ayi0 = h10
a
h20

h01
h11
h21


h02
xi
h12 yi
h22
1

To get to non-homogenous coordinates


xi0

yi0

h00 xi
h20 xi
h10 xi
h20 xi

+ h01 yi
+ h21 yi
+ h11 yi
+ h21 yi

+ h02
+ h22
+ h12
+ h22

Warning: This is non-linear!!!

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

24 / 44

Solving for Homographies


0
axi
h00
ayi0 = h10
a
h20


h02
xi
h12 yi
h22
1

h01
h11
h21

To get to non-homogenous coordinates


xi0

yi0

h00 xi
h20 xi
h10 xi
h20 xi

+ h01 yi
+ h21 yi
+ h11 yi
+ h21 yi

+ h02
+ h22
+ h12
+ h22

Warning: This is non-linear!!!


But wait a minute!
xi0 (h20 xi + h21 yi + h22 )

= h00 xi + h01 yi + h02

yi0

= h10 xi + h11 yi + h12

Raquel Urtasun (TTI-C)

(h20 xi + h21 yi + h22 )

Computer Vision

Jan 24, 2013

24 / 44

Solving for Homographies


0
axi
h00
ayi0 = h10
a
h20


h02
xi
h12 yi
h22
1

h01
h11
h21

To get to non-homogenous coordinates


xi0

yi0

h00 xi
h20 xi
h10 xi
h20 xi

+ h01 yi
+ h21 yi
+ h11 yi
+ h21 yi

+ h02
+ h22
+ h12
+ h22

Warning: This is non-linear!!!


But wait a minute!
xi0 (h20 xi + h21 yi + h22 )

= h00 xi + h01 yi + h02

yi0

= h10 xi + h11 yi + h12

Raquel Urtasun (TTI-C)

(h20 xi + h21 yi + h22 )

Computer Vision

Jan 24, 2013

24 / 44

Solving for homographies


xi0 (h20 xi + h21 yi + h22 )

= h00 xi + h01 yi + h02

yi0

= h10 xi + h11 yi + h12

(h20 xi + h21 yi + h22 )

This is still linear in the unknowns

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

25 / 44

Solving for homographies


Taking all the observations into account

!"#$#%#

%#

!"#

Defines a least squares problem:


min ||Ah||22
h

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

26 / 44

Solving for homographies


Taking all the observations into account

!"#$#%#

%#

!"#

Defines a least squares problem:


min ||Ah||22
h

Since h is only defined up to scale, solve for unit vector

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

26 / 44

Solving for homographies


Taking all the observations into account

!"#$#%#

%#

!"#

Defines a least squares problem:


min ||Ah||22
h

Since h is only defined up to scale, solve for unit vector


= eigenvector of AT A with smallest eigenvalue
Solution: h

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

26 / 44

Solving for homographies


Taking all the observations into account

!"#$#%#

%#

!"#

Defines a least squares problem:


min ||Ah||22
h

Since h is only defined up to scale, solve for unit vector


= eigenvector of AT A with smallest eigenvalue
Solution: h
Works with 4 or more points
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

26 / 44

Solving for homographies


Taking all the observations into account

!"#$#%#

%#

!"#

Defines a least squares problem:


min ||Ah||22
h

Since h is only defined up to scale, solve for unit vector


= eigenvector of AT A with smallest eigenvalue
Solution: h
Works with 4 or more points
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

26 / 44

Image Alignment Algorithm

Given images A and B


1

Compute image features for A and B

Match features between A and B

Compute homography between A and B using least squares on set of


matches

Is there a problem with this?

[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

27 / 44

Image Alignment Algorithm

Given images A and B


1

Compute image features for A and B

Match features between A and B

Compute homography between A and B using least squares on set of


matches

Is there a problem with this?

[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

27 / 44

Robustness
!"#$%&'()

%*$%&'()

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

28 / 44

Simple case
Lets consider a simpler example ... linear regression

!"#$%&'()*+,)-)%+.&),#),/&0&)1-,-2#+.,0)

3&-0,)045-"&0)6,)

How can we fix this?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

29 / 44

Simple case
Lets consider a simpler example ... linear regression

!"#$%&'()*+,)-)%+.&),#),/&0&)1-,-2#+.,0)

3&-0,)045-"&0)6,)

How can we fix this?


We need a better cost function
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

29 / 44

Simple case
Lets consider a simpler example ... linear regression

!"#$%&'()*+,)-)%+.&),#),/&0&)1-,-2#+.,0)

3&-0,)045-"&0)6,)

How can we fix this?


We need a better cost function
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

29 / 44

More Robust Least-squares


Least-squares assumes that the noise follows a Gaussian distribution
M-estimators are use to make least-squares more robust

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

30 / 44

More Robust Least-squares


Least-squares assumes that the noise follows a Gaussian distribution
M-estimators are use to make least-squares more robust
They involve applying a robust penalty function (r) to the residuals
X
(||ri ||)
ERLS (p) =
i

instead of taking the square of the residual

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

30 / 44

More Robust Least-squares


Least-squares assumes that the noise follows a Gaussian distribution
M-estimators are use to make least-squares more robust
They involve applying a robust penalty function (r) to the residuals
X
(||ri ||)
ERLS (p) =
i

instead of taking the square of the residual


We can take the derivative with respect to p and set it to 0
X
||ri || X (||ri ||) T ri
=
r
=0
(||ri ||)
p
||ri || i p
i

where (r) = 0 (r) is the derivative, called influence function

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

30 / 44

More Robust Least-squares


Least-squares assumes that the noise follows a Gaussian distribution
M-estimators are use to make least-squares more robust
They involve applying a robust penalty function (r) to the residuals
X
(||ri ||)
ERLS (p) =
i

instead of taking the square of the residual


We can take the derivative with respect to p and set it to 0
X
||ri || X (||ri ||) T ri
=
r
=0
(||ri ||)
p
||ri || i p
i

where (r) = 0 (r) is the derivative, called influence function


If we introduce a weight w (r ) = (r )/r , we observe that finding the
stationary point is equivalent to minimizing the iteratively reweighted
least squares (IRLS)
X
EIRLS =
w (||ri ||)||ri ||2
i
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

30 / 44

More Robust Least-squares


Least-squares assumes that the noise follows a Gaussian distribution
M-estimators are use to make least-squares more robust
They involve applying a robust penalty function (r) to the residuals
X
(||ri ||)
ERLS (p) =
i

instead of taking the square of the residual


We can take the derivative with respect to p and set it to 0
X
||ri || X (||ri ||) T ri
=
r
=0
(||ri ||)
p
||ri || i p
i

where (r) = 0 (r) is the derivative, called influence function


If we introduce a weight w (r ) = (r )/r , we observe that finding the
stationary point is equivalent to minimizing the iteratively reweighted
least squares (IRLS)
X
EIRLS =
w (||ri ||)||ri ||2
i
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

30 / 44

Iterative reweighted least-squares

We want to minimize
EIRLS =

w (||ri ||)||ri ||2

A simple algorithm works by iterating between


1
2

Solving for the parameters p


Solving for the weights w

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

31 / 44

Iterative reweighted least-squares

We want to minimize
EIRLS =

w (||ri ||)||ri ||2

A simple algorithm works by iterating between


1
2

Solving for the parameters p


Solving for the weights w

When the number of outliers is very high, IRLS does not work well (will not
converge to the global optima)

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

31 / 44

Iterative reweighted least-squares

We want to minimize
EIRLS =

w (||ri ||)||ri ||2

A simple algorithm works by iterating between


1
2

Solving for the parameters p


Solving for the weights w

When the number of outliers is very high, IRLS does not work well (will not
converge to the global optima)

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

31 / 44

Simple Idea

Given a hypothesized line, count the number of points that agree with the
line
Agree = within a small distance of the line i.e., the inliers to that line

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

32 / 44

Simple Idea

Given a hypothesized line, count the number of points that agree with the
line
Agree = within a small distance of the line i.e., the inliers to that line
For all possible lines, select the one with the largest number of inliers
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

32 / 44

Simple Idea

Given a hypothesized line, count the number of points that agree with the
line
Agree = within a small distance of the line i.e., the inliers to that line
For all possible lines, select the one with the largest number of inliers
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

32 / 44

Counting Inliers

!"#$%&'()*)
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

33 / 44

Counting Inliers

!"#$%&'()*+)
[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

33 / 44

Counting Inliers

!"#$%&'()*+)
Whats the problem with this approach?
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

33 / 44

How do we find the best line?

Unlike least-squares, no simple closed-form solution


Hypothesize-and-test

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

34 / 44

How do we find the best line?

Unlike least-squares, no simple closed-form solution


Hypothesize-and-test
Try out many lines, keep the best one

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

34 / 44

How do we find the best line?

Unlike least-squares, no simple closed-form solution


Hypothesize-and-test
Try out many lines, keep the best one
Which lines?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

34 / 44

How do we find the best line?

Unlike least-squares, no simple closed-form solution


Hypothesize-and-test
Try out many lines, keep the best one
Which lines?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

34 / 44

Translations

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

35 / 44

RAndom SAmple Consensus

!"#"$%&!"#&'(%$)&(%&*(+,-'.&$-/+%&$"%$#&'&

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

36 / 44

RAndom SAmple Consensus

!"#"$%&'()%*"+&,'%$*&'%&+'(-),.&$)/(%&!"#!$%&&

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

36 / 44

RAndom SAmple Consensus

!"#$"#%#&'%#()*+,)-.*%/0#&%#&'%&01&'+#%*"23'(%.4%0*,0'(+%

[Source: N. Snavely]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

36 / 44

RANSAC

All the inliers will agree with each other on the translation vector; the
(hopefully small) number of outliers will (hopefully) disagree with each other
RANSAC only has guarantees if there are < 50% outliers

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

37 / 44

RANSAC

All the inliers will agree with each other on the translation vector; the
(hopefully small) number of outliers will (hopefully) disagree with each other
RANSAC only has guarantees if there are < 50% outliers
All good matches are alike; every bad match is bad in its own way.
[Tolstoy via Alyosha Efros]
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

37 / 44

RANSAC

All the inliers will agree with each other on the translation vector; the
(hopefully small) number of outliers will (hopefully) disagree with each other
RANSAC only has guarantees if there are < 50% outliers
All good matches are alike; every bad match is bad in its own way.
[Tolstoy via Alyosha Efros]
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

37 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

[Source: R. Raguram]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

[Source: R. Raguram]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

Select points consistent


with model

[Source: R. Raguram]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

Select points consistent


with model

Repeat hypothesize and


verify loop

[Source: R. Raguram]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

Select points consistent


with model

Repeat hypothesize and


verify loop

[Source: R. Raguram]
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

Select points consistent


with model

Repeat hypothesize and


verify loop

Choose model with


largest set of inliers

[Source: R. Raguram]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC for line fitting example


1

Randomly select minimal


subset of points

Hypothesize a model

Compute error function

Select points consistent


with model

Repeat hypothesize and


verify loop

Choose model with


largest set of inliers

[Source: R. Raguram]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

38 / 44

RANSAC

Inlier threshold related to the amount of noise we expect in inliers


Often model noise as Gaussian with some standard deviation (e.g., 3 pixels)

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

39 / 44

RANSAC

Inlier threshold related to the amount of noise we expect in inliers


Often model noise as Gaussian with some standard deviation (e.g., 3 pixels)
Number of rounds related to the percentage of outliers we expect, and the
probability of success wed like to guarantee

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

39 / 44

RANSAC

Inlier threshold related to the amount of noise we expect in inliers


Often model noise as Gaussian with some standard deviation (e.g., 3 pixels)
Number of rounds related to the percentage of outliers we expect, and the
probability of success wed like to guarantee
Suppose there are 20% outliers, and we want to find the correct answer with
99% probability

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

39 / 44

RANSAC

Inlier threshold related to the amount of noise we expect in inliers


Often model noise as Gaussian with some standard deviation (e.g., 3 pixels)
Number of rounds related to the percentage of outliers we expect, and the
probability of success wed like to guarantee
Suppose there are 20% outliers, and we want to find the correct answer with
99% probability
How many rounds do we need?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

39 / 44

RANSAC

Inlier threshold related to the amount of noise we expect in inliers


Often model noise as Gaussian with some standard deviation (e.g., 3 pixels)
Number of rounds related to the percentage of outliers we expect, and the
probability of success wed like to guarantee
Suppose there are 20% outliers, and we want to find the correct answer with
99% probability
How many rounds do we need?

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

39 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k
The likelihood that S such trials will all fail is
1 P = (1 p k )S

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k
The likelihood that S such trials will all fail is
1 P = (1 p k )S

The required minimum number of trials is


S=

Raquel Urtasun (TTI-C)

log(1 P)
log(1 p k )

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k
The likelihood that S such trials will all fail is
1 P = (1 p k )S

The required minimum number of trials is


S=

log(1 P)
log(1 p k )

The number of trials grows quickly with the number of sample points used.

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k
The likelihood that S such trials will all fail is
1 P = (1 p k )S

The required minimum number of trials is


S=

log(1 P)
log(1 p k )

The number of trials grows quickly with the number of sample points used.
Use the minimum number of sample points k possible for any given trial
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How many rounds?


Sufficient number of trials S must be tried.
Let p be the probability that any given correspondence is valid and P be the
total probability of success after S trials.
The likelihood in one trial that all k random samples are inliers is p k
The likelihood that S such trials will all fail is
1 P = (1 p k )S

The required minimum number of trials is


S=

log(1 P)
log(1 p k )

The number of trials grows quickly with the number of sample points used.
Use the minimum number of sample points k possible for any given trial
Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

40 / 44

How big is the number of samples?


For alignment, depends on the motion model
Each sample is a correspondence (pair of matching points)

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

41 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


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

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems
Often works well in practice
Cons
Parameters to tune

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems
Often works well in practice
Cons
Parameters to tune
Sometimes too many iterations are required

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems
Often works well in practice
Cons
Parameters to tune
Sometimes too many iterations are required
Can fail for extremely low inlier ratios

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems
Often works well in practice
Cons
Parameters to tune
Sometimes too many iterations are required
Can fail for extremely low inlier ratios
We can often do better than brute-force sampling
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC pros and cons


Pros
Simple and general
Applicable to many different problems
Often works well in practice
Cons
Parameters to tune
Sometimes too many iterations are required
Can fail for extremely low inlier ratios
We can often do better than brute-force sampling
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

42 / 44

RANSAC as Voting

An example of a voting-based fitting scheme


Each hypothesis gets voted on by each data point, best hypothesis wins

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

43 / 44

RANSAC as Voting

An example of a voting-based fitting scheme


Each hypothesis gets voted on by each data point, best hypothesis wins
There are many other types of voting schemes, e.g., Hough transforms
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

43 / 44

RANSAC as Voting

An example of a voting-based fitting scheme


Each hypothesis gets voted on by each data point, best hypothesis wins
There are many other types of voting schemes, e.g., Hough transforms
[Source: N. Snavely]

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

43 / 44

Next class ... more on cameras and projection

Raquel Urtasun (TTI-C)

Computer Vision

Jan 24, 2013

44 / 44

You might also like