To solve the optical flow constraint equation for *u* and *v*,
the Lucas-Kanade method divides the original image into smaller sections
and assumes a constant velocity in each section. Then, it performs
a weighted least-square fit of the optical flow constraint equation
to a constant model for $${\left[\begin{array}{cc}u& v\end{array}\right]}^{T}$$ in
each section $$\Omega $$.
The method achieves this fit by minimizing the following equation:

*W* is a window function that emphasizes
the constraints at the center of each section. The solution to the
minimization problem is

.

The Lucas-Kanade method computes $${I}_{t}$$ using
a derivative of Gaussian filter.

To solve the optical flow constraint equation for *u* and *v*:

Compute $${I}_{x}$$ and $${I}_{y}$$ using
the following steps:

Use a Gaussian filter to perform temporal filtering.
Specify the temporal filter characteristics such as the standard
deviation and number of filter coefficients using the `NumFrames`

property.

Use a Gaussian filter and the derivative of a Gaussian
filter to smooth the image using spatial filtering. Specify the standard
deviation and length of the image smoothing filter using the `ImageFilterSigma`

property.

Compute $${I}_{t}$$ between
images 1 and 2 using the following steps:

Use the derivative of a Gaussian filter to perform
temporal filtering. Specify the temporal filter characteristics such
as the standard deviation and number of filter coefficients using
the `NumFrames`

property.

Use the filter described in step 1b to perform spatial
filtering on the output of the temporal filter.

Smooth the gradient components, $${I}_{x}$$, $${I}_{y}$$,
and $${I}_{t}$$,
using a gradient smoothing filter. Use the `GradientFilterSigma`

property
to specify the standard deviation and the number of filter coefficients
for the gradient smoothing filter.

Solve the 2-by-2 linear equations for each pixel using
the following method:

If $$A=\left[\begin{array}{cc}a& b\\ b& c\end{array}\right]=\left[\begin{array}{cc}{\displaystyle \sum {W}^{2}{I}_{x}^{2}}& {\displaystyle \sum {W}^{2}{I}_{x}{I}_{y}}\\ {\displaystyle \sum {W}^{2}{I}_{y}{I}_{x}}& {\displaystyle \sum {W}^{2}{I}_{y}^{2}}\end{array}\right]$$

Then the eigenvalues of A are $${\lambda}_{i}=\frac{a+c}{2}\pm \frac{\sqrt{4{b}^{2}+{(a-c)}^{2}}}{2};i=1,2$$

When the algorithm finds the eigenvalues, it compares
them to the threshold, $$\tau $$,
that corresponds to the value you enter for the `NoiseThreshold`

property.
The results fall into one of the following cases:

Case 1: $${\lambda}_{1}\ge \tau $$ and $${\lambda}_{2}\ge \tau $$

A is nonsingular, so the algorithm solves the system of equations
using Cramer's rule.

Case 2: $${\lambda}_{1}\ge \tau $$ and $${\lambda}_{2}<\tau $$

A is singular (noninvertible), so the algorithm normalizes the
gradient flow to calculate *u* and *v*.

Case 3: $${\lambda}_{1}<\tau $$ and $${\lambda}_{2}<\tau $$

The optical flow, *u* and *v*,
is 0.