1 of 219

2 of 219

3 of 219

Say we want affine transformation

  • How many knowns do we get with one match? mA = n
    • nx = a00*mx + a01*my + a02*1
    • ny = a10*mx + a11*my + a12*1
    • Solve M a = b
      • MT M a = MT b
      • a = (MT M)-1 MT b
    • Still works if overdetermined
      • WHY???

4 of 219

Linear least squares

Want to minimize squared error: || b - M a ||2 =

bTb - 2aTMTb + aTMTMa

This is convex and minimized when gradient = 0. So we take the derivative wrt a and set = 0.

-MTb + (MTM)a = 0

(MTM)a = MTb

a = (MTM)-1MTb yay!!!!

5 of 219

So how does least squares do?

6 of 219

So how does least squares do?

Error based on squared residual

Very scared of being wrong, even for just one point

Very bad at handling outliers in data

7 of 219

RANSAC: RANdom SAmple Consensus

8 of 219

RANSAC: RANdom SAmple Consensus

  • Parameters: data, model, n points to fit model,�k iterations, t threshold, d “good” fit cutoff

bestmodel = None�bestfit = INF�While i < k:� sample = draw n random points from data� Fit model to sample� inliers = data within t of model� if inliers > bestfit:� Fit model to all inliers� bestfit = fit� bestmodel = model� if inliers > d:� return model�return bestmodel

9 of 219

RANSAC: RANdom SAmple Consensus

  • Works well even with extreme noise.

10 of 219

We want projective (homography)

  • New matrix equations:

  • Same procedure, Solve M a = b
    • Exact if #rows of M = 8
    • Least squares if #rows of M > 8

11 of 219

In practice:

12 of 219

What’s happening?

13 of 219

Very bad for big panoramas!

14 of 219

How do we fix it? Cylinders!

15 of 219

How do we fix it? Cylinders!

16 of 219

How do we fix it? Cylinders!

17 of 219

Does it work?

18 of 219

Does it work? Yay!

19 of 219

THIS IS AS GOOD AS IT GETS!

  • Not so fast…
  • Our descriptor has some issues:
    • Not invariant to lighting changes!
  • Want features invariant to lighting

20 of 219

Histogram of Oriented Gradients (HOG)

Binning from http://aishack.in/tutorials/sift-scale-invariant-feature-transform-features/

  • Dalal and Triggs 2005
  • Better image descriptor
    • Compute gradients
    • Bin gradients
    • Aggregate blocks (4x4, 16x16 cells)
    • Normalize gradient magnitudes
  • Not reliant on magnitude, just direction
    • Invariant to some lighting changes
  • Train SVM to recognize people

21 of 219

Histogram of Oriented Gradients (HOG)

22 of 219

THIS IS AS GOOD AS IT GETS!

  • Not so fast…
  • Harris and has some issues:
    • Corners detection is rotation invariant
    • Harris not invariant to scale
  • Descriptors are also hard
    • Just looking at pixels is not rotation invariant!
    • HOG also not rotation invariant

23 of 219

Want features invariant to scaling, rotation, etc.

  • Scale Invariant Feature Transform (SIFT)
    • Lowe et al. 2004, many images from that paper
  • Get scale-invariant response map
  • Find keypoints
  • Extract rotation-invariant descriptors
    • Normalize based on orientation
    • Normalize based on lighting

24 of 219

Extract DoG features at multiple scales

25 of 219

Find local-maxima in location and scale

26 of 219

Throw out weak responses and edges

  • Estimate gradients
    • Similar to before, look at nearby responses
    • Not whole image, only a few points! Faster!
    • Throw out weak responses
  • Find cornery things
    • Same deal, structure matrix, use det and trace information

27 of 219

Find main orientation of patches

  • Look at weighted histogram of nearby gradients
    • Any gradient within 80% of peak gets its own descriptor
      • Multiple keypoints per pixel
    • Descriptors are normalized based on main orientation

28 of 219

Keypoints are normalized gradient histograms

  • Divide into subwindows (2x2, 4x4)
  • Bin gradients within subwindow, get histogram
    • Normalize to unit length
    • Clamp at maximum .2
    • Normalize again
    • Helps with lighting changes!

29 of 219

SIFT is great!

  • Find good keypoints, describe them
  • Finding objects, recognition, panoramas, etc.

30 of 219

