219
Alignment and tracking 16-385 Computer Vision Spring 2020, Lecture 25 http://www.cs.cmu.edu/~16385/

Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Alignment and tracking

16-385 Computer VisionSpring 2020, Lecture 25http://www.cs.cmu.edu/~16385/

Page 2: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

• Homework 6 has been posted and is due on April 22nd. - Any questions about the homework?- How many of you have looked at/started/finished homework 6?

• Take-home quiz 10 has been posted and is due on April 19th.

Course announcements

Page 3: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

• Finish optical flow lecture.

• Motion magnification using optical flow.

• Image alignment.

• Lucas-Kanade alignment.

• Baker-Matthews alignment.

• Inverse alignment.

• KLT tracking.

• Mean-shift tracking.

• Modern trackers.

Overview of today’s lecture

Page 4: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Slide credits

Most of these slides were adapted from:

• Kris Kitani (16-385, Spring 2017).

Page 5: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Motion magnification using

optical flow

Page 6: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

original motion-magnified

How would you achieve this effect?

• Compute optical flow from frame to frame.

• Magnify optical flow velocities.

• Appropriately warp image intensities.

Page 7: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

naïvely motion-magnified motion-magnified

How would you achieve this effect?

• Compute optical flow from frame to frame.

• Magnify optical flow velocities.

• Appropriately warp image intensities.

In practice, many additional steps

are required for a good result.

Page 8: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Some more examples

Page 9: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Some more examples

Page 10: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Image alignment

Page 11: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 12: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 13: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

http://www.humansensing.cs.cmu.edu/intraface/

Page 14: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 15: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

How can I find in the image?

Page 16: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Idea #1: Template Matching

Slow, combinatory, global solution

Page 17: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Idea #2: Pyramid Template Matching

Faster, combinatory, locally optimal

Page 18: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Idea #3: Model refinement

Fastest, locally optimal

(when you have a good initial solution)

Page 19: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Some notation before we get into the math…

2D image transformation

2D image coordinate

Parameters of the transformation

Translation

Affine

Pixel value at a coordinate

Warped image

Page 20: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Some notation before we get into the math…

2D image transformation

2D image coordinate

Parameters of the transformation

Translation

transform coordinate

Affine

Pixel value at a coordinate

Warped image

Page 21: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Some notation before we get into the math…

2D image transformation

2D image coordinate

Parameters of the transformation

Translation

transform coordinate

Affine

Pixel value at a coordinate

affine transformcoordinate

Warped image

can be written in matrix form when linearaffine warp matrix can also be 3x3 when last row is [0 0 1]

Page 22: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

is a function of ____ variables

takes a ________ as input and returns a _______

returns a ______ of dimension ___ x ___

where N is _____ for an affine model

this warp changes pixel values?

Page 23: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Image alignment(problem definition)

warped image template image

Find the warp parameters p such that the

SSD is minimized

Page 24: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Find the warp parameters p such that the

SSD is minimized

Page 25: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Image alignment(problem definition)

warped image template image

Find the warp parameters p such that the

SSD is minimized

How could you find a solution to this problem?

Page 26: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

This is a non-linear (quadratic) function of a

non-parametric function!

(Function I is non-parametric)

Hard to optimize

What can you do to make it easier to solve?

Page 27: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Hard to optimize

What can you do to make it easier to solve?

assume good initialization,

linearized objective and update incrementally

This is a non-linear (quadratic) function of a

non-parametric function!

(Function I is non-parametric)

Page 28: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Lucas-Kanade alignment

Page 29: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

If you have a good initial guess p…

can be written as …

(a small incremental adjustment)

(pretty strong assumption)

(this is what we are solving for now)

Page 30: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

How can we linearize the function I for a really small perturbation of p?

This is still a non-linear (quadratic) function of a

non-parametric function!

(Function I is non-parametric)

Page 31: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

How can we linearize the function I for a really small perturbation of p?

Taylor series approximation!

This is still a non-linear (quadratic) function of a

non-parametric function!

(Function I is non-parametric)

Page 32: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Multivariable Taylor Series Expansion

(First order approximation)

Page 33: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Multivariable Taylor Series Expansion

(First order approximation)

Recall:

chain rule

short-hand

short-hand

Page 34: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Linear approximation

Multivariable Taylor Series Expansion

(First order approximation)

What are the unknowns here?

Page 35: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Linear approximation

Multivariable Taylor Series Expansion

(First order approximation)

Now, the function is a linear function of the unknowns

