Lably
Skip to content

Optical flow

Pattern of motion in a visual scene due to relative motion of the observer

  • 11 min read
  • 4 chapters

Related on Lably

Through Motion, Euclid and World War II

The concept of optic flow has roots as far back as Euclid's Optics, but its modern formulation arose from Second World War research into pilot vision during landing. Several researchers arrived at the idea independently; James J. Gibson gave it its most influential treatment, publishing his theory in 1947 and created the term "optic flow" in 1950.

The term optical flow is also used by roboticists, encompassing related techniques from image processing and control of navigation including motion detection, object segmentation, time-to-contact information, focus of expansion calculations, luminance, motion compensated encoding, and stereo disparity measurement.

Estimation

Optical flow can be estimated in a number of ways. Broadly, optical flow estimation approaches can be divided into machine learning based models (sometimes called data-driven models), classical models (sometimes called knowledge-driven models) which do not use machine learning and hybrid models which use aspects of both learning based models and classical models.

Classical models

Many classical models use the intuitive assumption of brightness constancy; that even if a point moves between frames, its brightness stays constant. To formalise this intuitive assumption, consider two consecutive frames from a video sequence, with intensity I(x,y,t), where (x,y) refer to pixel coordinates and t refers to time. In this case, the brightness constancy constraint is

I(x,y,t)−I(x+u,y+v,t+1)=0,

where w:=(u,v) is the displacement vector between a point in the first frame and the corresponding point in the second frame. By itself, the brightness constancy constraint cannot be solved for u and v at each pixel, since there is only one equation and two unknowns. This is known as the aperture problem. Therefore, additional constraints must be imposed to estimate the flow field.

Regularized models

Perhaps the most natural approach to addressing the aperture problem is to apply a smoothness constraint or a regularization constraint to the flow field. One can combine both of these constraints to formulate estimating optical flow as an optimization problem, where the goal is to minimize the cost function of the form,

E=∬ΩΨ(I(x+u,y+v,t+1)−I(x,y,t))+αΨ(|∇u|)+αΨ(|∇v|)dxdy,

where Ω is the extent of the images I(x,y), ∇ is the gradient operator, α is a constant, and Ψ() is a loss function.

This optimisation problem is difficult to solve owing to its non-linearity. To address this issue, one can use a variational approach and linearise the brightness constancy constraint using a first order Taylor series approximation. Specifically, the brightness constancy constraint is approximated as,

∂I∂xu+∂I∂yv+∂I∂t=0.

For convenience, the derivatives of the image, ∂I∂x, ∂I∂y and ∂I∂t are often condensed to become Ix, Iy and It. Doing so, allows one to rewrite the linearised brightness constancy constraint as,

Ixu+Iyv+It=0.

The optimization problem can now be rewritten as

E=∬ΩΨ(Ixu+Iyv+It)+αΨ(|∇u|)+αΨ(|∇v|)dxdy.

For the choice of Ψ(x)=x2, this method is the same as the Horn-Schunck method. Of course, other choices of cost function have been used such as Ψ(x)=x2+ϵ2, which is a differentiable variant of the L1 norm.

To solve the aforementioned optimization problem, one can use the Euler-Lagrange equations to provide a system of partial differential equations for each point in I(x,y,t). In the simplest case of using Ψ(x)=x2, these equations are,

Ix(Ixu+Iyv+It)−αΔu=0,
Iy(Ixu+Iyv+It)−αΔv=0,

where Δ=∂2∂x2+∂2∂y2 denotes the Laplace operator. Since the image data is made up of discrete pixels, these equations are discretised. Doing so yields a system of linear equations which can be solved for (u,v) at each pixel, using an iterative scheme such as Gauss-Seidel.

Although, linearising the brightness constancy constraint simplifies the optimisation problem significantly, the linearisation is only valid for small displacements and/or smooth images. To avoid this problem, a multi-scale or coarse-to-fine approach is often used. In such a scheme, the images are initially downsampled and the linearised Euler-Lagrange equations are solved at the reduced resolution. The estimated flow field at this scale is then used to initialise the process at next scale. This initialisation process is often performed by warping one frame using the current estimate of flow field so that it is as similar to other as possible.

