Post

Homography in Computer Vision (4-Point Solution and N-Point Least Squares)

Homography in Computer Vision (4-Point Solution and N-Point Least Squares)

๐Ÿ“ What Is Homography?

A homography is a projective transformation that maps points from one plane to another.

It is widely used for:

  • Image stitching
  • Perspective correction
  • Planar object tracking
  • Camera pose estimation (planar scenes)

A homography is represented by a 3ร—3 matrix:

\[\mathbf{H} = \begin{bmatrix} h_{11} & h_{12} & h_{13} \\ h_{21} & h_{22} & h_{23} \\ h_{31} & h_{32} & h_{33} \end{bmatrix}\]

Defined up to scale: \(\mathbf{H} \sim \lambda \mathbf{H}\)

So it has 8 degrees of freedom.


๐Ÿ”— Point Mapping Equation

Using homogeneous coordinates:

\[\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} \sim \mathbf{H} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\]

Which expands to:

\[x' = \frac{h_{11}x + h_{12}y + h_{13}}{h_{31}x + h_{32}y + h_{33}}\] \[y' = \frac{h_{21}x + h_{22}y + h_{23}}{h_{31}x + h_{32}y + h_{33}}\]

๐ŸŸฆ Case 1: Homography from 4 Point Correspondences

Why 4 Points?

  • Each point correspondence gives 2 independent equations
  • Homography has 8 unknowns
  • Minimum: 4 point pairs

Linear Equation per Point

For correspondence ((x,y) \leftrightarrow (xโ€™,yโ€™)):

\[\begin{aligned} x'(h_{31}x + h_{32}y + h_{33}) &= h_{11}x + h_{12}y + h_{13} \\ y'(h_{31}x + h_{32}y + h_{33}) &= h_{21}x + h_{22}y + h_{23} \end{aligned}\]

Rearranged into linear form:

\[\mathbf{A} \mathbf{h} = \mathbf{0}\]

Where:

\[\mathbf{h} = [h_{11}, h_{12}, h_{13}, h_{21}, h_{22}, h_{23}, h_{31}, h_{32}, h_{33}]^T\]

Matrix (\mathbf{A}) has size 8ร—9.


Solution

  • Solve using SVD
  • Solution = right singular vector corresponding to smallest singular value
  • Reshape into 3ร—3 matrix

๐ŸŸฉ Case 2: Homography from N Points (N โ‰ฅ 4)

When more than 4 correspondences are available, the system becomes overdetermined.

This improves:

  • Noise robustness
  • Numerical stability

๐Ÿ“Š Linear System (DLT Form)

For N point pairs:

\[\mathbf{A} \mathbf{h} = \mathbf{0}\]

Where:

  • (\mathbf{A}) is (2N)ร—9
  • (N > 4)

๐Ÿงฎ Pseudo-Inverse / Least Squares View

We solve:

\[\min_{\mathbf{h}} \| \mathbf{A} \mathbf{h} \|^2\]

Subject to:

\[\| \mathbf{h} \| = 1\]

Solution

  • Compute SVD of (\mathbf{A})
  • Take eigenvector corresponding to smallest singular value
  • Equivalent to solving with Mooreโ€“Penrose pseudo-inverse

๐Ÿ”ง Normalized DLT (Important in Practice)

Before solving:

  1. Normalize points (zero mean, unit variance)
  2. Solve homography
  3. Denormalize result

This greatly improves numerical stability.


โš ๏ธ Degenerate Configurations

Homography estimation fails if:

  • Points are collinear
  • All points lie on a line
  • Insufficient spatial spread

โš–๏ธ 4-Point vs N-Point Comparison

Aspect4 PointsN Points
MinimumYesNo
Noise robustnessโŒโœ…
Uses least squaresโŒโœ…
Typical useTheory, exactReal systems

๐Ÿง  Practical Pipeline

1
2
3
4
5
6
7
Feature Match
   โ†“
RANSAC (inliers)
   โ†“
Normalized DLT
   โ†“
Homography

๐ŸŽฏ Takeaway

  • Homography has 8 DOF
  • 4 points give a minimal exact solution
  • N points โ†’ least squares via SVD / pseudo-inverse
  • Normalization is critical in real systems

Understanding this math is essential for stitching, tracking, and registration ๐Ÿš€

This post is licensed under CC BY 4.0 by the author.