Page 36: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

is a function of _____ variables

is a _________ of dimension ___ x ___

is a _________ of dimension ___ x ___

is a __________ of dimension ___ x ___

output of

Page 37: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

The Jacobian

Affine transform

Rate of change of the warp

(A matrix of partial derivatives)

Page 38: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

is a _________ of dimension ___ x ___

is a _________ of dimension ___ x ___

is a _________ of dimension ___ x ___

Page 39: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 40: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

Page 41: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

Page 42: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

Page 43: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

warp parameters

(6 for affine)

Page 44: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

warp parameters

(6 for affine)

image gradient

(1 x 2)

Page 45: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

warp parameters

(6 for affine)

image gradient

(1 x 2)

Partial derivatives of warp function

(2 x 6)

Page 46: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

warp parameters

(6 for affine)

image gradient

(1 x 2)

Partial derivatives of warp function

(2 x 6)

incremental warp

(6 x 1)

Page 47: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

pixel coordinate

(2 x 1)

image intensity

(scalar)

warp function

(2 x 1)

warp parameters

(6 for affine)

image gradient

(1 x 2)

Partial derivatives of warp function

(2 x 6)

incremental warp

(6 x 1)

template image intensity

(scalar)

When you implement this, you will compute everything in parallel and store as matrix … don’t loop over x!

Page 48: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Summary(of Lucas-Kanade Image Alignment)

Solve for increment

Taylor series approximation

Linearize

Difficult non-linear optimization problem

Assume known approximate solution

Strategy:

Problem:

then solve for

warped image template image

Page 49: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

OK, so how do we solve this?

Page 50: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Another way to look at it…

(moving terms around)

Have you seen this form of optimization problem before?

vector of

variables

vector of

constantsconstant

Page 51: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Another way to look at it…

How do you solve this?

Looks like

variableconstant constant

Page 52: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Least squares approximation

is solved by

is optimized when

where

Applied to our tasks:

after applying

Page 53: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Solve for increment

Taylor series approximation

Linearize

Difficult non-linear optimization problem

Assume known approximate solution

Strategy:

Solve:

warped image template image

Solution:Solution to least squares

approximation

Hessian

Page 54: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Gauss-Newton gradient decent

non-linear optimization!

This is called…

Page 55: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Lucas Kanade (Additive alignment)

Just 8 lines of code!

x’coordinates of the warped image

(gradients of the warped image)

Page 56: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Baker-Matthews alignment

Page 57: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Image Alignment(start with an initial solution, match the image and template)

Page 58: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Additive Alignment

incremental perturbation of parameters

Image Alignment Objective Function

Given an initial solution…several possible formulations

Page 59: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional Alignment

incremental warps of image

Image Alignment Objective Function

Given an initial solution…several possible formulations

Additive Alignment

incremental perturbation of parameters

Page 60: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Additive strategy

go back, adjust and try

again

first shot

second shot

Page 61: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional strategy

start from herefirst shot

second shot

Page 62: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Additive

I(x)

W(x;p)

Page 63: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

T(x)Additive

I(x)

W(x;p+Dp)

W(x;p)

Page 64: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

W(x;0 + Dp) = W(x;Dp) W(x;p)

Compositional

I(x)

T(x)Additive

I(x)

W(x;p+Dp)

W(x;p)

Page 65: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

W(x;0 + Dp) = W(x;Dp)

T(x)

W(x;p)

W(x;p) o W(x;Dp)Compositional

I(x)

T(x)Additive

I(x)

W(x;p)

W(x;p+Dp)

Page 66: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional Alignment

Assuming an initial solution p and a compositional warp increment

Original objective function (SSD)

Page 67: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional Alignment

Assuming an initial solution p and a compositional warp increment

Original objective function (SSD)

Another way to write the composition Identity warp

Page 68: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional Alignment

Assuming an initial solution p and a compositional warp increment

Original objective function (SSD)

Another way to write the composition

Skipping over the derivation…the new update rule is

Identity warp

Page 69: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

So what’s so great about this compositional form?

Page 70: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

linearized form linearized form

Additive Alignment Compositional Alignment

Page 71: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

The Jacobian is constant.

Jacobian can be precomputed!

linearized form linearized form

Jacobian of W(x;p) Jacobian of

W(x;0)

Additive Alignment Compositional Alignment

Page 72: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional Image Alignment

Minimize

W(x;0 + Dp) = W(x;Dp)

T(x)

W(x;p)

W(x;p) o W(x;Dp)

