Say we want affine transformation
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!!!!
So how does least squares do?
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
RANSAC: RANdom SAmple Consensus
RANSAC: RANdom SAmple Consensus
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
RANSAC: RANdom SAmple Consensus
We want projective (homography)
In practice:
What’s happening?
Very bad for big panoramas!
How do we fix it? Cylinders!
How do we fix it? Cylinders!
How do we fix it? Cylinders!
Does it work?
Does it work? Yay!
THIS IS AS GOOD AS IT GETS!
Histogram of Oriented Gradients (HOG)
Binning from http://aishack.in/tutorials/sift-scale-invariant-feature-transform-features/
Histogram of Oriented Gradients (HOG)
THIS IS AS GOOD AS IT GETS!
Want features invariant to scaling, rotation, etc.
Extract DoG features at multiple scales
Find local-maxima in location and scale
Throw out weak responses and edges
Find main orientation of patches
Keypoints are normalized gradient histograms
SIFT is great!
SIFT is great!
Slides by: Connor Schenck
Topics:
*LK can technically be dense.
What is Optical Flow?
What is Optical Flow?
Movement
What is Optical Flow?
Movement
What is Optical Flow?
Movement
What is Optical Flow?
Movement
What is Optical Flow?
Movement
Object
What is Optical Flow?
Movement
Pan
What is Optical Flow?
Movement
Forward
What is Optical Flow?
Movement
Why do we want Optical Flow?
Why do we want Optical Flow?
Motion Estimation
Why do we want Optical Flow?
Motion Estimation
Object Tracking
Why do we want Optical Flow?
Motion Estimation
Object Tracking
Visual Odometry
How do we find the flow in an image?
Feature Matching
Previously: Features!
Feature Matching
Feature Matching
Feature Matching
SOLVED!
Feature Matching
Disadvantages:
Feature Matching
Disadvantages:
-Sparse!
Feature Matching
Disadvantages:
-Sparse!
-Feature alignment not exact
Feature Matching
Feature Matching
Disadvantages:
-Sparse!
-Feature alignment not exact
-Low accuracy
Feature Matching
Advantages:
Disadvantages:
-Sparse!
-Feature alignment not exact
-Low accuracy
Feature Matching
Advantages:
-Scale/rotation invariant
-*kinda* lighting invariant
-Can handle large movements
Disadvantages:
-Sparse!
-Feature alignment not exact
-Low accuracy
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
What do we do instead?
An observation...
An observation...
An observation...
An observation...
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
An observation...
f(t)
f(-p)
An observation...
f(t)
f(-p)
SAME!
An observation...
f(t)
f(-p)
Insight: Moving the object to the right is the same as moving the observed pixel to the left
Lucas-Kanade Optical Flow
Can we use this relationship to compute optical flow?
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.
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
Lucas-Kanade Optical Flow
Assuming the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
Lucas-Kanade Optical Flow
Assuming the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
Observation point
Lucas-Kanade Optical Flow
Assuming the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
The movement @p
Lucas-Kanade Optical Flow
Assuming the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
First image
Second image
Lucas-Kanade Optical Flow
Assuming the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
Brightness
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
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?
Quick & Dirty: Taylor Expansion
Approximate complex function with nth-order polynomial
Quick & Dirty: Taylor Expansion
Approximate complex function with nth-order polynomial
f(x) ≈ 𝚺i aixi
Quick & Dirty: Taylor Expansion
Approximate complex function with nth-order polynomial
f(x) ≈ 𝚺i aixi
For first-order i=1
≈ a1x1 + a0x0
≈ mx + b
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
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
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)
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)
Lucas-Kanade Optical Flow
mp - m𝚫p + b ≈ f(p, t + 𝚫t)
Out of space
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
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
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!
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!
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)
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
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
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?!
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
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
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
Previously: Image derivatives
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
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)
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
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)
Lucas-Kanade Optical Flow
-dx𝚫x + -dy𝚫y ≈ f((x,y), t + 𝚫t) - f((x,y), t)
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]
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]
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]
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]
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]
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]
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
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
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!
Ambiguity in flow
It[x,y] =
It+1[x,y] =
Possible:�u=1, v=0�u=.5, v=.5�u=0, v=1�… underspecified!
Lucas-Kanade Optical Flow
Let’s back up
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
Lucas-Kanade Optical Flow
Let’s back up
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
What does this mean?
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
dx
dy
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
dx
dy
Brightness/x-pixel
Brightness/y-pixel
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
dx
dy
u
v
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
dx
dy
u
v
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.
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.
Lucas-Kanade Optical Flow
dx*u + dy*v = It[x,y] - It+𝚫t[x,y]
dx
dy
u
v
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
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!
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]
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
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?
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)
Lucas-Kanade Optical Flow
Testing for invertibility: 𝚫p = (STS)-1STT
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
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
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 - 𝛌
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 - 𝛌
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Bad
No gradient
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Bad
No gradient
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Bad
No gradient
Slightly better
Can’t detect vertical motion
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
Bad
No gradient
Slightly better
Can’t detect vertical motion
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
Lucas-Kanade Optical Flow
How to pick (x,y)? What makes a good feature?
CORNERS!
Lucas-Kanade Optical Flow
When does LK fail?
Lucas-Kanade Optical Flow
When does LK fail?
-Lighting changes
-Large movement
-Specularities
-No good features
-Aperture Problem
Lucas-Kanade Optical Flow
When does LK fail?
-Lighting changes
-Large movement
-Specularities
-No good features
-Aperture Problem
Lucas-Kanade Optical Flow
Aperture Problem
Lucas-Kanade Optical Flow
Aperture Problem
Line moving up and to the right
Lucas-Kanade Optical Flow
Aperture Problem
Line moving up and to the right
Lucas-Kanade Optical Flow
Aperture Problem
Line moving up and to the right
Line moving only to the right
Lucas-Kanade Optical Flow
Aperture Problem - Barber pole illusion
Lucas-Kanade Optical Flow
Aperture Problem - Barber pole illusion
Lucas-Kanade Optical Flow
Aperture Problem - Barber pole illusion
Actual movement to the right
Lucas-Kanade Optical Flow
Aperture Problem - Barber pole illusion
Apparent movement to the up and right
Improving on LK: Iterative LK
dx1*u + dy1*v = It[x,y] - It+𝚫t[x,y]
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
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
Improving on LK: Image Pyramids
Improving on LK: Image Pyramids
Image 1
Image 2
Improving on LK: Image Pyramids
Image 1
Image 2
Improving on LK: Image Pyramids
Image 1
Image 2
Run LK
Run LK
Run LK
Upsample
Upsample
Optical Flow
Optical Flow
Sparse vs Dense
Optical Flow
Sparse vs Dense
Compute flow only for specific features
Compute flow for all pixels
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.
Optical Flow
Is there a way to do dense optical flow?
Farnebäck Optical Flow
Farnebäck, Gunnar. "Two-frame motion estimation based on polynomial expansion." Scandinavian conference on Image analysis. Springer, Berlin, Heidelberg, 2003.
Farnebäck Optical Flow
Recall: We assumed the object moves by 𝚫p over 𝚫t
f(p - 𝚫p, t) = f(p, t + 𝚫t)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Solve for 𝚫p
𝚫p = -½(At)-1(bt+𝚫t - bt)
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
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
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]
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
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
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?
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
At𝚫p = -½(bt+𝚫t - bt)
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
At𝚫p = -½(bt+𝚫t - bt)
At = At+𝚫t
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
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
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
A𝚫p = -½(bt+𝚫t - bt)
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
A𝚫p = -½(bt+𝚫t - bt)
𝚫b = -½(bt+𝚫t - bt)
Farnebäck Optical Flow
bt+𝚫t = bt - 2At𝚫p
Let’s try a different approach:
A𝚫p = 𝚫b
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)
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
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
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)
Farnebäck Optical Flow
Still assuming 𝚫p is constant over the neighborhood, but not really true…
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.
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
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
Farnebäck Optical Flow
𝚺i wi||Ai𝚫p - 𝚫bi||2
Farnebäck Optical Flow
𝚺i wi||Ai𝚫p - 𝚫bi||2
𝚺i wi||AiSd - 𝚫bi||2
Plug in Sd for 𝚫p.
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
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