The Lucas–Kanade method assumes that the displacement of the image contents between two nearby instants (frames) is small and approximately constant within a neighborhood of the point p under consideration. Thus the
optical flow equation can be assumed to hold for all pixels within a window centered at p. Namely, the local image flow (velocity) vector (V_x,V_y) must satisfy \begin{align} I_x(q_1) V_x + I_y (q_1) V_y &= -I_t(q_1) \\ I_x(q_2) V_x + I_y (q_2) V_y &= -I_t(q_2) \\ & \; \ \vdots \\ I_x(q_n) V_x + I_y (q_n) V_y &= -I_t(q_n) \end{align} where q_1,q_2,\dots,q_n are the pixels inside the window, and I_x(q_i),I_y(q_i),I_t(q_i) are the partial derivatives of the image I with respect to position x, y and time t, evaluated at the point q_i and at the current time. These equations can be written in
matrix form A v = b, where A = \begin{bmatrix} I_x(q_1) & I_y(q_1) \\[10pt] I_x(q_2) & I_y(q_2) \\[10pt] \vdots & \vdots \\[10pt] I_x(q_n) & I_y(q_n) \end{bmatrix} \quad\quad\quad v = \begin{bmatrix} V_x\\[10pt] V_y \end{bmatrix} \quad\quad\quad b = \begin{bmatrix} -I_t(q_1) \\[10pt] -I_t(q_2) \\[10pt] \vdots \\[10pt] -I_t(q_n) \end{bmatrix} This system has more equations than unknowns and thus it is usually over-determined. The Lucas–Kanade method obtains a compromise solution by the
least squares principle. Namely, it solves the 2 \times 2 system A^T A v=A^T b or \mathrm{v}=(A^T A)^{-1}A^T b where A^T is the
transpose of matrix A. That is, it computes \begin{bmatrix} V_x\\[10pt] V_y \end{bmatrix} = \begin{bmatrix} \sum_i I_x(q_i)^2 & \sum_i I_x(q_i)I_y(q_i) \\[10pt] \sum_i I_y(q_i)I_x(q_i) & \sum_i I_y(q_i)^2 \end{bmatrix}^{-1} \begin{bmatrix} -\sum_i I_x(q_i)I_t(q_i) \\[10pt] -\sum_i I_y(q_i)I_t(q_i) \end{bmatrix} where the central matrix in the equation is an
Inverse matrix. The sums are running from i=1 to n. The matrix A^T A is often called the
structure tensor of the image at the point p. == Weighted window ==