Jacobian is simple and can be precomputed

Page 73: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Lucas Kanade (Additive alignment)

Page 74: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Shum-Szeliski (Compositional alignment)

Page 75: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Any other speed up techniques?

Page 76: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Inverse alignment

Page 77: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Why not compute warp updates on the template?

Additive Alignment Compositional Alignment

Page 78: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Why not compute warp updates on the template?

Additive Alignment Compositional Alignment

What happens if you let the template be

warped too?

Inverse Compositional Alignment

Page 79: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

W(x;0 + Dp) = W(x;Dp)

T(x)

W(x;p)

W(x;p) o W(x;Dp)

T(x)W(x;0 + Dp) = W(x;Dp)W(x;p)

Compositional

Inverse compositionalW(x;p) o W(x;Dp)-1

I(x)

I(x)

Page 80: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compositional strategy

start from herefirst shot

second shot

Page 81: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Inverse Compositional strategy

first shotmove the hole

Page 82: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

So what’s so great about this inverse compositional form?

Page 83: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Inverse Compositional Alignment

Minimize

Solution

Update

can be precomputed from template!

Page 84: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Properties of inverse compositional alignment

Jacobian can be precomputedIt is constant - evaluated at W(x;0)

Gradient of template can be precomputedIt is constant

Hessian can be precomputed

Warp must be invertible

(main term that needs to be computed)

Page 85: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Lucas Kanade (Additive alignment)

Page 86: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Shum-Szeliski (Compositional alignment)

Page 87: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1. Warp image

2. Compute error image

3. Compute gradient

4. Evaluate Jacobian

5. Compute Hessian

6. Compute

7. Update parameters

Baker-Matthews (Inverse Compositional alignment)

Page 88: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Algorithm Efficient Authors

Forwards Additive No Lucas, Kanade

Forwards

compositionalNo Shum, Szeliski

Inverse Additive Yes Hager, Belhumeur

Inverse

CompositionalYes Baker, Matthews

Page 89: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kanade-Lucas-Tomasi

(KLT) tracker

Page 90: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

https://www.youtube.com/watch?v=rwIjkECpY0M

Page 91: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Feature-based tracking

How should we select the ‘small images’ (features)?

How should we track them from frame to frame?

Up to now, we’ve been aligning entire images

but we can also track just small image regions too!(sometimes called sparse tracking or sparse alignment)

Page 92: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

An Iterative Image Registration Technique

with an Application to Stereo Vision.

1981

Lucas Kanade

Detection and Tracking of Feature Points.

1991

Kanade Tomasi

Good Features to Track.

1994

Tomasi Shi

History of the

Kanade-Lucas-Tomasi

(KLT) Tracker

The original KLT algorithm

Page 93: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Method for aligning

(tracking) an image patch

Kanade-Lucas-Tomasi

Method for choosing the

best feature (image patch)

for tracking

Lucas-Kanade Tomasi-Kanade

How should we select features?How should we track them from frame to

frame?

Page 94: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

What are good features for tracking?

Page 95: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

What are good features for tracking?

Intuitively, we want to avoid smooth

regions and edges.

But is there a more is principled way to

define good features?

Page 96: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Can be derived from the tracking algorithm

What are good features for tracking?

Page 97: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Can be derived from the tracking algorithm

What are good features for tracking?

‘A feature is good if it can be tracked well’

Page 98: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Recall the Lucas-Kanade image alignment method:

incremental update

error function (SSD)

Page 99: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Recall the Lucas-Kanade image alignment method:

incremental update

error function (SSD)

linearize

Page 100: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Recall the Lucas-Kanade image alignment method:

incremental update

error function (SSD)

linearize

Gradient update

Page 101: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Recall the Lucas-Kanade image alignment method:

incremental update

error function (SSD)

linearize

Gradient update

Update

Page 102: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Stability of gradient decent iterations depends on …

Page 103: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Stability of gradient decent iterations depends on …

Inverting the Hessian

When does the inversion fail?

Page 104: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Stability of gradient decent iterations depends on …

Inverting the Hessian

When does the inversion fail?

H is singular. But what does that mean?

Page 105: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Above the noise level

Well-conditioned

both Eigenvalues are large

both Eigenvalues have similar magnitude

Page 106: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Concrete example: Consider translation model

Hessian

How are the eigenvalues related to image content?

←when is this singular?

Page 107: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

interpreting eigenvalues

l1

l2

l2 >> l1

l1 >> l2

What kind of image patch does

each region represent?

