Skip to content

Homography and Projective Transformation

Source: CS1674 Ch.6. A single view is ambiguous in depth; multiple views resolve 3D. This chapter covers 2D transformations, homogeneous coordinates, the homography (projective warp), panorama stitching, and how to estimate H from correspondences (2D-DLT) with RANSAC.

1. Why Multiple Views?

Structure and depth are inherently ambiguous from a single image. Two (or more) views of the same object let us recover geometry. The alignment problem: given matched feature pairs xixi, what transformation T relates them? We fit T's parameters to the correspondences. The canonical application is image mosaics / panorama stitching.

2. 2D Transformations

A transformation is a coordinate-changing machine p=T(p), global (same for every point) and described by few parameters. As a matrix: p=Mp.

2.1 Linear 2D transformations (2×2)

These are combinations of scale, rotation, shear, mirror — but not translation.

TransformMatrixEffect
Scaling (uniform)diag(a,a)Multiply both axes by a
Scaling (non-uniform)[a00b]Different scale per axis
Rotation[cosθsinθsinθcosθ]Rotate about origin; θ=90x=y,y=x
Shear[1shxshy1]Slant
Mirror (Y-axis)[1001]Flip
Mirror (origin)[1001]Rotate 180°

2.2 Translation needs homogeneous coordinates

Translation p=p+t is non-linear in 2D — it cannot be written as a 2×2 matrix multiply. Solution: homogeneous coordinates (x,y)(x,y,1), with the rule:

(x,y,w)(xw,yw,1)

So a 2D point is represented by a 3-vector; to recover image coords divide by w.

2.3 2D Affine transformations (3×3)

Affine = linear transform + translation. Written in homogeneous form with last row [0 0 1]:

[xy1]=[abtxcdty001][xy1]

Properties: maps lines to lines; parallel lines stay parallel.

2.4 2D Projective transformations — Homography (3×3)

Projective = affine + projective warp. General 3×3 matrix:

[xyw]=[h1h2h3h4h5h6h7h8h9]H[xy1](x,y)=(h1x+h2y+h3h7x+h8y+h9, h4x+h5y+h6h7x+h8y+h9)

A homography is a mapping between two projective planes with the same center of projection. Parallel lines need NOT remain parallel (they meet at a vanishing point). Also called a projective transformation.

Hierarchy: Linear ⊂ Affine ⊂ Projective. Degrees of freedom — Linear 4, Affine 6, Projective (homography) 8 (after fixing scale).


3. Panorama Stitching — Motivation

When the camera rotates about its optical center (no translation), the images are related by a homography. Stitching them reprojects all images onto a common plane, forming a synthetic wide-angle view (mosaic).

Basic procedure

  1. Capture a sequence from the same position, rotating about the optical center.
  2. Compute the homography between consecutive images.
  3. Warp/compose images onto a common canvas.
  4. Blend to create the mosaic.
  5. Repeat for more images.

4. Computing the Homography (2D-DLT)

Given n4 matched point pairs (xi,xi), set up equations with H's entries as unknowns. Because H is defined up to scale, fix h9=1 → 8 unknowns, needing ≥ 8 linear equations (i.e., at least 4 point correspondences).

For one correspondence (x,y)(x,y):

x=h1x+h2y+h3h7x+h8y+1,y=h4x+h5y+h6h7x+h8y+1

Cross-multiplying gives two linear equations in the 8 unknowns:

[xy1000xxxy000xy1yxyy][h1h2h3h4h5h6h7h8]=[xy]

Stack all n pairs into Ah=b with AR2n×8.

Solving

  • Overdetermined (n>4): least squares h=(AA)1Ab.
  • Homogeneous form (don't fix h9, use Ah=0): the solution is the unit-norm eigenvector of AA with the smallest eigenvalue:
minh=1Ah2h=v1, λ1=minλ

This is the classic Direct Linear Transform (DLT).


5. Applying a Homography (Image Warping)

Given H and image 1, produce image 2 on a shared canvas.

5.1 Forward warping

Send each pixel p of image 1 to p=Hp in image 2's canvas. Problem: pixels may land between integer locations → round or distribute (splat) the color. Can leave holes.

5.2 Inverse warping (preferred)

For each output pixel p in image 2, fetch its source by (x,y)=H1p. If it falls between pixels in image 1, interpolate (bilinear). Avoids holes; standard for mosaics.


6. Dealing with Outliers: RANSAC for Homography

Matched points always contain errors/outliers. RANSAC:

  1. Sample 4 matched pairs, compute H.
  2. Warp image 1 by H; measure reprojection error for every point.
  3. Count inliers (error < threshold).
  4. Repeat; keep H with most inliers; refit with all inliers. (Hough voting on translation is the simpler special case when only t is unknown.)

7. Assembling the Panorama

  • Chain stitching: img1 H12 img2 H23 img3 … Each Hi,i+1 is a pairwise homography. Simple but error accumulates (drift).
  • Drift correction: add a copy of the first image at the end and optimize global homographies Hi (to the plane of the first image) so the loop closes. This removes accumulated misalignment.
  • Blending: seamlessly combine overlapping regions. Simple method — feathering:
output=(1α)img1+αimg2,α[0,1]

(a linear cross-dissolve across the overlap). More advanced: Laplacian pyramid blending (Ch.3).


8. Summary

ConceptKey point
Homogeneous coordsEncode translation as matrix mult via (x,y,1)
Affine3×3, last row [0 0 1]; preserves parallelism
Homography3×3 general; 8 DOF; relates views from same center
Estimation2D-DLT, ≥4 correspondences, least squares / smallest eigenvector
WarpingPrefer inverse warping + interpolation
RobustnessRANSAC to reject outlier matches
Mosaicchain + drift correction + feathering blend

Bottom line: write 2D transformations as matrix–vector multiplies in homogeneous coordinates; fit them from correspondences; use RANSAC; stitch via homography + inverse warping + blending.