A bit of theory always helps but if you want you can jump to my Github page to see the step by step implementation of the optical flow models that I am discussing here.
Introduction
Motion information is one of the most valuable cues of the visual system and it is the foundation of many computer vision applications. These include visual navigation, segmentation, video compression, object tracking, and behavior analysis. Motion information in the time-ordered images sequence is extracted from estimating the displacements of intensity patterns which is known as Optical flow.
The basic hypothesis in estimating optical flow is brightness constancy which originated from the physiological definition of Perceptual Constancy. The brightness constancy states that the intensity of moving pixels remains constant in a short duration. Let be the intensity for the pixel at time then,
with applying Taylor expansion on the left side of Eq. \eqref{eq:k1} the optical flow constrain equation drives as,
where and is the spatial intensity gradient and is temporal gradient and is velocity vector.
Horn and Schunk
The brightness constancy constraint alone is inadequate to solve the ambiguity of motion flow. With assuming motion field varies smoothly over frames (smoothness constraint), Horn and Schunk proposed first variational optical flow estimation. Horn and Schunk formulated motion flow as a global energy function. This energy function should be minimized with respect to two error terms:
1. | Data Error: | |
2. | Smoothness Error: |
So that, the total error is equal to,
Minimise the Eq. \eqref{eq:e_total} and with some variational calculus knowledge, we can drive the two main optical flow equations as,
where and are the average flow of some neighbours around pixle . The optimal is approximated by iterativly estimate and using Eq. \eqref{eq:hs_final}
You can check my step by step implementation of Horn and Schunkon model in here.
Lucas–Kanade Method
Horn and Schunck assume the global smoothness constraint to solve the motion ambiguity, in contrast Lucas–Kanade used local smoothness constraint. Lucas–Kanade assumed the motion is constant at some neighbourhood around pixles and solves the optical flow equations for all the pixels in that neighbourhood. Thus the motion vector can be estimated by finding a solution that minimizes the sum of squared errors,
is the number of pixel neighbourhoods. For neighbourhood , thus we have equations and unknown (over-determined system) and and is estimated by,
You can check my step by step implementation of Lucas–Kanade Method model in here.
Farneback
Farneback used second-degree polynomial expansion to calculate motion. Farnback model contains two main steps:
1- Approximating the neighbourhood around each pixel as a quadric function using polynomial expansion
2- Use the expansion coefficients to estimate the displacement of pixels
Polynomial expansion approximating the neighbourhood around a pixel by a quadratic equation as,
This approximation achieved by applying an operation called Normalized convolution using basis of as:
Where is the basis, is an applicability matrix, is diagonal of , is a certainty matrix and is diagonal of
putting Eq. \eqref{eq:norm_conv} and Eq. \eqref{eq:poly} together we can represent the quadratic equation as a form of tensor by,
where
where to are expansion coefficient.
Based on brightness constancy, the displacement vector can be found by solving the following equation,
which result in:
so that, is then estimated by
and this result can improved iteratively by,
You can check my step by step implementation of Farneback Method model in here.