Page 108: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

interpreting eigenvalues

‘horizontal’

edge

‘vertical’

edge

flat

l1

l2

l2 >> l1

l1 >> l2

l1 ~ l2

‘corner’

Page 109: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

interpreting eigenvalues

flat

‘corner’

l1

l2

l2 >> l1

l1 >> l2

l1 ~ l2

‘horizontal’

edge

‘vertical’

edge

Page 110: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

What are good features for tracking?

Page 111: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

What are good features for tracking?

‘big Eigenvalues means good for tracking’

Page 112: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

KLT algorithm

1. Find corners satisfying

2. For each corner compute displacement to next frame using

the Lucas-Kanade method

3. Store displacement of each corner, update corner position

4. (optional) Add more corner points every M frames using 1

5. Repeat 2 to 3 (4)

6. Returns long trajectories for each corner point

Page 113: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-shift algorithm

Page 114: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 115: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Page 116: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Find the region of

highest density

Page 117: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Pick a point

Page 118: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Draw a window

Page 119: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the

(weighted) mean

Page 120: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 121: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 122: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 123: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 124: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 125: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 126: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 127: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 128: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 129: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 130: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 131: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 132: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

Page 133: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Compute the mean

Page 134: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean Shift Algorithm

Fukunaga & Hostetler (1975)

A ‘mode seeking’ algorithm

Shift the window

To understand the theory behind this we need to understand…

Page 135: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kernel density estimation

Page 136: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kernel Density Estimation

A method to approximate an underlying PDF from samples

Put ‘bump’ on every sample to approximate the PDF

To understand the mean shift algorithm …

samples (+)

bumps

sum of bumps

Page 137: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

probability density function

1 2 3 4 5 6 7 8 9 10

cumulative density function

p(x)

Say we have some hidden PDF…

Page 138: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

ran

do

mly

sa

mp

le

0

1We can draw samples,

using the CDF…

Page 139: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

ran

do

mly

sa

mp

le

0

1

Page 140: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

ran

do

mly

sa

mp

le

0

1

samples

Page 141: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

samples

Now to estimate the ‘hidden’ PDF

place Gaussian bumps on the samples…

Page 142: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

samples

discretized ‘bump’

Page 143: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

samples

Page 144: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

samples

Page 145: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

1 2 3 4 5 6 7 8 9 10

samples

Kernel Density

Estimate

approximates the

original PDF

Page 146: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kernel Density Estimation

Approximate the underlying PDF from samples from it

Put ‘bump’ on every sample to approximate the PDF

Gaussian ‘bump’ aka ‘kernel’

but there are many types of kernels!

For example…

Page 147: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kernel Function

returns the ‘distance’ between two points

Page 148: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Epanechnikov kernel

Uniform kernel

Normal kernel

These are all radially symmetric kernels

Page 149: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Radially symmetric kernels

profile

…can be written in terms of its profile

Page 150: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Connecting KDE and the

Mean Shift Algorithm

Page 151: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-Shift Tracking

Given a set of points:

and a kernel:

Find the mean sample point:

Page 152: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-Shift Algorithm

While

Initialize

1. Compute mean-shift

2. Update

Where does this algorithm come from?

shift values becomes really small

place we start

compute the ‘mean’

compute the ‘shift’

update the point

Page 153: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

While

Initialize

Where does this algorithm come from?

Where does this

come from?

Mean-Shift Algorithm

2. Update

1. Compute mean-shift

Page 154: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Kernel density estimate (radially symmetric kernels)

Gradient of the PDF is related to the mean shift vector

How is the KDE related to the mean shift algorithm?

The mean shift vector is a ‘step’ in the direction of the gradient of the KDE

Recall:

We can show that:

can compute probability for any point using the KDE!

mean-shift algorithm is maximizing the objective function

Page 155: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

In mean-shift tracking, we are trying to find this

which means we are trying to…

Page 156: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

We are trying to optimize this:

usually non-linear

How do we optimize this non-linear function?

non-parametric

find the solution that has the highest probability

Page 157: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

We are trying to optimize this:

How do we optimize this non-linear function?

compute partial derivatives … gradient descent!

usually non-linear non-parametric

Page 158: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Compute the gradient

Page 159: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Gradient

Expand the gradient (algebra)

Page 160: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Gradient

Expand gradient

Page 161: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Gradient

Expand gradient

Call the gradient of the kernel function g

Page 162: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Gradient

change of notation(kernel-shadow pairs)

Expand gradient