SIFT is great!

31 of 219

Slides by: Connor Schenck

32 of 219

Topics:

  • Sparse* Optical Flow (Lucas-Kanade, 1981)
  • Dense Optical Flow (Farneback, 2003)

*LK can technically be dense.

33 of 219

What is Optical Flow?

34 of 219

What is Optical Flow?

Movement

35 of 219

What is Optical Flow?

Movement

36 of 219

What is Optical Flow?

Movement

37 of 219

What is Optical Flow?

Movement

38 of 219

What is Optical Flow?

Movement

Object

39 of 219

What is Optical Flow?

Movement

Pan

40 of 219

What is Optical Flow?

Movement

Forward

41 of 219

What is Optical Flow?

Movement

42 of 219

Why do we want Optical Flow?

43 of 219

Why do we want Optical Flow?

Motion Estimation

44 of 219

Why do we want Optical Flow?

Motion Estimation

Object Tracking

45 of 219

Why do we want Optical Flow?

Motion Estimation

Object Tracking

Visual Odometry

46 of 219

How do we find the flow in an image?

47 of 219

Feature Matching

48 of 219

Previously: Features!

  • Highly descriptive local regions
  • Ways to describe those regions
  • Useful for:
    • Matching
    • Recognition
    • Detection

49 of 219

Feature Matching

50 of 219

Feature Matching

51 of 219

Feature Matching

SOLVED!

52 of 219

Feature Matching

Disadvantages:

53 of 219

Feature Matching

Disadvantages:

-Sparse!

54 of 219

Feature Matching

Disadvantages:

-Sparse!

-Feature alignment not exact

55 of 219

Feature Matching

56 of 219

Feature Matching

Disadvantages:

-Sparse!

-Feature alignment not exact

-Low accuracy

57 of 219

Feature Matching

Advantages:

Disadvantages:

-Sparse!

-Feature alignment not exact

-Low accuracy

58 of 219

Feature Matching

Advantages:

-Scale/rotation invariant

-*kinda* lighting invariant

-Can handle large movements

Disadvantages:

-Sparse!

-Feature alignment not exact

-Low accuracy

59 of 219

Feature Matching

Advantages:

-Scale/rotation invariant

-*kinda* lighting invariant

-Can handle large movements

Disadvantages:

-Sparse!

-Feature alignment not exact

-Low accuracy

Overall: Doesn’t work very well for Optical Flow

60 of 219

What do we do instead?

61 of 219

An observation...

62 of 219

An observation...

63 of 219

An observation...

64 of 219

An observation...

65 of 219

An observation...

f(t)

66 of 219

An observation...

f(t)

67 of 219

An observation...

f(t)

68 of 219

An observation...

f(t)

69 of 219

An observation...

f(t)

70 of 219

An observation...

f(t)

71 of 219

An observation...

f(t)

72 of 219

An observation...

f(t)

73 of 219

An observation...

f(t)

74 of 219

An observation...

f(t)

f(-p)

75 of 219

An observation...

f(t)

f(-p)

SAME!

76 of 219

An observation...

f(t)

f(-p)

Insight: Moving the object to the right is the same as moving the observed pixel to the left

77 of 219

Lucas-Kanade Optical Flow

Can we use this relationship to compute optical flow?

78 of 219

Lucas-Kanade Optical Flow

Can we use this relationship to compute optical flow?

B.D. Lucas, T. Kanade, “An Image Registration Technique with an Application to Stereo Vision”, in Proceedings of Image Understanding Workshop, 1981, pp. 121-130.

79 of 219

Lucas-Kanade Optical Flow

Can we use this relationship to compute optical flow?

B.D. Lucas, T. Kanade, “An Image Registration Technique with an Application to Stereo Vision”, in Proceedings of Image Understanding Workshop, 1981, pp. 121-130.

You will be implementing the LK optical flow algorithm for the homework

80 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

81 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Observation point

82 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

The movement @p

83 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

First image

Second image

84 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Brightness

85 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Approximate with a first-order Taylor expansion

86 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Approximate with a first-order Taylor expansion

What in the doodely is a first-order Taylor expansion?

87 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

88 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

89 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For first-order i=1

≈ a1x1 + a0x0

≈ mx + b

90 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For first-order i=1

≈ a1x1 + a0x0

≈ mx + b

x

f(x)

mx + b

