Patch-based vs regularized flow

Optical flow gives every pixel its own motion vector. One brightness equation per pixel cannot determine two unknowns, so something has to be added: either the assumption that a whole window moves together, or a smoothness term that ties neighboring vectors to each other. Compare both on a scene with textured, flat, striped and repetitive regions, and click a pixel to see why its window succeeds or fails.

Frame I0I_0 click to select a pixel and its window
Frame I1I_1 cards in I0I_0
Patch-based flow Lucas–Kanade on the window around every pixel no estimate
Regularized flow smoothness term α2∥∇ui∥2\alpha^2 \|\nabla \mathbf{u}_i\|^2,
True flow u∗\mathbf{u}^* color = direction, saturation = length (full at px)
color key
Window around true u∗\mathbf{u}^* (×) patch-based regularized
I0I_0 in the window
error E(u)E(\mathbf{u}) over ±4\pm 4 px, black = smallest

One equation, two unknowns

Optical flow looks for a vector ui\mathbf{u}_i at every pixel such that I1(xi+ui)≈I0(xi)I_1(\mathbf{x}_i + \mathbf{u}_i) \approx I_0(\mathbf{x}_i). Summing the squared differences over all pixels gives

ESSD-OF({ui})=∑i[I1(xi+ui)−I0(xi)]2E_{\text{SSD-OF}}(\{\mathbf{u}_i\}) = \sum_i \left[ I_1(\mathbf{x}_i + \mathbf{u}_i) - I_0(\mathbf{x}_i) \right]^2

Each ui\mathbf{u}_i has two components, so nn pixels have 2n2n unknowns, but only nn equations. Minimizing this alone is hopeless: almost any pixel of I1I_1 with the same brightness is a perfect match. Two ways out are compared here.

Patch-based flow

Assume that all pixels in a small window move by the same u\mathbf{u}, and estimate it with Lucas–Kanade: linearize, solve A⊤A Δu=A⊤bA^\top A\, \Delta\mathbf{u} = A^\top \mathbf{b} and repeat. The window around each pixel gives that pixel's vector. Whether this works depends on A⊤A=∑i∇I1∇I1⊤A^\top A = \sum_i \nabla I_1 \nabla I_1^\top, the same matrix as in the Harris detector:

Here, eigen-directions with λ<τ\lambda < \tau are left out of the solution: an edge window gives the normal flow, and a flat window gives no vector.

Regularized flow

Instead of fixing the motion per window, add a term that penalizes differences between neighboring vectors:

E({ui})=∑i[I1(xi+ui)−I0(xi)]2+α2∑i∥∇ui∥2E(\{\mathbf{u}_i\}) = \sum_i \left[ I_1(\mathbf{x}_i + \mathbf{u}_i) - I_0(\mathbf{x}_i) \right]^2 + \alpha^2 \sum_i \|\nabla \mathbf{u}_i\|^2

∥∇ui∥2\|\nabla \mathbf{u}_i\|^2 is the sum of the squared differences of ui\mathbf{u}_i to its right and lower neighbors. Now the problem is well posed: where the image has texture, the data term decides; where it has none, the smoothness term fills in the motion from the surroundings. Along an edge, the data term fixes the normal component and the neighbors supply the other one.

The data term is linearized as in Lucas–Kanade, around the current flow ui0\mathbf{u}^0_i: I1(xi+ui)−I0(xi)≈Ixui+Iyvi+ciI_1(\mathbf{x}_i + \mathbf{u}_i) - I_0(\mathbf{x}_i) \approx I_x u_i + I_y v_i + c_i, with the gradient (Ix,Iy)(I_x, I_y) of I1I_1 at xi+ui0\mathbf{x}_i + \mathbf{u}^0_i and ci=I1(xi+ui0)−I0(xi)−Ixui0−Iyvi0c_i = I_1(\mathbf{x}_i + \mathbf{u}^0_i) - I_0(\mathbf{x}_i) - I_x u^0_i - I_y v^0_i. Setting the derivatives with respect to uiu_i and viv_i to zero, with the mean uˉi\bar{\mathbf{u}}_i of the nn neighbors held fixed, gives

ui=uˉi−IxIxuˉi+Iyvˉi+ciα2n+Ix2+Iy2,vi=vˉi−IyIxuˉi+Iyvˉi+ciα2n+Ix2+Iy2u_i = \bar u_i - I_x \frac{I_x \bar u_i + I_y \bar v_i + c_i}{\alpha^2 n + I_x^2 + I_y^2}, \qquad v_i = \bar v_i - I_y \frac{I_x \bar u_i + I_y \bar v_i + c_i}{\alpha^2 n + I_x^2 + I_y^2}

Each vector is the average of its neighbors, corrected along the gradient by how badly that average fits the brightness. Repeating this for all pixels spreads information across the image one pixel per sweep, so filling a large flat region takes many iterations. Every 20 sweeps, the image is linearized again at the current flow.

The weight α\alpha sets the balance. A small α\alpha follows the data and keeps its noise and ambiguities; a large α\alpha gives smooth flow, but also smears the sharp change of motion at an object's silhouette into the background. The true flow, with its sharp boundaries, usually has a higher energy than the smooth result: the quadratic smoothness term prefers to blur boundaries.

Try this