An alternate approach is to discretize the optimisation problem and then perform a search of the possible (u,v) values without linearising it. This search is often performed using Max-flow min-cut theorem algorithms, linear programming or belief propagation methods.

These regularized methods typically require manual tuning of the Lagrange multiplier, the so-called regularization parameters. There has been some progress in the automatic determination of these parameters in the context of optical flow applied to particle image velocimetry (PIV) data.

Parametric models

Instead of applying the regularization constraint on a point by point basis as per a regularized model, one can group pixels into regions and estimate the motion of these regions. This is known as a parametric model, since the motion of these regions is parameterized. In formulating optical flow estimation in this way, one makes the assumption that the motion field in each region be fully characterised by a set of parameters. Therefore, the goal of a parametric model is to estimate the motion parameters that minimise a loss function which can be written as,

α^=arg⁡minα∑(x,y)∈Rg(x,y)ρ(x,y,I1,I2,uα,vα),

where α is the set of parameters determining the motion in the region R, ρ() is data cost term, g() is a weighting function that determines the influence of pixel (x,y) on the total cost, and I1 and I2 are frames 1 and 2 from a pair of consecutive frames.

The simplest parametric model is the Lucas-Kanade method. This uses rectangular regions and parameterises the motion as purely translational. The Lucas-Kanade method uses the original brightness constancy constraint as the data cost term and selects g(x,y)=1. This yields the local loss function,

α^=arg⁡minα∑(x,y)∈R|I(x+uα,y+vα,t+1)−I(x,y,t)|.

Other possible local loss functions include the negative normalized cross-correlation between the two frames.

Learning-based models

Instead of seeking to model optical flow directly, one can train a machine learning system to estimate optical flow. Since 2015, when FlowNet was proposed, learning based models have been applied to optical flow and have gained prominence. Initially, these approaches were based on Convolutional Neural Networks arranged in a U-Net architecture, often utilizing encoder-decoder or feature pyramid structures, such as PWC-Net, which integrated cost volumes (a 4D tensor representing the matching costs between all pairs of pixels in two feature maps) and warping (the process of spatially transforming one image based on a predicted flow field) to refine flow estimates across multiple scales. However, with the advent of transformer architecture in 2017, transformer based models have gained prominence. A significant shift occurred with the introduction of RAFT (Recurrent All-Pairs Field Transforms), which replaced coarse-to-fine pyramids with a single GRU-based state that iteratively updates the flow field. By maintaining a constant feature resolution at 1/8 of the input, RAFT significantly improved the preservation of fine details and robustness to fast motion compared to previous bottleneck-heavy designs, influencing a wide range of subsequent models that adopt similar iterative update mechanisms.

However, the all-pairs correlation used in such models is computationally expensive; for high-resolution content like FullHD or 4K, global matching can require more than 32 GB of VRAM, making it impractical for consumer-grade GPUs. To address this, efficiency-focused methods such as Flow1D, MeFlow, and Memfof have been developed. While these approaches generally optimize memory usage by decomposing the 2D search space, the latter optimizes correlation volumes for high-resolution multi-frame sequences, providing a practical implementation for standard GPUs.

Most learning-based approaches to optical flow use supervised learning. In this case, many frame pairs of video data and their corresponding ground-truth flow fields are used to optimise the parameters of the learning-based model to accurately estimate optical flow. This process often relies on vast synthetic training datasets, such as FlyingChairs and FlyingThings3D, due to the number of parameters involved. The models are then evaluated on benchmarks like MPI Sintel, KITTI, and the high-resolution Spring dataset. However, models trained exclusively on synthetic data often struggle with the domain gap when applied to real-world footage.

To address this, some learning-based optical flow approaches use self-supervised learning (sometimes called unsupervised learning) to reduce the need for large datasets with ground-truth data and leverage real-world footage without labels during training. Instead of training models to minimise the differences between estimated and ground-truth flow fields, they are trained to achieve learning objectives such as brightness constancy and smoothness of the flow field. More recently, methods like CroCo have introduced cross-view completion pre-training. Forcing the network to predict the masked regions of one image using the full second image teaches the model a strong geometric understanding and better generalization than models trained solely on task-specific labels.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Robotics