Topic: registration and alignment
Bringing two images, two frames or two shapes into register: every approach in the course, side by side
Alignment comes up on many days of this course: tiles to stitch, a drifting time-lapse, two stains of one section, the frames of a movie, outlines of hands, two photographs of a scene. This page puts the approaches next to each other. It does not teach them; follow the links to the units for that.
The question
Two images show (partly) the same thing. Where does each point of one image lie in the other? The answer is a transform: a map from the coordinates of the moving image to those of the fixed one. Once you have it, you can resample the moving image onto the fixed grid (inverse mapping and interpolation) and compare, overlay, average or subtract them.

Every registration method, whatever its name, makes three choices:
- Which transforms are allowed? A shift, a rotation, an affine map, a smooth deformation, a vector for every pixel. More freedom fits more, including things it should not fit.
- What counts as “aligned”? The grey levels agree (sum of squared differences), they agree up to brightness and contrast (correlation), one predicts the other (mutual information), or a set of matched points land on each other.
- How is the best transform found? By trying every candidate, by a closed formula, by a robust guess-and-check, or by walking downhill from a start.
The rest of this page goes through the three choices, then compares the methods.
Which transforms?
Choose the simplest model the physics allows: a microscope stage moves (translation); a slide put back on the stage also turns (rigid); a different objective adds scale (similarity); a flat object photographed at an angle needs a homography; tissue that bends, grows or is cut into sections needs a smooth deformation; cells moving independently need a flow field or tracking. Each extra number is one more way to fit noise, or to “register away” a real change.
Try the five parametric models on the same point pairs:
Questions on this demo: feature alignment exercise. The models in detail: affine maps and homogeneous coordinates, the transform hierarchy and the homography, free-form deformation with splines.
What counts as aligned?
There are two kinds of evidence.
- Intensities: compare all the pixels of the overlap. Needs nothing but the images; uses every pixel, so it is precise; fails on empty or repetitive texture and, with the simple scores, when the two images have different contrast.
- Features: find distinctive points (corners, blobs, beads, landmarks) in both images, match them, and fit the transform to the pairs. Copes with large offsets, rotation, small overlap and occlusion; fails when there are too few distinctive points, or when repeated texture gives wrong matches.
For intensities, the score decides which differences between the images are allowed:

| Score | Allows | Use when |
|---|---|---|
| sum of squared differences | nothing: same grey levels | same camera, same settings |
| normalised cross-correlation | brightness and contrast change (linear) | illumination or exposure differ |
| mutual information | any one-to-one relation between grey levels | different stains, channels or modalities |
| matched points | anything between the points | features or landmarks can be found and matched |
Scores in detail: three scores, mutual information and the joint histogram (demo: joint histogram). Features in detail: keypoints, descriptors, matching.
How is the best transform found?
The score, as a function of the transform’s numbers, is a landscape. The four ways of searching it in the course:
- Try everything. For a shift, compute the score for every shift at once with the FFT (cross-correlation, phase correlation). Global and fast, but only for shifts (other parameters: loop over them, as in the first figure).
- Solve a formula. For matched points, the best rigid, similarity or affine transform is a least-squares fit in closed form (Procrustes, fitting clean pairs).
- Guess and check. With wrong matches among the right ones, least squares is pulled away. RANSAC fits the transform to random minimal samples and keeps the one most pairs agree with.
- Walk downhill. From a start, change the parameters a little in the direction that improves the score: Lucas–Kanade, Horn–Schunck, free-form registration. The only option for many parameters, but it finds the nearest good alignment, not the best one.

The basin explains two standard tricks. Coarse to fine: blur or shrink both images first, so fine texture turns into coarse texture and the basin widens; align there, then refine at full resolution (pyramids for Lucas–Kanade). Rough first, fine after: get the rough transform from something global (phase correlation, features + RANSAC), then refine with a local, downhill method.
Features and outliers

