Optical flow: where did each pixel go?
Optical flow gives every pixel a displacement between two frames. Learn how it is scored (endpoint error), the assumption underneath it, and three learned estimators: FlowNet, PWC-Net and RAFT.
What runs in CodeSplash
You will be able to
- Define optical flow and the brightness-constancy assumption behind it
- Compute endpoint error and say why it isn't pixel error
- Explain warping, cost volumes and coarse-to-fine search in PWC-Net
- Describe RAFT's all-pairs correlation and repeated updates, and what more iterations don't guarantee
A displacement for every pixel
ReadOptical flowOptical flowFor each pixel, how far it moved between two frames, as a horizontal and a vertical shift in pixels. assigns each pixel of one frame a shift in pixels: where that point appears in the next frame. Most estimators rest on brightness constancyBrightness constancyThe assumption that a point keeps its brightness as it moves, so matching brightness finds the motion., the idea that a point keeps its brightness as it moves:
Flow is movement in the image, not speed in the world. A far car and a near bicycle can have the same flow. Shiny surfaces, shadows, occlusion and textureless walls all break the assumption.
Scoring a flow field
ReadThe standard score is endpoint errorEndpoint errorThe straight-line distance between a predicted and a true flow vector, in pixels, averaged over pixels.: the straight-line distance between the predicted and the true shift at each pixel, averaged:
In the reference's example, three points truly move two pixels right. One prediction is exact; one moves only one pixel; one adds a pixel of vertical motion. The per-point errors are 0, 1 and 1 pixels, a mean of 0.667. That is a distance in pixels, not the squared difference of pixel brightness.
FlowNet: learn the mapping
ReadFlowNet feeds two frames to a convolutional encoder–decoder and trains it to output the flow field directly, with endpoint error at several output scales as the loss:
True flow is almost never measured in real video, so training sets are mostly synthetic: rendered scenes where every shift is known. That makes domain shift the first question for any flow model on your footage.
Warp, compare, refine
ReadPWC-Net works coarse to fineCoarse-to-fine estimationEstimate motion on a small copy of the image, then upsample it and refine it at each larger scale.. At the smallest scale it estimates rough flow; at each larger scale it upsamples that flow, warpsWarpingMove the pixels of one frame along a flow field to predict another frame; the leftover difference shows the error. the second frame's features by it, and builds a small cost volumeCost volumeA table of how similar each feature in one frame is to features at nearby, or all, positions in the next frame.: how well each feature matches features a few pixels around the warped spot.
In the reference's toy, the coarse flow says two pixels; the local match scores for offsets of minus one, zero and plus one are 0.0, 0.4 and 1.0, so the refined shift is 3.
When the first guess is wrong
PredictPredict first
At the coarsest level, PWC-Net's guess is off by much more than the small search window used at the next level. What happens?
Reveal
The error stays. Each level only searches a few pixels around the warped guess. If the true match is outside that window, no level can find it. Large, fast motion is where coarse-to-fine methods fail, so test large displacements on purpose.
RAFT: all pairs, many small steps
ReadRAFT compares every feature in frame one with every feature in frame two, , and pools that table at several scales. A recurrent unit then updates one full-resolution flow field again and again, each time looking up the correlations around the current estimate:
The reference's toy replaces the learned update with a fixed half-step toward the best match. After three steps the flow is 0.875, 0.875 and −1.75: seven-eighths of the way. More iterations converge to the model's answer, not to the truth.
Where the errors are
ReadAn average endpoint error hides where the mistakes sit. Report it separately for:
- occluded and visible pixels: points that disappear have no true match;
- small and large motions;
- the resolution you actually run at.
A clip where the whole frame shifts together is easy. Objects moving independently, rotation, transparency and lighting changes are the real test.
DExplorable · Optical flow: Lucas–Kanade, warping and endpoint error
How can a computer tell how far each part of an image moved between two frames?
With this picture and motion, what will Lucas–Kanade find?
Picture
Many small blobs (rich texture), diagonal stripes, or two broad smooth blobs.
How far the picture moves to the right between the frames.
How far the picture moves down between the frames.
Turns the picture about its center, so the motion differs from place to place.
Scales the picture about its center: things move outward when it grows.
Lucas–Kanade assumes one motion inside a square window this many pixels around each point.
Each step warps the second frame by the current estimate and solves for the remaining motion.
Random noise added to the second frame.
Mean endpoint error 0.14 px. 4% of the windows see the pattern change in one direction only.
Commit your prediction above to see the result
Make your prediction to see the result.
What runs here
Read| Entry | In CodeSplash |
|---|---|
| VID029 · FlowNet | Runs as a notebook (the reference program; no method) |
| VID030 · PWC-Net | Explained here |
| VID031 · RAFT | Needs a data type CodeSplash doesn't load yet (video) |
Check: optical flow
CheckpointCheck yourself
What does an optical-flow field give you?
Show the answer
Answer: b
Flow is displacement in the image plane. Turning it into real-world speed needs depth and camera geometry.
Check yourself
A flow model's endpoint error is reported as a mean over pixels. What is it?
Show the answer
Answer: a
EPE compares displacement vectors. A warped-brightness error is a different, photometric quantity.
Check yourself
Why is domain shift a central worry for supervised flow models like FlowNet?
Show the answer
Answer: b
Rendered training data has perfect labels and a different look from your footage. Test on data like yours.
Check yourself
At each pyramid level, what does PWC-Net compare?
Show the answer
Answer: b
Warping by the upsampled flow, then a local cost volume, keeps each level's search small.
Check yourself
Which test is most likely to expose a coarse-to-fine flow model's weakness?
Show the answer
Answer: b
A wrong coarse guess can't be repaired by a small local search. Report errors by motion size.
Check yourself
Running RAFT's update for more iterations makes its flow converge. Does that make it physically correct?
Show the answer
Answer: b
Iteration refines the model's answer. Ambiguous regions stay ambiguous; report iterations, memory and errors by region.
Check yourself
What does RAFT's all-pairs correlation cost as images grow?
Show the answer
Answer: a
Every feature is compared with every other, so large images need pooling, cropping or a lot of memory.
Check yourself
A cloud passes over the scene between two frames. Which assumption does that break?
Show the answer
Answer: b
Brightness-based matching can mistake a lighting change for motion, or miss motion hidden by it.
Recap
Recap- Optical flow is per-pixel displacement in the image, resting on brightness constancy.
- Endpoint error is a distance between flow vectors; report it by region and motion size.
- FlowNet learns the mapping directly, mostly from synthetic data.
- PWC-Net warps and searches locally, coarse to fine; RAFT correlates all pairs and refines many times.
Concepts in this lesson