keep this in memory:

Page 163: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

multiply it out

too long!

(use short hand notation)

Page 164: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

multiply by one!

collecting like terms…

What’s happening here?

Page 165: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

The mean shift is a ‘step’ in the direction of the gradient of the KDE

mean shift!

mean shift

Can interpret this to be

gradient ascent with

data dependent step size

constant

Let

Page 166: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-Shift Algorithm

While

Initialize

1. Compute mean-shift

2. Update

gradient with

adaptive step size

Just 5 lines of code!

Page 167: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Everything up to now has been about

distributions over samples…

Page 168: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-shift tracker

Page 169: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Dealing with images

Pixels for a lattice, spatial density is the same everywhere!

What can we do?

Page 170: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Consider a set of points:

Sample mean:

Mean shift:

Associated weights:

Page 171: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-Shift Algorithm(for images)

While

Initialize

1. Compute mean-shift

2. Update

Page 172: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 173: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 174: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 175: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 176: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 177: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 178: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 179: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 180: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 181: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 182: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 183: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 184: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 185: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

For images, each pixel is point with a weight

Page 186: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Finally… mean shift tracking in video!

Page 187: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Frame 1 Frame 2

‘target’

center coordinate

of target

center coordinate of

candidate

Goal: find the best candidate location in frame 2

Use the mean shift algorithm

to find the best candidate location

‘candidate’there are many ‘candidates’ but only one ‘target’

Page 188: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Non-rigid object tracking

hand tracking

Page 189: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target

Compute a descriptor for the target

Page 190: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target Candidate

Search for similar descriptor in neighborhood in next frame

Page 191: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target

Compute a descriptor for the new target

Page 192: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target Candidate

Search for similar descriptor in neighborhood in next frame

Page 193: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

How do we model the target and candidate regions?

Page 194: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Modeling the target

M-dimensional target descriptor

A normalized

color histogram

(weighted by distance)

Kronecker delta

function

function of inverse

distance

(weight)

Normalization

factor

(centered at target center)

a ‘fancy’ (confusing) way to write a weighted histogram

sum over

all pixels

quantization

function

bin ID

Page 195: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Modeling the candidate

M-dimensional candidate descriptor

(centered at location y)

bandwidth

a weighted histogram at y

Page 196: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Similarity between

the target and candidate

Bhattacharyya Coefficient

Just the Cosine distance between two unit vectors

Distance function

Page 197: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Now we can compute the similarity between a

target and multiple candidate regions

Page 198: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

target

similarity over imageimage

Page 199: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

target

similarity over imageimage

we want to find this peak

Page 200: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Objective function

Assuming a good initial guess

Linearize around the initial guess (Taylor series expansion)

derivativefunction at specified value

same as

Page 201: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Remember

definition of this?

Linearized objective

Fully expanded

Page 202: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

where

Does not depend on unknown y Weighted kernel density estimate

Weight is bigger when

Fully expanded linearized objective

Moving terms around…

Page 203: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

OK, why are we doing all this math?

Page 204: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

We want to maximize this

Page 205: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

where

Fully expanded linearized objective

We want to maximize this

Page 206: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

where

Fully expanded linearized objective

doesn’t depend on unknown y

We want to maximize this

Page 207: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

where

Fully expanded linearized objective

doesn’t depend on unknown y

We want to maximize this

only need to

maximize this!

Page 208: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

where

Fully expanded linearized objective

doesn’t depend on unknown y

what can we use to solve this weighted KDE?

Mean Shift Algorithm!

We want to maximize this

Page 209: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

the new sample of mean of this KDE is

(this was derived earlier)

(new candidate

location)

Page 210: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Mean-Shift Object Tracking

1. Initialize location

Compute

Compute

2. Derive weights

3. Shift to new candidate location (mean shift)

4. Compute

5. If return

Otherwise and go back to 2

For each frame:

Page 211: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target

Compute a descriptor for the target

Page 212: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target Candidate

Search for similar descriptor in neighborhood in next frame

Page 213: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target

Compute a descriptor for the new target

Page 214: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Target Candidate

Search for similar descriptor in neighborhood in next frame

Page 215: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 216: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

Modern trackers

Page 217: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 218: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally
Page 219: Alignment and tracking16385/lectures/lecture25.pdf · Idea #1: Template Matching Slow, combinatory, global solution. Idea #2: Pyramid Template Matching Faster, combinatory, locally

References

Basic reading:• Szeliski, Sections 4.1.4, 5.3, 8.1.