91 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For first-order i=1

≈ a1x1 + a0x0

≈ mx + b

x

f(x)

mx + b

Equal at x

92 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Approximate with a first-order Taylor expansion

m(p - 𝚫p) + b ≈ f(p, t + 𝚫t)

93 of 219

Lucas-Kanade Optical Flow

Assuming the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Approximate with a first-order Taylor expansion

m(p - 𝚫p) + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

94 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

Out of space

95 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Subtract f(p, t) from both sides

96 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

97 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

Plugging mp + b in for f(p, t) cancels out!

98 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

Plugging mp + b in for f(p, t) cancels out!

99 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

100 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

These we know

101 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

These we know

This is what we want to know

102 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

These we know

This is what we want to know

What is this?!

103 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

Slope

x

f(x)

mx + b

104 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

Slope = derivative

x

f(x)

mx + b

105 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

Slope = derivative, aka gradient,

We know how to do gradients!

x

f(x)

mx + b

106 of 219

Previously: Image derivatives

  • Recall:
  • We don’t have an “actual”�Function, must estimate
  • Possibility: set h = 2
  • What will that look like?

107 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

m = dp = dx 0

0 dy

x

f(x)

mx + b

108 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

-dp𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

109 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

-dp𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

Let’s drop the vector notation

110 of 219

Lucas-Kanade Optical Flow

mp - m𝚫p + b ≈ f(p, t + 𝚫t)

mp - m𝚫p + b - f(p, t) ≈ f(p, t + 𝚫t) - f(p, t)

Recall f(x, t) = mx + b

-m𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

-dp𝚫p ≈ f(p, t + 𝚫t) - f(p, t)

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

111 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

112 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

113 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

114 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

115 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

116 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

117 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

118 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

Solve for u,v

119 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

Solve for u,v

1 equation, 2 unknowns

120 of 219

Lucas-Kanade Optical Flow

-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)

Let’s clean up the notation a bit

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

Solve for u,v

1 equation, 2 unknowns IMPOSSIBLE!

121 of 219

Ambiguity in flow

It[x,y] =

It+1[x,y] =

Possible:�u=1, v=0�u=.5, v=.5�u=0, v=1�… underspecified!

122 of 219

Lucas-Kanade Optical Flow

Let’s back up

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

123 of 219

Lucas-Kanade Optical Flow

Let’s back up

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

What does this mean?

124 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

125 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

126 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

127 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

Brightness/x-pixel

Brightness/y-pixel

128 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

u

v

129 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

u

v

130 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

u

v

Underspecified: Lots of u and v solve this equation.

131 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

u

v

Idea: What if we assume neighbors move together? I.e., they have the same u,v.

132 of 219

Lucas-Kanade Optical Flow

dx*u + dy*v = It[x,y] - It+𝚫t[x,y]

dx

dy

u

v

133 of 219

Lucas-Kanade Optical Flow

dx1*u + dy1*v = It[x1,y1] - It+𝚫t[x1,y1]

dx2*u + dy2*v = It[x2,y2] - It+𝚫t[x2,y2]

...

dx9*u + dy9*v = It[x9,y9] - It+𝚫t[x9,y9]

9 equations, 2 unknowns

134 of 219

Lucas-Kanade Optical Flow

dx1*u + dy1*v = It[x1,y1] - It+𝚫t[x1,y1]

dx2*u + dy2*v = It[x2,y2] - It+𝚫t[x2,y2]

...

dx9*u + dy9*v = It[x9,y9] - It+𝚫t[x9,y9]

9 equations, 2 unknowns

OVERSPECIFIED!

135 of 219

Lucas-Kanade Optical Flow

S𝚫p = T

S = dx1 dy1

dx2 dy2

...

dx9 dy9

𝚫p = u

v

T = It[x1,y1] - It+𝚫t[x1,y1]

It[x2,y2] - It+𝚫t[x2,y2]

...

It[x9,y9] - It+𝚫t[x9,y9]

136 of 219

Lucas-Kanade Optical Flow

S𝚫p = T

||S𝚫p - T||2 = 0

𝚫p = (STS)-1STT

S = dx1 dy1

dx2 dy2

...

dx9 dy9

𝚫p = u

v

T = It[x1,y1] - It+𝚫t[x1,y1]

It[x2,y2] - It+𝚫t[x2,y2]

...