A few wrong matches are normal (repeated texture, noise). Least squares gives every pair a vote in proportion to its squared error, so one far-off wrong pair pulls the fit away; RANSAC counts votes instead. The feature alignment unit has the full pipeline (demo: RANSAC on matches).
Side by side
| Approach | Transform | Evidence | Assumes | Cost | Fails when | Units |
|---|---|---|---|---|---|---|
| Template matching, sliding score | shift | intensities (SSD, NCC) | same size and orientation | every shift × every pixel | rotation, scale; repeated texture | matching |
| Cross-correlation with the FFT | shift | intensities | overlap with contrast; periodic images (or padding) | three FFTs | wrap-around without padding; broad peaks | FFT correlation |
| Phase correlation, stitching | shift (sub-pixel), many tiles | intensities, phase only | enough overlap; translation only | three FFTs per pair | rotation, scale; noise at high frequencies; empty tiles | phase correlation, stitching |
| Procrustes | rigid, similarity | matched landmarks | the correspondences are known and correct | closed form (one small SVD) | wrong correspondences | shape models |
| Keypoints + RANSAC | rigid to homography | matched features | enough distinctive points; most matches right | detection + matching + a few hundred guesses | empty or repetitive images; different modalities | keypoints, matching, alignment, RANSAC |
| Lucas–Kanade | shift per window | intensities, brightness constancy | small motion; texture in the window | closed form per pixel (pyramid for large motion) | flat regions; edges (aperture problem); large motion | flow constraint, Lucas–Kanade |
| Horn–Schunck | vector per pixel | intensities, brightness constancy | smooth motion everywhere | many iterations | motion boundaries are blurred; flat regions filled in unchecked | Horn–Schunck |
| Free-form (spline) registration | smooth deformation | SSD, NCC or mutual information | the deformation is smooth; a rough alignment first | an optimisation over many parameters | folding; “registers away” real change; local minima | splines on images, non-rigid |
| Tracking | one position per object and frame | detections | objects can be detected; motion is predictable | assignment per frame | dense crowds; fast motion; divisions | linking, prediction |
| Two views, structure from motion | camera poses + 3D points | matched features | a static scene with depth (parallax) | RANSAC + bundle adjustment | pure rotation, flat scenes, tiny baseline | two views, SfM |
Motion: registration between frames
Optical flow is registration of two frames a moment apart, with the most freedom of all: one vector per pixel. Two things make it possible. Motion between frames is small, so the downhill search starts inside the basin; and neighbouring pixels move together, which supplies the information one pixel cannot: along an edge, only the motion across the edge can be seen (the aperture problem; demo: the aperture). Lucas–Kanade assumes one motion per window, Horn–Schunck a smooth field, and non-rigid registration a smooth family of deformations that may be large and may change the contrast. Tracking instead keeps the identity of objects, and is usually done after correcting the global drift (drift correction).
When no single transform exists
A transform maps image to image. That works when the scene is flat (a section, a slide, a painting) or the camera only turns. In a 3D scene seen from two positions, near points shift more than far ones (parallax), and no 2D transform aligns everything. Then the geometry is between the cameras: each point in one image lies on a line in the other (epipolar geometry), and how far along that line gives its depth (stereo, structure from motion). The degenerate cases of that geometry are exactly the cases where a homography does explain the matches.
The math: one objective
For images, registration solves T^\ast \;=\; \arg\min_{T \in \mathcal T}\; \mathcal D\big(I_{\text{fixed}},\; I_{\text{moving}} \circ T\big) \;+\; \lambda\, \mathcal R(T), and for matched points p_i \leftrightarrow q_i T^\ast \;=\; \arg\min_{T \in \mathcal T}\; \sum_i \rho\big(\lVert T(p_i) - q_i \rVert\big).
- The family \mathcal T: shifts (2 parameters), rigid (3), similarity (4), affine (6), homography (8), B-spline deformations (2 per control point), flow fields (2 per pixel).
- The dissimilarity \mathcal D: \sum (I_f - I_m\circ T)^2; -\text{NCC}; -\text{MI}, where \text{MI} = H(I_f) + H(I_m\circ T) - H(I_f, I_m\circ T) from the joint histogram.
- The regulariser \mathcal R: zero for parametric families (the family is the regularisation); \int \lVert\nabla \mathbf u\rVert^2 for Horn–Schunck; bending energy or a penalty on a negative Jacobian determinant for free-form deformations.
- The robust loss \rho: \rho(r) = r^2 is least squares (closed form for rigid, similarity and affine: Procrustes); RANSAC uses \rho(r) = 0 if r < \varepsilon, else 1, and searches by random minimal samples.
The solvers: exhaustive search (for shifts, all at once by the correlation theorem \mathcal F^{-1}[\hat I_f^{\,*}\hat I_m], or phase correlation with the magnitude divided out); closed form (Procrustes via an SVD, the direct linear transform for homographies); Gauss–Newton on a linearisation I_m(\mathbf x + \mathbf u) \approx I_m + \nabla I_m^{\top}\mathbf u, which for one shift per window gives the Lucas–Kanade system with the structure tensor as its matrix. The linearisation is valid only for small \mathbf u: that is the basin of the figure above, and the reason for pyramids.
Checking the result
A registration always returns some transform. Check it:
- Look: a two-colour overlay or a checkerboard of fixed and aligned moving image; edges should continue across the squares.
- Measure on points you did not use: held-out landmarks or beads, and their distance after alignment (applications and limits).
- Read the confidence: the height and sharpness of a correlation peak, the number of RANSAC inliers, the residual of the fit (how much to trust a peak).
- For deformations: the Jacobian determinant must stay positive (no folding), and the deformation should not be freer than the question allows.
- For motion: the warping residual, or ground truth on simulated sequences (evaluating flow).
All units on this topic
| Day | Units |
|---|---|
| 1 Images | affine transforms, inverse mapping, interpolation (demo) |
| 6 Splines | splines on images, free-form deformation (demo) |
| 21 Hough | RANSAC (demo) |
| 23 FFT registration | sliding and scoring (demo) · cross-correlation with the FFT (demo) · phase correlation (demo) · stitching (demo, sub-pixel, drift) |
| 24 Keypoints | keypoints (demo) · descriptors (demo) · matching (demo) · from matches to a transform (transform zoo, RANSAC on matches) |
| 25 Optical flow | brightness constancy, aperture (demo) · Lucas–Kanade (demo) · Horn–Schunck (demo) · non-rigid registration (joint histogram, free-form) |
| 26 Tracking | linking (demo) · motion models |
| 30 Snakes | Procrustes and shape models (demo) |
| 49 Multiple views | cameras · two views (demo) · stereo · structure from motion (demo) |
Related topic pages: finding points (correlation peaks, keypoints), eigenvectors (structure tensor, Procrustes, calibration), energy minimisation (Horn–Schunck, regularised registration); all topics.