CSE486, Penn State Robert Collins Lecture 23: Flow Estimation Key points for today: Brightness constancy equation Aperature problem Lucas-Kanade algorithm
CSE486, Penn StateRobert Collins
Lecture 23:
Flow Estimation
Key points for today: Brightness constancy equation Aperature problem Lucas-Kanade algorithm
CSE486, Penn StateRobert Collins
Review: Flow Due to Self-Motion
Rotation Translation
Flow:
Rotation component Translation component
rotation component does notdepend on scene structure.
translational component does varyas scene Z-value varies. That is, itexhibits motion parallax.
CSE486, Penn StateRobert Collins
Special Case: Pure Translation
To better understand what flow fields look like, let’sjust consider the case of pure translational motion.
Then, the flow is formed by projection of parallelvelocity vectors in the scene
the 3D scenethe 2D image
parallel velocity vectorsall the same length
?
CSE486, Penn StateRobert Collins
Special Case I: Pure Translation
Assume Assume TTzz ≠≠ 0 0
Define:Define:
Camps, PSU
CSE486, Penn StateRobert Collins
Special Case I: Pure Translation
What if What if TTzz == 0 ? 0 ?
All motion field vectors are parallel to each other andAll motion field vectors are parallel to each other andinversely proportional to depth !inversely proportional to depth !
Camps, PSUTIE IN WITH SIMPLE STEREO!
CSE486, Penn StateRobert Collins
Special Case I: Pure Translation
The motion field in this case is RADIAL:The motion field in this case is RADIAL:••It consists of vectors passing through pIt consists of vectors passing through poo = ( = (xxoo,y,yoo))••If:If:
•• TTzz > 0, > 0, (camera moving towards object)(camera moving towards object)
•• the vectors point away from p the vectors point away from poo
••ppoo is the is the POINT OF EXPANSIONPOINT OF EXPANSION•• TTzz < 0, < 0, (camera moving away from object)(camera moving away from object)
••the vectors point towards pthe vectors point towards poo
••ppoo is the is the POINT OF CONTRACTIONPOINT OF CONTRACTION
TTzz > 0 > 0 TTzz < 0 < 0
Camps, PSU
CSE486, Penn StateRobert Collins Pure Translation:
Properties of the MF
• If Tz≠ 0 the MF is RADIAL with all vectorspointing towards (or away from) a singlepoint po. If Tz = 0 the MF is PARALLEL.
• The length of the MF vectors is inverselyproportional to depth Z. If Tz ≠ 0 it is alsodirectly proportional to the distancebetween p and po.
Camps, PSU
CSE486, Penn StateRobert Collins Pure Translation:
Properties of the MF
• po is the vanishing point of the direction oftranslation.
• po is the intersection of the ray parallel tothe translation vector and the image plane.
Camps, PSU
CSE486, Penn StateRobert Collins
Motion Field vs Optic Flow
Motion Field: projection of 3D relative velocity vectors onto the 2D image plane.
Optic Flow: observed 2D displacements of brightness patterns in the image.
Motion field is what we want to know.Optic flow is what we can estimate.
CSE486, Penn StateRobert Collins
Optic Flow ≠ Motion Field
Consider a moving light source:
MF = 0 since the points on the scene are not movingOF ≠ 0 since there is a moving pattern in the images
CSE486, Penn StateRobert Collins
Approximating MF with OF
Nevertheless, we will estimate OF (since MF cannotreally be observed!).
To avoid apparent flow due to changingillumination, assume that the apparent brightnessof moving objects remains constant.
CSE486, Penn StateRobert Collins
Brightness Constancy Equationconsider a scene point moving through an image sequence
I(x,y,1) I(x,y,2) I(x,y,k)
(x(1),y(1))(x(2),y(2))
(x(k),y(k))
claim: its brightness/color will remain the same (that’spartly how we can recognize that it IS the same point)
I
CSE486, Penn StateRobert Collins
Brightness Constancy Equation
Camps, PSU
Take derivative of both sides Take derivative of both sides wrt wrt time:time:
I
I
I I I
(using chain rule)
CSE486, Penn StateRobert Collins
Brightness Constancy Equation
I I I
(derivative across frames. Also known,(derivative across frames. Also known, e.g. frame difference) e.g. frame difference)
I
(spatial gradient; we can compute this!)(spatial gradient; we can compute this!)I I,
(optical flow, what we want to find)(optical flow, what we want to find), = (u, v)
CSE486, Penn StateRobert Collins
Brightness Constancy Equation
Becomes:Becomes:
Optical Flow is CONSTRAINED to be on a line !Optical Flow is CONSTRAINED to be on a line ! (equation has for a (equation has for a u + b + b vv + c = 0) + c = 0)
Camps, PSU
I I I
I I
What is the practical implication of this?
CSE486, Penn StateRobert Collins
Brightness Constancy Equation
Optical Flow is CONSTRAINED to be on a line !Optical Flow is CONSTRAINED to be on a line ! (equation has for a (equation has for a u + b + b vv + c = 0) + c = 0)
What is the practical implication of this?
Known (spatial andtemporal gradients)
Unknowns (componentsof flow vector)
CSE486, Penn StateRobert Collins
Implications
• Q: how many unknowns and equations per pixel?
• Intuitively, this constraint means that
– The component of the flow in the gradientdirection is determined (called Normal Flow)
– The component of the flow parallel to an edge isunknown
Seitz, UW
CSE486, Penn StateRobert Collins
The Aperture Problem
Camps, PSU
CSE486, Penn StateRobert Collins
The Aperture Problem
Camps, PSU
CSE486, Penn StateRobert Collins
The Aperture Problem
Camps, PSU
CSE486, Penn StateRobert Collins
The Aperture Problem
Camps, PSU
CSE486, Penn StateRobert Collins
The Aperture Problem
The Image Brightness Constancy Assumption onlyThe Image Brightness Constancy Assumption onlyprovides the OF component in the direction of theprovides the OF component in the direction of thespatial image gradientspatial image gradient
Camps, PSU
CSE486, Penn StateRobert Collins
Aperature Problem
• Another example is the barber-pole illusion.
Consider a pointTrue motionis this way
Apparent motionis this direction
CSE486, Penn StateRobert Collins
Optical Flow ≠ Motion Flow
• The aperature problem reminds us once again thatoptical flow is not the same thing as motion flow.– near an edge, we can only observe (measure) the
component of flow perpendicular to the edge– cannot measure the component of flow parallel to the edge.– another case of non-observability of optical flow is in
areas of constant intensity. No flow is observed.
Camps, PSU
CSE486, Penn StateRobert Collins
Computing Optical Flow
• Algorithms for computing OF are of two types:– Differential Techniques
• Based on spatial and temporal variations of the imagebrightness at all pixels.
• Used to compute DENSE flow.
– Matching Techniques• Similar to stereo feature matching, compute disparities.
• Used to compute SPARSE flow.
Camps, PSU
CSE486, Penn StateRobert Collins
A Differential Technique:Constant Flow, aka Lucas-Kanade
CSE486, Penn StateRobert Collins
Lucas-Kanade Motivation
• Q: how many unknowns and equations per pixel?
• We need two or more pixels to solve.
Seitz, UW
• Due to aperature problem, we would liketo include pixels with different gradientdirections.
CSE486, Penn StateRobert Collins
can infer correct solutionusing two or more directions
Solving the Aperature Problem
• Using gradients with two or more directions
aperature problem withsingle gradient direction
CSE486, Penn StateRobert Collins
Solving the aperture problem
• How to get more equations for a pixel?– Basic idea: impose additional constraints
• most common is to assume that the flow field is smooth locally
• e.g. pretend the pixel’s neighbors have same displacement (u,v)– If we use a 5x5 window, that gives us 25 equations per pixel!
Seitz, UW
recall:
CSE486, Penn StateRobert Collins
Lucas-Kanade flow
• We have more equations than unknowns: solve least squares problem.This is given by:
– Summations over all pixels in the KxK window
Seitz, UW
CSE486, Penn StateRobert Collins
Conditions for solvability
– Optimal (u, v) satisfies Lucas-Kanade equation
When is This Solvable?• ATA should be invertible• ATA should not be too small due to noise
– eigenvalues λ1 and λ2 of ATA should not be too small• ATA should be well-conditioned
– λ1/ λ2 should not be too large (λ1 = larger eigenvalue)
Seitz, UW
CSE486, Penn StateRobert Collins
Does ATA seem familiar?
Look at the matrix:
Harris Corner Detector Matrix!
CSE486, Penn StateRobert Collins
Review: Harris Corner DetectorIn Lecture 10 we derived the Harris corner detector by considering SSD of shifted intensity patches…
CSE486, Penn StateRobert Collins
Tie in Harris with Motion Analysis
Was spatial shift in singleframe. Now is displacementacross two frames in time.
Current frame
Previous frame
CSE486, Penn StateRobert Collins
Tie in with Harris
– large gradients, all the same– large λ1, small λ2
Seitz, UWWill have aperature problem
Edge
CSE486, Penn StateRobert Collins
Tie in with Harris
– gradients have small magnitude– small λ1, small λ2
Seitz, UW
Ill-conditioned matrix. Likelyto compute garbage answer.
Low Texture Region
CSE486, Penn StateRobert Collins
Tie in with Harris
– gradients are different, large magnitudes– large λ1, large λ2
Seitz, UW
Good corner feature. Also good place to estimate flow!
Corner
CSE486, Penn StateRobert Collins
Implications
• Corners are when λ1, λ2 are big; this is alsowhen Lucas-Kanade works best.
• Corners are regions with two differentdirections of gradient (at least).
• Aperture problem disappears at corners.• Corners are good places to compute flow!
CSE486, Penn StateRobert Collins
Feature-based Techniques
Camps, PSU
CSE486, Penn StateRobert Collins
Feature Matching for Sparse Flow
I(x,y,t) I(x,y,t+1)
General idea: Find Corners in one image (because these are good areas to estimate flow) Search for Corresponding intensity patches in second image.
CSE486, Penn StateRobert Collins
KLT Algorithm
Public-domain code by Stan Birchfield.Available from
http://www.ces.clemson.edu/~stb/klt/
Tracking corner features through 2 or more frames
CSE486, Penn StateRobert Collins
KLT Algorithm
1. Find corners in first image2. Extract intensity patch around each corner3. Use Lucas-Kanade algorithm to estimate
constant displacement of pixels in patch
1. Iteration and multi-resolution to handle large motions 2. Subpixel displacement estimates (bilinear interp warp)3. Can track feature through a whole sequence of frames4. Ability to add new features as old features get “lost”
Niceties
CSE486, Penn StateRobert Collins
Correlation-Based Matching
• Another approach is to match intensitypatches using correlation or NCC.– We talked about this for stereo as well:
CSE486, Penn StateRobert Collins
Correlation-based Matching
1. Find corners in first image2. Extract intensity patch around each corner3. Use NCC to compute match scores within
the search window in second image 4. Identify highest score (best match)
CSE486, Penn StateRobert Collins
Important Note on Efficiency
Given image patch in one imageWe don’t want to search everywherein the second image for a match.
?
CSE486, Penn StateRobert Collins
Important Note on Efficiency
Given image patch in one imageWe don’t want to search everywherein the second image for a match.
With stereo, we had an epipolar line constraint.
Search region
CSE486, Penn StateRobert Collins
Important Note on Efficiency
Given image patch in one imageWe don’t want to search everywherein the second image for a match.
We don’t know the relative R,T here, so noepipolar constraint.But… motion is known to be “small”, so canstill bound the search region.
Search region
CSE486, Penn StateRobert Collins
Note on using Normalized Correlation
If we use normalized correlation to match featurepatches, we can relax the constant brightness assumption!
We thus remove some potential error sources (changes in illumination or camera gain)
CSE486, Penn StateRobert Collins
Another Correlation-based Algorithm
Due to David Nister, “Visual Odometry”, CVPR 2004
Observation: corners in one image tend to stay corners over short periods of time.
Therefore, we only need to match corners to corners.
Review:
CSE486, Penn StateRobert Collins
Nister’s Algorithm
1. Find corners in first image2. Extract intensity patch around each corner3. Find corners in second image4. Extract intensity patch around each of them5. Find matching pairs (c1,c2) such that• C1 is a corner patch from image 1• C2 is a corner patch from image 2• C2 is the best match for C1• C1 is the best match for C2
CSE486, Penn StateRobert Collins
Nister’s Algorithm
1. Find corners in first image2. Extract intensity patch around each corner3. Find corners in second image4. Extract intensity patch around each of them5. Find matching pairs (c1,c2) such that• C1 is a corner patch from image 1• C2 is a corner patch from image 2• C2 is the best match for C1• C1 is the best match for C2
Question: Why do this too? Answer: Approx solution to the linear assignment problem -- you get better matches.
CSE486, Penn StateRobert Collins
Linear Assignment Problem
Aka the “Marriage Problem”
Simplest form:1) given k boys and k girls2) ask each boy to rank the girls in order of desire3) ask each girl to also rank order the boys4) The marriage problem determines the pairing of boys and girls to maximize sum of overall pairwise rankings.
Note: in general you may not get your most desireablespouse, but on average you rarely get the least.
CSE486, Penn StateRobert Collins
Linear Assignment Problem
The optimal solution to the LAP is too computationallyintensive for real-time feature matching/tracking.
Therefore, we use a heuristic solution where featurescan pair up only if each is the best match for the other(i.e. boy-girl pairs that each listed each other as #1)
This throws away a lot of potential point matches, butthe ones that are left are usually pretty good.