It[x9,y9] - It+𝚫t[x9,y9]

Least-squares solution

137 of 219

Lucas-Kanade Optical Flow

S𝚫p = T

||S𝚫p - T||2 = 0

𝚫p = (STS)-1STT

S = dx1 dy1

dx2 dy2

...

dx9 dy9

𝚫p = u

v

T = It[x1,y1] - It+𝚫t[x1,y1]

It[x2,y2] - It+𝚫t[x2,y2]

...

It[x9,y9] - It+𝚫t[x9,y9]

What if this isn’t invertible?

138 of 219

Lucas-Kanade Optical Flow

S𝚫p = T

||S𝚫p - T||2 = 0

𝚫p = (STS)-1STT

S = dx1 dy1

dx2 dy2

...

dx9 dy9

𝚫p = u

v

T = It[x1,y1] - It+𝚫t[x1,y1]

It[x2,y2] - It+𝚫t[x2,y2]

...

It[x9,y9] - It+𝚫t[x9,y9]

What if this isn’t invertible?

E.G., no structure around (x,y)

139 of 219

Lucas-Kanade Optical Flow

Testing for invertibility: 𝚫p = (STS)-1STT

140 of 219

Lucas-Kanade Optical Flow

Testing for invertibility: 𝚫p = (STS)-1STT

STS is symmetric so it can be decomposed as

STS = U UT

𝛌1 0

0 𝛌2

141 of 219

Lucas-Kanade Optical Flow

Testing for invertibility: 𝚫p = (STS)-1STT

STS is symmetric so it can be decomposed as

STS = U UT

det(STS - 𝛌I) = 0

𝛌1 0

0 𝛌2

142 of 219

Lucas-Kanade Optical Flow

Testing for invertibility: 𝚫p = (STS)-1STT

STS is symmetric so it can be decomposed as

STS = U UT

det(STS - 𝛌I) = 0

= 0

𝛌1 0

0 𝛌2

𝚺i (dxi)2 - 𝛌 𝚺i (dxi)(dyi)

𝚺i (dxi)(dyi) 𝚺i (dyi)2 - 𝛌

143 of 219

Lucas-Kanade Optical Flow

Testing for invertibility: 𝚫p = (STS)-1STT

STS is symmetric so it can be decomposed as

STS = U UT

det(STS - 𝛌I) = 0

= 0

If either 𝛌1 or 𝛌2 are ≤0, S is not invertible and there is no solution!

𝛌1 0

0 𝛌2

𝚺i (dxi)2 - 𝛌 𝚺i (dxi)(dyi)

𝚺i (dxi)(dyi) 𝚺i (dyi)2 - 𝛌

144 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

145 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

146 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

Bad

No gradient

147 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

Bad

No gradient

148 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

Bad

No gradient

Slightly better

Can’t detect vertical motion

149 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

Bad

No gradient

Slightly better

Can’t detect vertical motion

150 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

Bad

No gradient

Slightly better

Can’t detect vertical motion

Best

Vertical and horizontal motion

151 of 219

Lucas-Kanade Optical Flow

How to pick (x,y)? What makes a good feature?

CORNERS!

152 of 219

Lucas-Kanade Optical Flow

When does LK fail?

153 of 219

Lucas-Kanade Optical Flow

When does LK fail?

-Lighting changes

-Large movement

-Specularities

-No good features

-Aperture Problem

154 of 219

Lucas-Kanade Optical Flow

When does LK fail?

-Lighting changes

-Large movement

-Specularities

-No good features

-Aperture Problem

155 of 219

Lucas-Kanade Optical Flow

Aperture Problem

156 of 219

Lucas-Kanade Optical Flow

Aperture Problem

Line moving up and to the right

157 of 219

Lucas-Kanade Optical Flow

Aperture Problem

Line moving up and to the right

158 of 219

Lucas-Kanade Optical Flow

Aperture Problem

Line moving up and to the right

Line moving only to the right

159 of 219

Lucas-Kanade Optical Flow

Aperture Problem - Barber pole illusion

160 of 219

Lucas-Kanade Optical Flow

Aperture Problem - Barber pole illusion

161 of 219

Lucas-Kanade Optical Flow

Aperture Problem - Barber pole illusion

Actual movement to the right

162 of 219

Lucas-Kanade Optical Flow

Aperture Problem - Barber pole illusion

