Goal
Resample a pair of uncalibrated images into a matched epipolar projection: a homography pair such that corresponding epipolar lines are horizontal in both images and disparities between matched points are purely horizontal. Input: point correspondences () sufficient to estimate the fundamental matrix , or itself if already known. Output: the pair , each a projective transform, together with the resampled image pair. No camera matrices or calibration are used; the construction depends on 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 and denote homogeneous image-1 and image-2 coordinates of a correspondence. Let denote the rank-2 fundamental matrix satisfying . Let denote the epipole in image 2, the left null vector of : . Let denote a non-singular matrix such that — this factorisation always exists, since makes any such compatible with . Let denote the translation centring a chosen reference point — the image centre, by default — at the origin. Let denote the rotation about the origin that aligns the translated epipole with the -axis. Let denote the -coordinate of the epipole after applying and .
Perspectivity sending the aligned epipole to the ideal point , chosen so its Jacobian at the origin equals the identity to first order.
maps . After perspective division, , which for expands as — a rigid map to first order near the origin. The rectifying homography for image 2 is
Writing , a homography of image 1 preserves epipolar-line correspondence with iff for some free vector (Theorem 4.5). When sends the epipole to exactly, this family collapses (Corollary 4.6) to with restricted to a 3-parameter affine form.
Affine restriction of the epipolar-line-preserving family (Corollary 4.6), leaving the -coordinate of the transformed point unchanged.
The free parameters are fixed by ordinary linear least squares. Let and denote the matched points transformed by the pre-affine map and by , with and their inhomogeneous coordinates. Because leaves the -coordinate unchanged, the -residual is constant and drops out of the minimisation; only
is minimised over . Restricting to the affine subgroup is what keeps this fit linear — a general projective does not admit a closed-form least-squares solution.
A projective map is quasi-affine with respect to a convex view window if does not meet the line at infinity : no point of is sent to infinity or behind the camera by . Violating this condition tears the resampled image into disconnected pieces.
If the epipole does not lie in the view window of image 2, a matching from the Theorem 4.5 family is quasi-affine on some convex subwindow of image 1 (Theorem 5.7) — not necessarily on all of .
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′"]
- Estimate from the correspondences by a linear least-squares method if not already known, and factor it as with the epipole in image 2.
- Choose a reference point in image 2 and build , the translation sending to the origin.
- Build , the rotation about the origin that aligns the translated epipole with the -axis, and read off , its distance from the origin.
- Build from and form .
- Verify that is quasi-affine on . If the epipole lies inside , shrink the view window until it excludes , or abandon this construction for a different projectivity — a new reference point cannot help, since sends that same in-window epipole to infinity regardless of where the window is centred, so still meets the line at infinity.
- Transform the matched points by (image 1) and (image 2), and fit of by linear least squares.
- Form and confirm it is quasi-affine on some convex subwindow .
- Resample both images through and 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 in the number of correspondences for the affine fit, plus for the final per-pixel resampling of both images; no iterative optimisation is required beyond the optional nonlinear refinement of itself.
- Theorem 5.7 guarantees quasi-affinity of the matching transform only on a convex subwindow of the first image, not necessarily on the whole of ; part of can remain unusable if it corresponds to points outside .
- If the epipole lies inside the view window — forward or near-forward motion — Theorem 5.7 does not apply, since its hypothesis requires the epipole to lie outside ; 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 as a rigid map holds for ; as the epipole approaches the view window, shrinks, the approximation degrades, and the mapped coordinates grow without bound near .
- The rectified pair carries no metric information: reconstruction from 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
- R. I. Hartley. Theory and Practice of Projective Rectification. International Journal of Computer Vision, 1999. pdf
- H. C. Longuet-Higgins. A Computer Algorithm for Reconstructing a Scene from Two Projections. Nature 293, 1981. doi.org/10.1038/293133a0