Horn–Schunck: global smoothness, and how to evaluate a flow field

Image analysis

About this lecture

Lucas–Kanade answers only where a window has texture. Horn and Schunck (1981) ask for a flow field that fits the constraints and is smooth everywhere.

  • The flow as a regularised energy: data + λ·smoothness, the pattern of the deconvolution day (regularisation).
  • What λ does; filling-in of flat regions.
  • The update: average the neighbours, step towards the constraint line.
  • Sharp motion boundaries and robust penalties.
  • Evaluating a flow field: endpoint error, angular error, and the warping residual when there is no ground truth.

Slides titled The math give the formulas and proofs; the ideas are complete without them.

Recall: misfit + λ·penalty

From the regularisation unit: when the data alone do not determine the answer, minimise

misfit to the data + λ · penalty on implausible answers.

  • Deconvolution: the unknown was the sharp image, the penalty its roughness.
  • Here: the unknown is the flow field (u, v); the misfit is how badly each pixel’s constraint is violated; the penalty is how much neighbouring vectors differ.
  • Graph cuts (segmentation energy) had the same structure with labels instead of vectors.

Horn–Schunck: the idea

Every pixel pays for two things:

  • data: its distance from its own constraint line (squared);
  • smoothness: λ times how much its vector differs from its neighbours’ (squared).

λ small: trust the constraints (noisy; flat regions undetermined). λ large: a smooth field that blurs across motion boundaries.

The result is dense: a vector at every pixel, including flat regions. Lucas–Kanade gives vectors with holes and a confidence.

A flat disc inside a textured ring, moved 1.5 pixels. Lucas-Kanade leaves the flat disc and the flat surroundings grey (no confidence); Horn-Schunck with lambda 100 gives one uniform colour everywhere, filled in.

Filling-in

In a flat region there are no constraints, but smoothness pulls the flow in from the textured pixels around it. Over the iterations the flow spreads inwards like heat (it is a diffusion: the heat equation): about a pixel per iteration, so a large flat region needs hundreds of iterations.

The update in words

Each iteration, every pixel

  1. takes the average of its neighbours’ vectors,
  2. moves that average towards its own constraint line, by a step that is large where its gradient is strong and small where the gradient is weak or λ is large.

A pixel already on its line keeps the average. A pixel in a flat region just takes the average: that is the filling-in.

By hand: (I_x, I_y, I_t) = (2, 0, -4) (line u = 2), neighbour average (0, 0), λ = 1: the new vector is (1, 0), half way to the line. With λ = 0 it jumps onto the line: (2, 0).

Velocity space with the constraint line u = 2 and the neighbour average at the origin. The new vector lies on the way from the average to the line: (2, 0) for lambda 0, (1, 0) for lambda 1, (0.5, 0) for lambda 3.

Horn–Schunck as pseudocode

u = v = 0 at every pixel
repeat N sweeps:
    for every pixel:
        ū, v̄ = average of the 4 neighbours (previous sweep)
        r = (Ix·ū + Iy·v̄ + It) / (4λ + Ix² + Iy²)    # how far off its line
        u_new = ū − Ix·r;   v_new = v̄ − Iy·r
    u, v = u_new, v_new
  • Where I_x = I_y = 0 (flat), the step -I_x r, -I_y r is 0: the pixel just takes the average. That is the filling-in.
  • Each sweep costs a few operations per pixel, but flat regions need many sweeps.

The math: Horn–Schunck

Discrete energy over pixels p and 4-neighbour pairs (p, q): E(u, v) = \sum_p (I_x u_p + I_y v_p + I_t)^2 + \lambda \sum_{(p, q)} \big[(u_p - u_q)^2 + (v_p - v_q)^2\big]. With the neighbour averages \bar u_p, \bar v_p, setting \partial E/\partial u_p = \partial E/\partial v_p = 0 gives (I_x^2 + 4\lambda)u + I_xI_y v = 4\lambda\bar u - I_xI_t and its twin, solved by u = \bar u - I_x\,\frac{I_x\bar u + I_y\bar v + I_t}{4\lambda + I_x^2 + I_y^2},\qquad v = \bar v - I_y\,\frac{I_x\bar u + I_y\bar v + I_t}{4\lambda + I_x^2 + I_y^2}.

  • Applied to all pixels repeatedly: an iterative solver of a sparse linear system. E is a sum of squares of linear functions: convex, one minimum.
  • Updating the pixels in checkerboard order (first the “black”, then the “white” ones) makes each half-step an exact minimisation: E never increases (the demo does this).
  • Continuous form (Euler–Lagrange): I_x(I_xu + I_yv + I_t) - \lambda\nabla^2 u = 0, and the same for v.