Apparent movement to the up and right

163 of 219

Improving on LK: Iterative LK

dx1*u + dy1*v = It[x,y] - It+𝚫t[x,y]

164 of 219

Improving on LK: Iterative LK

dx1*u + dy1*v = It[x,y] - It+𝚫t[x,y]

dx2*u + dy2*v = It[x,y] - It+𝚫t[x + dx1,y + dy1]

Propagate dx1, dy1 forward and re-estimate

165 of 219

Improving on LK: Iterative LK

dx1*u + dy1*v = It[x,y] - It+𝚫t[x,y]

dx2*u + dy2*v = It[x,y] - It+𝚫t[x + dx1,y + dy1]

...

dxn*u + dyn*v = It[x,y] - It+𝚫t[x + dxn-1,y + dyn-1]

Propagate dx1, dy1 forward and re-estimate

Propagate dx2, dy2 forward and re-estimate

166 of 219

Improving on LK: Image Pyramids

167 of 219

Improving on LK: Image Pyramids

Image 1

Image 2

168 of 219

Improving on LK: Image Pyramids

Image 1

Image 2

169 of 219

Improving on LK: Image Pyramids

Image 1

Image 2

Run LK

Run LK

Run LK

Upsample

Upsample

170 of 219

Optical Flow

171 of 219

Optical Flow

Sparse vs Dense

172 of 219

Optical Flow

Sparse vs Dense

Compute flow only for specific features

Compute flow for all pixels

173 of 219

Optical Flow

Sparse vs Dense

Compute flow only for specific features

Compute flow for all pixels

Lucas-Kanade is technically a dense algorithm, but in practice only works on good feature points, i.e., it’s sparse.

174 of 219

Optical Flow

Is there a way to do dense optical flow?

175 of 219

Farnebäck Optical Flow

Farnebäck, Gunnar. "Two-frame motion estimation based on polynomial expansion." Scandinavian conference on Image analysis. Springer, Berlin, Heidelberg, 2003.

176 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

177 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

In LK we approximate this with a first-order Taylor Expansion

178 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

179 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For first-order i=1

≈ a1x1 + a0x0

≈ mx + b

x

f(x)

mx + b

180 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For second-order i=2

≈ a1x2 + a1x1 + a0x0

≈ ax2 + bx + c

x

f(x)

ax2 + bx + c

181 of 219

Quick & Dirty: Taylor Expansion

Approximate complex function with nth-order polynomial

f(x) ≈ 𝚺i aixi

For second-order i=2

≈ a1x2 + a1x1 + a0x0

≈ ax2 + bx + c

xTAx + bx + c

x

f(x)

ax2 + bx + c

Vector notation

182 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

183 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

184 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

Poly parameters from first image

Poly parameters from second image

185 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

186 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

187 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

At = At+𝚫t

188 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

At = At+𝚫t

189 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

At = At+𝚫t

bt+𝚫t = bt - 2At𝚫p

190 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

At = At+𝚫t

bt+𝚫t = bt - 2At𝚫p

191 of 219

Farnebäck Optical Flow

Recall: We assumed the object moves by 𝚫p over 𝚫t

f(p - 𝚫p, t) = f(p, t + 𝚫t)

Instead, let’s approximate with a second-order Taylor Expansion

(p-𝚫p)TAt(p-𝚫p) + bt(p-𝚫p) + ct = pTAt+𝚫tp + bt+𝚫tp + ct+𝚫t

pTAtp + (bt - 2At𝚫p)Tp + 𝚫pTAt𝚫p - bt𝚫p + ct = pTAt+𝚫tp + pbt+𝚫t + ct+𝚫t

At = At+𝚫t

bt+𝚫t = bt - 2At𝚫p

ct+𝚫t = 𝚫pTAt𝚫p - bt𝚫p + ct

192 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

193 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

194 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

A, b, and c can be solved pointwise using least squares over a small neighborhood like before

195 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

A, b, and c can be solved pointwise using least squares over a small neighborhood like before

196 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

A, b, and c can be solved pointwise using least squares over a small neighborhood like before

S = x1 y1

x2 y2

...

xk yk

T = I[x1,y1]

I[x2,y2]

...

I[xk,yk]

197 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

A, b, and c can be solved pointwise using least squares over a small neighborhood like before

S = x1 y1

x2 y2

...

