Hartley Projective Rectification | VitaVision
Back to atlas

Hartley Projective Rectification

8 min readAdvancedView in graph
Based on
Theory and Practice of Projective Rectification
Hartley · International Journal of Computer Vision 1999
DOI ↗

Goal

Resample a pair of uncalibrated images into a matched epipolar projection: a homography pair (H,H)(H, H') such that corresponding epipolar lines are horizontal in both images and disparities between matched points are purely horizontal. Input: point correspondences xixi\mathbf{x}_i \leftrightarrow \mathbf{x}'_i (n8n \geq 8) sufficient to estimate the fundamental matrix FF, or FF itself if already known. Output: the pair (H,H)(H, H'), each a 3×33 \times 3 projective transform, together with the resampled image pair. No camera matrices or calibration are used; the construction depends on FF alone. The guarantee is topological and geometric — a rectilinear-stereo-equivalent epipolar geometry that enables 1-D correspondence search — not metric: reconstruction from the rectified pair recovers scene structure only up to an unknown 3-D projectivity.

Algorithm

Let x=(x,y,1)T\mathbf{x} = (x, y, 1)^T and x=(x,y,1)T\mathbf{x}' = (x', y', 1)^T denote homogeneous image-1 and image-2 coordinates of a correspondence. Let FF denote the 3×33 \times 3 rank-2 fundamental matrix satisfying xTFx=0\mathbf{x}'^T F\,\mathbf{x} = 0. Let e\mathbf{e}' denote the epipole in image 2, the left null vector of FF: eTF=0T\mathbf{e}'^T F = \mathbf{0}^T. Let MM denote a non-singular 3×33 \times 3 matrix such that F=[e]×MF = [\mathbf{e}']_\times M — this factorisation always exists, since eT[e]×=0T\mathbf{e}'^T[\mathbf{e}']_\times = \mathbf{0}^T makes any such MM compatible with eTF=0T\mathbf{e}'^T F = \mathbf{0}^T. Let TT denote the translation centring a chosen reference point u0\mathbf{u}_0 — the image centre, by default — at the origin. Let RR denote the rotation about the origin that aligns the translated epipole with the xx-axis. Let ff denote the xx-coordinate of the epipole after applying TT and RR.

Definition
Epipole-to-infinity perspectivity (GG)

Perspectivity sending the aligned epipole (f,0,1)T(f, 0, 1)^T to the ideal point (f,0,0)T(f, 0, 0)^T, chosen so its Jacobian at the origin equals the identity to first order.

G=[1000101/f01].G = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ -1/f & 0 & 1 \end{bmatrix}.

GG maps (u,v,1)T(u,v,1u/f)T(u, v, 1)^T \mapsto (u,\, v,\, 1 - u/f)^T. After perspective division, (u,v,1)11u/f(u,v,1)(u, v, 1) \mapsto \tfrac{1}{1 - u/f}(u, v, 1), which for u/f<1|u/f| < 1 expands as (u,v,1)(1+u/f+(u/f)2+)(u, v, 1)(1 + u/f + (u/f)^2 + \cdots) — a rigid map to first order near the origin. The rectifying homography for image 2 is

H=GRT.H' = G R T.

Writing F=[e]×MF = [\mathbf{e}']_\times M, a homography HH of image 1 preserves epipolar-line correspondence with HH' iff H=(I+HeaT)HMH = (I + H'\mathbf{e}'\,\mathbf{a}^T)\,H' M for some free vector a\mathbf{a} (Theorem 4.5). When HH' sends the epipole to (1,0,0)T(1, 0, 0)^T exactly, this family collapses (Corollary 4.6) to H=A(HM)H = A\,(H'M) with AA restricted to a 3-parameter affine form.

Definition
Matching affine transform (AA)

Affine restriction of the epipolar-line-preserving family (Corollary 4.6), leaving the yy-coordinate of the transformed point unchanged.

A=[abc010001].A = \begin{bmatrix} a & b & c \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}.

The free parameters a,b,ca, b, c are fixed by ordinary linear least squares. Let x^i=HMxi\hat{\mathbf{x}}_i = H'M\,\mathbf{x}_i and x^i=Hxi\hat{\mathbf{x}}'_i = H'\,\mathbf{x}'_i denote the matched points transformed by the pre-affine map and by HH', with (x^i,y^i)(\hat x_i, \hat y_i) and (x^i,y^i)(\hat x'_i, \hat y'_i) their inhomogeneous coordinates. Because AA leaves the yy-coordinate unchanged, the yy-residual is constant and drops out of the minimisation; only

i(ax^i+by^i+cx^i)2\sum_i \bigl(a\,\hat x_i + b\,\hat y_i + c - \hat x'_i\bigr)^2

is minimised over a,b,ca, b, c. Restricting AA to the affine subgroup is what keeps this fit linear — a general projective AA does not admit a closed-form least-squares solution.

Definition
Quasi-affine transform

A projective map HH is quasi-affine with respect to a convex view window WW if H(W)H(W) does not meet the line at infinity LL_\infty: no point of WW is sent to infinity or behind the camera by HH. Violating this condition tears the resampled image into disconnected pieces.

If the epipole e\mathbf{e}' does not lie in the view window WW' of image 2, a matching HH from the Theorem 4.5 family is quasi-affine on some convex subwindow W+WW^+ \subseteq W of image 1 (Theorem 5.7) — not necessarily on all of WW.

Procedure

flowchart TB
    A["Estimate F and epipole e′"] --> B["Build H′ = G R T"]
    B --> C["Fit matching H = A(H′M) by affine least squares"]
    C --> D["Resample both images through H and H′"]
Algorithm
Hartley projective rectification
Input: Point correspondences xixi\mathbf{x}_i \leftrightarrow \mathbf{x}'_i, n8n \geq 8; view windows W,WW, W' containing the matched points. A precomputed fundamental matrix FF may be supplied to skip step 1, but the correspondences are still required — step 6 fits the matching transform to them.
Output: Rectifying homography pair (H,H)(H, H').
  1. Estimate FF from the correspondences by a linear least-squares method if not already known, and factor it as F=[e]×MF = [\mathbf{e}']_\times M with e\mathbf{e}' the epipole in image 2.
  2. Choose a reference point u0\mathbf{u}_0 in image 2 and build TT, the translation sending u0\mathbf{u}_0 to the origin.
  3. Build RR, the rotation about the origin that aligns the translated epipole with the xx-axis, and read off ff, its distance from the origin.
  4. Build GG from ff and form H=GRTH' = G R T.
  5. Verify that HH' is quasi-affine on WW'. If the epipole e\mathbf{e}' lies inside WW', shrink the view window until it excludes e\mathbf{e}', or abandon this construction for a different projectivity — a new reference point u0\mathbf{u}_0 cannot help, since GRTGRT sends that same in-window epipole to infinity regardless of where the window is centred, so H(W)H'(W') still meets the line at infinity.
  6. Transform the matched points by HMH'M (image 1) and HH' (image 2), and fit a,b,ca, b, c of AA by linear least squares.
  7. Form H=A(HM)H = A(H'M) and confirm it is quasi-affine on some convex subwindow W+WW^+ \subseteq W.
  8. Resample both images through HH and HH' by inverse mapping with interpolation.

Implementation

The epipole-to-infinity perspectivity and the affine matching-transform fit in Rust:

use nalgebra::{Matrix3, Vector3};

/// Perspectivity sending the aligned epipole (f, 0, 1) to the ideal
/// point (f, 0, 0); its Jacobian at the origin is the identity.
fn epipole_to_infinity(f: f64) -> Matrix3<f64> {
    Matrix3::new(
        1.0,      0.0, 0.0,
        0.0,      1.0, 0.0,
        -1.0 / f, 0.0, 1.0,
    )
}

/// Fit the 3-parameter affine matching transform A (Corollary 4.6) by
/// ordinary linear least squares, minimising
/// sum_i (a*x_i + b*y_i + c - xp_i)^2 over the transformed
/// correspondences (x_i, y_i) <-> xp_i.
fn fit_matching_affine(pts: &[(f64, f64)], xp: &[f64]) -> (f64, f64, f64) {
    let mut m = Matrix3::<f64>::zeros();
    let mut rhs = Vector3::<f64>::zeros();
    for (&(x, y), &xpi) in pts.iter().zip(xp) {
        let row = Vector3::new(x, y, 1.0);
        m += row * row.transpose();
        rhs += row * xpi;
    }
    let sol = m
        .lu()
        .solve(&rhs)
        .expect("normal equations well-posed for n >= 3 non-collinear points");
    (sol.x, sol.y, sol.z)
}

Remarks

  • The construction is O(n)O(n) in the number of correspondences for the affine fit, plus O(Ω1+Ω2)O(|\Omega_1| + |\Omega_2|) for the final per-pixel resampling of both images; no iterative optimisation is required beyond the optional nonlinear refinement of FF itself.
  • Theorem 5.7 guarantees quasi-affinity of the matching transform HH only on a convex subwindow W+WW^+ \subseteq W of the first image, not necessarily on the whole of WW; part of WW can remain unusable if it corresponds to points outside WW'.
  • If the epipole lies inside the view window WW' — forward or near-forward motion — Theorem 5.7 does not apply, since its hypothesis requires the epipole to lie outside WW'; the paper's only stated remedy is to shrink the view window or choose a different reference point, with no guarantee of a valid full-window solution.
  • The first-order approximation of GG as a rigid map holds for u/f<1|u/f| < 1; as the epipole approaches the view window, ff shrinks, the approximation degrades, and the mapped coordinates grow without bound near u=fu = f.
  • The rectified pair carries no metric information: reconstruction from (H,H)(H, H') recovers scene structure only up to an unknown 3-D projectivity, not up to a similarity or Euclidean transform.
  • See the stereo rectification survey for a comparison against Loop-Zhang and polar rectification.

References

  1. R. I. Hartley. Theory and Practice of Projective Rectification. International Journal of Computer Vision, 1999. pdf
  2. H. C. Longuet-Higgins. A Computer Algorithm for Reconstructing a Scene from Two Projections. Nature 293, 1981. doi.org/10.1038/293133a0

Parallel foundation with

Compared with