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:
- Normalize points (zero mean, unit variance)
- Solve homography
- 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
| Aspect | 4 Points | N Points |
|---|---|---|
| Minimum | Yes | No |
| Noise robustness | โ | โ |
| Uses least squares | โ | โ |
| Typical use | Theory, exact | Real 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.