xk yk

T = I[x1,y1]

I[x2,y2]

...

I[xk,yk]

SAST + bST + c = T

||SAST + bST + c - T||2 = 0

198 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

A, b, and c can be solved pointwise using least squares over a small neighborhood like before

S = x1 y1

x2 y2

...

xk yk

T = I[x1,y1]

I[x2,y2]

...

I[xk,yk]

SAST + bST + c = T

||SAST + bST + c - T||2 = 0

Quadratic Regression

199 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Solve for 𝚫p

𝚫p = -½(At)-1(bt+𝚫t - bt)

Same problem as before:

What if it’s not invertible?

200 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

201 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

At𝚫p = -½(bt+𝚫t - bt)

202 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

At𝚫p = -½(bt+𝚫t - bt)

At = At+𝚫t

203 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

At𝚫p = -½(bt+𝚫t - bt)

At = At+𝚫t

At ≠ At+𝚫t

In reality not equal

204 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

At𝚫p = -½(bt+𝚫t - bt)

At = At+𝚫t

At ≠ At+𝚫t

In reality not equal

A = ½(At + At+𝚫t)

Average together

205 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = -½(bt+𝚫t - bt)

206 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = -½(bt+𝚫t - bt)

𝚫b = -½(bt+𝚫t - bt)

207 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = 𝚫b

208 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = 𝚫b

Assume neighbors move together (just like LK)

209 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = 𝚫b

Assume neighbors move together (just like LK)

Ai𝚫p = 𝚫bi

210 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = 𝚫b

Assume neighbors move together (just like LK)

Ai𝚫p = 𝚫bi

Apply least squares

𝚺i wi||Ai𝚫p - 𝚫bi||2

211 of 219

Farnebäck Optical Flow

bt+𝚫t = bt - 2At𝚫p

Let’s try a different approach:

A𝚫p = 𝚫b

Assume neighbors move together (just like LK)

Ai𝚫p = 𝚫bi

Apply least squares

𝚺i wi||Ai𝚫p - 𝚫bi||2

Gaussian weight (so we care more about the center of the neighborhood than the edges)

212 of 219

Farnebäck Optical Flow

Still assuming 𝚫p is constant over the neighborhood, but not really true…

213 of 219

Farnebäck Optical Flow

Still assuming 𝚫p is constant over the neighborhood, but not really true…

Relax and assume instead 𝚫p is an affine function in the neighborhood.

214 of 219

Farnebäck Optical Flow

Still assuming 𝚫p is constant over the neighborhood, but not really true…

Relax and assume instead 𝚫p is an affine function in the neighborhood.

𝚫p =

a1 + a2x + a3y + a7x2 + a8xy

a4 + a5x + a6y + a7xy + a8y2

215 of 219

Farnebäck Optical Flow

Still assuming 𝚫p is constant over the neighborhood, but not really true…

Relax and assume instead 𝚫p is an affine function in the neighborhood.

𝚫p =

𝚫p = Sd

a1 + a2x + a3y + a7x2 + a8xy

a4 + a5x + a6y + a7xy + a8y2

S =

1 x y 0 0 0 x2 xy

0 0 0 1 x y xy y2

d =

a1

a2

a3

a4

a5

a6

a7

a8

216 of 219

Farnebäck Optical Flow

𝚺i wi||Ai𝚫p - 𝚫bi||2

217 of 219

Farnebäck Optical Flow

𝚺i wi||Ai𝚫p - 𝚫bi||2

𝚺i wi||AiSd - 𝚫bi||2

Plug in Sd for 𝚫p.

218 of 219

Farnebäck Optical Flow

𝚺i wi||Ai𝚫p - 𝚫bi||2

𝚺i wi||AiSd - 𝚫bi||2

d = 𝚺iwi(Si)T(Ai)TSi 𝚺iwi(Si)T(Ai)T𝚫bi

Plug in Sd for 𝚫p.

Least squares solve for d

-1

219 of 219

Farnebäck Optical Flow

𝚺i wi||Ai𝚫p - 𝚫bi||2

𝚺i wi||AiSd - 𝚫bi||2

d = 𝚺iwi(Si)T(Ai)TSi 𝚺iwi(Si)T(Ai)T𝚫bi

Plug in Sd for 𝚫p.

Least squares solve for d

-1

Same inverse problem, but in practice less of an issue