- build intuition for motion in image coordinates,
- recover motion with a readable patch-matching baseline,
- estimate a sparse motion field on synthetic data with known ground truth,
- measure accuracy with endpoint error and match ratios,
- study how patch size, search radius, and noise change the results,
- and inspect failure modes such as repetitive texture and motion that is too large.
The book’s figures
The book introduces the task with two frames of a street in Palma (Figure 46.3): each region of the first frame has to be assigned a displacement into the second. The code in this section solves the same task on synthetic frames with known ground truth. Related figures in the book:- the matching-cost map, whose minimum SSD location becomes the estimated displacement, the counterpart of the patch-matching diagnostic below;
- the patch-size comparison: small patches are noisy, large patches blur motion boundaries, the same tradeoff the parameter sweep measures;
- the perception demonstrations: a still photograph that implies motion, a static pattern that looks like it moves, and two space-time illusions (first, second);
- the learned alternatives in chapter 49 of the book: a network that maps two frames directly to optical flow, and one that keeps features, a cost volume, and cost aggregation. The endpoint error that this section reports is defined there as well.
Intuition
Between two video frames, a moving object often keeps a similar local appearance. So a small patch around a point in Frame 1 may reappear a few pixels away in Frame 2. This section uses the image-coordinate convention common in vision:- increases to the right,
- increases downward,
- a motion vector is written as .
Synthetic example setup
Start with clean synthetic frames, because the true motion is known exactly. That lets you debug the estimator before dealing with real video. The scene uses a few textured geometric shapes so patch matching has enough visual structure to lock onto. The helper below builds a frame pair with a known integer translation. The motion-intuition figure comes later, once the patch matcher has also produced the estimated target.Patch matching by local search
The baseline method is deliberately simple:- extract an odd-sized patch around a point in Frame 1,
- search a square window around the same location in Frame 2,
- score each candidate with SSD (sum of squared differences),
- keep the displacement with the lowest score.
Single-point motion estimation
First, track one carefully chosen point so every part of the process is visible. Read the top row from left to right: the source patch in Frame 1, the searched region in Frame 2, and the SSD surface over candidate displacements. Then compare the bottom-row patches: a low-error match means the winning displacement is also visually plausible.

Sparse motion field estimation
One point builds intuition, but a motion field needs many arrows. You sample textured points on a grid, run the same local matcher at each one, and compute metrics over all valid points. To keep the figure readable, it shows only a subset of arrows, and exact estimates and mismatches are styled differently so the coherent global translation stands out.
Validation metrics
Because the synthetic translation is known, you can score the estimates directly.- Endpoint error (EPE) is the Euclidean distance between the estimated vector and the true vector.
- Exact match ratio is the fraction of estimates that recover the exact integer motion.
- Correct-within-1-pixel ratio is a softer measure that counts near misses as acceptable.

Parameter sweeps
Three knobs matter immediately:- Patch size: larger patches are often more stable, but they blur away local detail.
- Search radius: larger windows can recover larger motion, but they cost more and may invite distractors.
- Noise level: noisy images reduce the reliability of appearance matching.

Failure cases
A basic local matcher has clear blind spots. Two of the most important:- Repetitive texture: many candidate patches look equally good.
- Motion outside the search radius: the correct answer is never even evaluated.


Limitations
Patch matching works well when:- motion is moderate,
- the search window covers the true displacement,
- local texture is distinctive,
- and noise is not too strong.