Try it: Horn–Schunck

Sharp motion boundaries

The squared penalty hates jumps: a jump of 2 costs 4 times a jump of 1. So it blurs the border between a moving cell and the still background.

  • Robust penalties (total variation, Charbonnier): pay for the size of a jump, not its square; one sharp jump becomes cheaper than a smeared ramp. Pointer: the “total variation” row of the regularisation table, and MRF priors on the Ising day.
  • A robust data term ignores pixels where brightness constancy fails (occlusions, bleaching).
  • Modern variational flow = robust data + robust smoothness + coarse-to-fine + warping (the pyramid of the last unit works for Horn–Schunck too).

Lucas–Kanade or Horn–Schunck?

Lucas–Kanade Horn–Schunck
assumption constant flow in a window smooth flow everywhere
output vectors where there is texture, plus a confidence a dense field
knob window size ρ λ
computation closed form per pixel many iterations
flat regions no answer (honest) filled in from the surroundings (plausible, unchecked)
large motion pyramid + warping pyramid + warping

Learned flow networks (modern deep learning day) are trained on synthetic sequences and evaluated in exactly the way of the next slides.

Evaluating a flow field: with ground truth

Make test data whose motion is known: warp a real image by a known flow (as in the demos), or simulate a sequence.

  • Endpoint error (EPE): the length of (estimate − truth), per pixel; its mean over the image; its map. Errors concentrate at motion boundaries and in flat regions.
  • Angular error (AE): the angle between (u, v, 1) and (u_{gt}, v_{gt}, 1), the older measure. It punishes errors at slow pixels much more: estimate (0.1, 0) against truth (0.6, 0) has EPE 0.5 and AE 25°; (2, 1) against (2.5, 1) also has EPE 0.5 but AE only 5.8°. EPE is preferred.
  • Choose λ (or ρ) by the EPE on synthetic data that resembles your real data.

Top: the estimate (0.1, 0, 1) and the truth (0.6, 0, 1) drawn as space-time arrows, 0.5 pixels apart at their tips and 25 degrees apart in angle. Bottom: for the same endpoint error of 0.5 the angular error falls as the true speed grows; (2, 1) against (2.5, 1) gives 5.8 degrees.

The math: error measures

\mathrm{EPE} = \sqrt{(u - u_{gt})^2 + (v - v_{gt})^2},\qquad \mathrm{AE} = \arccos\frac{u\,u_{gt} + v\,v_{gt} + 1}{\sqrt{u^2 + v^2 + 1}\,\sqrt{u_{gt}^2 + v_{gt}^2 + 1}} .

  • The “+1” treats each flow as a direction in space–time, (u, v, 1): the AE is the angle between the two space–time directions.
  • For slow motions the space–time vectors are nearly (0, 0, 1), so a small absolute error is a large angle; for fast motions the same absolute error is a small angle.
  • Both are 0 iff the estimate equals the truth; EPE is in pixels and easy to interpret.

Without ground truth: the warping residual

On real data there is no truth. Warp frame 2 back by the estimated flow and subtract frame 1: the warping residual.

  • A correct flow (and brightness constancy) leaves only noise.
  • A small residual is necessary, not sufficient: in a flat region, a wrong flow leaves no residual (flat moved anywhere is still flat). The aperture problem hides errors in the residual too.
  • Large residuals point to failures: motion boundaries, occlusions, bleaching.
  • Recall the discrepancy idea of the regularisation unit: a residual much smaller than the noise means overfitting.
Ring scene after 60 Horn-Schunck sweeps: the flow is still white (zero) in the flat centre; the endpoint error is large there; the warping residual is small there (mean absolute residual 2.0 in the centre against 3.0 overall).

Try it: evaluating

Summary

  • Horn–Schunck: minimise data misfit + λ·(differences between neighbouring vectors): the regularisation pattern with a vector field as the unknown.
  • Update: average the neighbours, step towards the constraint line; flat regions are filled in from their surroundings, slowly.
  • λ: small = noisy, large = smeared motion boundaries; robust penalties keep sharp boundaries.
  • LK: local, sparse, with a confidence. HS: global, dense. Both need small motion or a pyramid.
  • Evaluate with endpoint error against known motion; without truth, the warping residual finds failures but cannot prove correctness.