One motion for the whole image
Lucas–Kanade moves a small window by a shift . When the camera pans, rotates or zooms, or when the scene is a single plane, every pixel follows one transformation with a few parameters . They are estimated from all pixels at once by minimizing
Pixels whose falls outside have nothing to be compared with and are left out. Since their number changes with , the demo reports the mean of over the pixels that count.
Motion models
The models are the 2D transformations, written so that is the identity. Coordinates are measured from the image center, so that rotation and scaling turn around the middle of the image:
- Translation, 2 parameters: .
- Euclidean, 3 parameters: , rotation and shift.
- Affine, 6 parameters: , .
- Projective, 8 parameters: , , the motion of a plane seen by a moving camera, as in the homography demo.
The chain rule
As in Lucas–Kanade, is linearized around the current estimate, . The derivative of the error with respect to the parameters has two factors: how the image changes when moves, and how moves when changes,
For the affine model, for example,
Each entry of , taken over the whole image, is one of the steepest-descent images: the change of the warped image when one parameter grows a little. The images for and are just the gradients; the others are the gradients weighted by the position, which is why the corners of the image carry most of the information about rotation and scaling.
Gauss–Newton with unknowns
Minimizing is a least-squares problem in . Its normal equations are an system, no matter how many pixels there are:
For translation, is the matrix of Lucas–Kanade summed over the whole image. The iteration stops when an update moves the image corners by less than 0.001 px.
Choosing the model
A model with too few parameters cannot reach zero error: the best it can do is a compromise, and the rest stays visible in the error image as a pattern that grows towards the image border. A model with more parameters than the motion needs can express the true motion too, but its extra parameters also follow whatever the images do not share, such as noise and interpolation errors, and every step costs more. The simplest model that describes the motion is usually the most accurate.
Limits
- The linearization only holds near the solution. Large shifts and rotations need a good start, which a coarse-to-fine pyramid provides for parametric models just as for a window.
- The model has to fit the whole image. A moving object or a scene with depth breaks it, since different parts move differently; robust error functions and per-pixel optical flow handle that.
- Brightness constancy is assumed as before: noise averages out over the many pixels, but changes in exposure do not.
Try this
- Press Play with the defaults: shift (10, −7), rotation 15° and scale 1.12 move the image corners by more than 30 px. The affine model needs 15 updates. For ten of them the corner error falls slowly, since the linearization only roughly points the way; then, once the estimate is close, it drops from 4 px to 0.05 px within three steps, the fast final convergence of Gauss–Newton. The error image fades to almost uniform gray; the last 0.05 px comes from interpolation, since was made by resampling the image.
- Switch the model to translation: no shift can explain a rotation and a scaling, the estimate drifts and still ends 33 px off at the corners after 30 iterations, and the error image keeps strong edges that grow towards the border. Euclidean converges in 19 updates but stays 13 px off, since it cannot scale.
- Set the tilt to 1.5: the affine model no longer settles and stays about 16 px off at the corners, while the projective model reaches 0.16 px after 27 updates.
- Choose the projective model at the defaults: it needs 19 updates and ends at 0.37 px instead of 0.05 px. Its two extra parameters cannot stay at zero; they also fit the interpolation errors. With a pure shift (rotation 0, scale 1), translation ends within 0.005 px after 7 updates and projective at 0.11 px. A model should be as simple as the motion allows.
- Compare the steepest-descent images for and : the second is the first multiplied by , faint in the middle and strong at the left and right, with opposite signs on the two sides.
- Change the pre-smoothing : at 3 the iteration converges in 10 updates but only to 0.17 px, at 1 it takes 23 updates and ends at 0.02 px, and at 0.5 the fence and the flowers only look linear over about a pixel and the estimate never settles. Smoothing widens the basin and speeds up the first steps, detail makes the result accurate. A pyramid gets both.
- Choose the test chart: its repeated bars look alike at many shifts, and with this large motion the estimate never gets going and is still 33 px off after 30 steps. Reduce the motion to shift (3, −2), rotation 3° and scale 1.04, and it converges.