Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation...

7
1 CSE486 Robert Collins Back to Lucas-Kanade CSE486 Robert Collins Step-by-Step Derivation P P y x W I Δ + )) ]; , ([ ( [ The key to the derivation is Taylor series approximation: P P W I P y x W I Δ + )) ]; , ([ ( [ ~ ~ We will derive this step-by-step. First, we need two background formula: CSE486 Robert Collins Step-by-Step Derivation First consider the expansion for a single variable p CSE486 Robert Collins Step-by-Step Derivation Note that each variable parameter p i contributes a term of the form CSE486 Robert Collins Step-by-Step Derivation Now let’s rewrite the expression as a matrix equation. For each term, we can rewrite: So that we have: CSE486 Robert Collins Step-by-Step Derivation Further collecting the dw/dp i terms into a matrix, we can write: P P y x W I Δ + )) ]; , ([ ( [ P P W I P y x W I Δ + )) ]; , ([ ( [ ~ ~ which are the terms in the matrix equation:

Transcript of Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation...

Page 1: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

1

CSE486Robert Collins

Back to Lucas-Kanade

CSE486Robert Collins

Step-by-Step Derivation

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

The key to the derivation is Taylor series approximation:

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

~~

We will derive this step-by-step. First, we need two background formula:

CSE486Robert Collins

Step-by-Step Derivation

First consider the expansion for a single variable p

CSE486Robert Collins

Step-by-Step Derivation

Note that each variable parameter pi contributes a term of the form

CSE486Robert Collins

Step-by-Step Derivation

Now let’s rewrite the expression as a matrix equation. For each term,we can rewrite:

So that we have:

CSE486Robert Collins

Step-by-Step DerivationFurther collecting the dw/dpi terms into a matrix, we can write:

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

~~

which are the terms in the matrix equation:

Page 2: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

2

CSE486Robert Collins

Let W([x,y]; P) be a warping function.P is the parameter (vector) of the warping function.

Case 1: P = [u, v]. This is the simple point “optic flow” case

Case 2: P represents parameters of an affine transform i.e.

+

+=

11

1)];,([

642

531 y

x

ppp

pppPyxW

Dr. Ng Teck Khim

2])],([))];,([([ yxTPyxWIpatchimagewithin

y

x

−∑

The objective function for finding the best match is

Summary: the forward LK update equations CSE486Robert Collins

The objective function for finding the best match is

The Lucas-Kanade algorithm minimizes the above objective functionin a Gauss-Newton gradient descent non-linear optimization process.

2])],([))];,([([ yxTPyxWIpatchimagewithin

y

x

−∑

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

Dr. Ng Teck Khim

CSE486Robert Collins

For affine warping, n = 6 and so

=

+++

+++∂

=∂

1000

0100

642

531

yx

yxP

PyPyxP

PyPxPx

P

W

Dr. Ng Teck Khim

∂∂

=∂

=

n

yyyy

n

xxxx

yx

P

W

P

W

P

W

P

WP

W

P

W

P

W

P

W

P

W

WWPyxWLet

L

L

321

321

],[)];,([CSE486Robert Collins

Δ∂

∂Δ

∂∇+−

∂∇=

−Δ∂

∂∇+

∂∇=

Δ∂

})()],())];,([([][{

)],())];,([([][2

PP

WI

P

WIyxTPyxWI

P

WI

yxTPP

WIPyxWI

P

WI

P

E

TT

T

Setting to zero givesP

E

Δ∂

∑ ∑

−∂

∂∇=

−∂

∂∇

∂∇

∂∇=Δ

)))];,([(),(()(

)))]];,([(),(()([])([

1

1

PyxWIyxTP

WIH

PyxWIyxTP

WI

P

WI

P

WIP

T

TT

Update P = P+ΔP and iterate

Dr. Ng Teck Khim

warptheofJacobiantheisP

W

PyxWatIimageofgradienttheisy

I

x

II

where

yxTPP

WIPyxWI

yxTPPyxWIE

∂=∇

−Δ∂

∂∇+=

−Δ+=

)];,([][

]),())];,([([

]),())];,([([

2

2

Hessian

CSE486Robert Collins

Iterate Warp I to obtain I(W([x y];P))

Compute the error image T(x) – I(W([x y]; P))

Warp the gradient with W([x y]; P)

Evaluate at ([x y]; P)

Compute steepest descent images

Compute Hessian matrix

Compute

Compute ΔP

Update P P + ΔP

I∇

P

W

P

WI∂

∂∇

∑ ∂

∂∇

∂∇ )()(

P

WI

P

WI T

∑ −∂

∂∇ )))];,([(),(()( PyxWIyxT

P

WI T

Until ΔP magnitude is negligible

Source: “Lucas-Kanade 20 years on: A unifying framework” Baker and Mathews, IJCV 04

Dr. Ng Teck Khim

CSE486Robert Collins

Source: “Lucas-Kanade 20 years on: A unifying framework” Baker and Mathews, IJCV 04

Algorithm At a Glance

Page 3: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

3

CSE486Robert Collins Steepest Descent Images, Another Look

image gradX gradY

dW/dp1 dW/dp2 dW/dp3

dW/dp4 dW/dp5 dW/dp6

I

I dW/dp1 I dW/dp2 I dW/dp3. . .

I dW/dp4 I dW/dp5 I dW/dp6. . .

CSE486Robert Collins

Approximating Normalized Correlation

We can remove some potential error sources (changes in illumination or camera gain) if we first normalize the template and the local search window by subtracting off mean and dividing by standard deviation.

Traditional LK is sensitive to changes in brightness (SSD makes a constant brightness assumption!)

CSE486Robert Collins

MultiScale Gradient Descent

. • Traditional LK is just refining a position estimate

• We must be close to the right answer to start with,and we are only guaranteed to descend to a localminimum in the SSD function (might not be best)

• To increase range of LK methods, we can applythem in a coarse to fine image pyramid, so at eachlevel a small refinement is sufficient.

CSE486Robert Collins

Baker, Matthews, CMU

State of the Art Lucas Kanade TrackingTracking facial mesh models

CSE486Robert Collins

Using LK to Align the Background

CSE486Robert Collins

LK for Aligning the Background

General idea: We can also apply LK to align the whole image, which amounts to stabilizing the background of a moving camera.

Page 4: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

4

CSE486Robert Collins

Destination image

Recall: Projective Warping

from Hartley & Zisserman

Source Image

H

Usually need at least a projective warp to align the image, because field of view islarger. Assumption: 1) background is approximately planar OR 2) cameramotion is mostly rotational (small translation)

CSE486Robert Collins

Summary: Planar Projection

x

y

Point on planeRotation + Translation

Perspectiveprojection

Pixel coordsu

v

Internalparams

Homography

CSE486Robert Collins

Estimating a Homography

Matrix Form:

Equations:

= Wx(x,y; h11, ... , h33)

= Wy(x,y; h11, ... , h33)

CSE486Robert Collins

Degrees of Freedom?

There are 9 numbers h11,…,h33 , so are there 9 DOF?

No. Note that we can multiply all hij by nonzero kwithout changing the equations:

CSE486Robert Collins

Estimating a Homography

Matrix Form:

Equations:

= Wx(x,y; h11, ... , h32)

= Wy(x,y; h11, ... , h32)

Actually, we need to enforce that there are only eight degrees of freedom. Is usually suffices to set h33=1.

1

1

1

CSE486Robert Collins

Application: Stabilization

Given a sequence of video frames, warp theminto a common image coordinate system.

This “stabilizes” the video to appear as if thecamera is not moving.

frame k k+1 k+2k-1k-2

destinationframe

Page 5: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

5

CSE486Robert Collins

Motivation for Stabilization

• Make it easier to distinguish object motionfrom camera motion

• Allows simpler object motion predictionmodels (e.g. constant velocity) to be moreaccurate.

• Easier for people to look at

CSE486Robert Collins

Stabilization Example

VIVID project

CSE486Robert Collins

Stabilization by Chaining

What if the reference image does not overlap with all the source images? As long as there are pairwise overlaps, wecan chain (compose) pairwise homographies.

frame k k+1 k+2

destination

k+3 k+4

Not recommended for long sequences, as alignment errors accumulate over time.

H43H3

2H21H1

0

H40 = H1

0 * H21 * H3

2 * H43

CSE486Robert Collins

Application: Mosaicing

from Hartley & Zisserman

Destination imageSource 1 Source 2

Mosaic

H1 H2

CSE486Robert Collins

Fixation via Mosaicingincoming image is aligned to a background mosiac and adjustments topan/tilt are made to keep a feature near center of the image.

Sarnoff, VSAM project

CSE486Robert Collins

Note on Background Stabilization

Homography assumes scene is roughly planar.

What if scene isn’t planar? Alignment will not be good if significant 3D relief

“parallax”

Page 6: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

6

CSE486Robert Collins

Parallax due to Nonplanarity

Sarnoff, VSAM project

CSE486Robert Collins

Pan/Tilt Mosiac Tracking

Dellaert and Collins

http://www.cs.cmu.edu/~rcollins/Frank/framerate/framerate.html

CSE486Robert Collins

An alternate, feature-based approach

CSE486Robert Collins

Idea: Sparse Feature Matching

I(x,y,t) I(x,y,t+1)

General idea: Find corners in one image (because these are good areas to estimate displacement) Use translation-only LK to estimate displacement Fit higher-order parametric motion to the sparse displacements to estimate the warp

CSE486Robert Collins

KLT Algorithm

Public-domain code by Stan Birchfield.Available from

http://www.ces.clemson.edu/~stb/klt/

Tracking corner features through 2 or more frames

CSE486Robert Collins

KLT Algorithm

1. Find corners in first image2. Extract intensity patch around each corner3. Use Lucas-Kanade algorithm to estimate

constant displacement of pixels in patch

1. Iteration and multi-resolution to handle large motions 2. Subpixel displacement estimates (bilinear interp warp)3. Can track feature through a whole sequence of frames4. Ability to add new features as old features get “lost”

Niceties

Page 7: Step-by-Step Derivationrtc12/CSE598G/LKintroContinued_6pp.pdf · Step-by-Step Derivation istheJacobianofthewarp P W isthegradientofimageIatWxyP y I x I I ... in a Gauss-Newton gradient

7

CSE486Robert Collins

Fit Homography using Least Squares

We now have a set of point correspondences (x , y) --> (x’, y’)

Assume related by homography:

Solve for h11,...,h32 using least squares.

CSE486Robert Collins

L.S. using Algebraic Distance

Multiplying through by denominator

Rearrange

CSE486Robert Collins

Algebraic Distance, h33=1 (cont)

Point 1

additionalpoints

2N x 8 8 x 1 2N x 1

Point 4

Point 3

Point 2

CSE486Robert Collins

Algebraic Distance, h33=1 (cont)

A h = b2Nx8 8x1 2Nx1Linear

equations

Solve: AT A h = AT b 2Nx8 8x1 2Nx18x2N 8x2N

(AT A) h = (AT b)8x18x8 8x1

h = (AT A) (AT b)-1

Matlab: h = A \ b

CSE486Robert Collins

Caution: Numeric Conditioning

R.Hartley: “In Defense of the Eight Point Algorithm”

Observation: Linear estimation of projective transformation parameters from point correspondences often suffer from poor“conditioning” of the matrices involves. This means the solutionis sensitive to noise in the points (even if there are no outliers).

To get better answers, precondition the matrices by performinga normalization of each point set by:• translating center of mass to the origin • scaling so that average distance of points from origin is sqrt(2).• do this normalization to each point set independently

Read the paper if you care (it is a nice paper). But usually in matlab, using double float, it doesn’t matter.