Classical Computer Vision: Geometry and Matching
Develop geometric understanding for matching, homographies, epipolar geometry, and multi-view reconstruction fundamentals.
Content
Homographies and Planar Transformations
Versions:
Watch & Learn
AI-discovered learning video
Watch & Learn
AI-discovered learning video
Homographies and Planar Transformations: When Flat Worlds Make Perfect Sense
You gathered a small army of keypoints, matched them bravely across images, and now you want the whole scene to line up like it respects authority. Enter: the homography — a 3x3 matrix with main-character energy.
We’ve already scouted the terrain: robust features, descriptors, and alignment. Now we’re upgrading from “match a few points” to “warp the entire image like a seasoned reality-bender” — but only when the world is basically flat or the camera just rotated. This is the geometry glue that makes panoramas seamless, posters look frontal, and AR stickers cling to tables like they pay rent.
What Is a Homography (and Why Should You Care)?
- A homography is a projective transformation between two images that map points on the same plane to each other.
- In homogeneous coordinates, a point x in image 1 maps to x′ in image 2 via: x′ ~ H x, where H is a 3x3 matrix with 8 degrees of freedom (scale is arbitrary).
- It’s the right tool when either:
- The scene is planar (e.g., a page, billboard, floor), or
- The camera undergoes pure rotation (no translation), i.e., capturing a panorama from a fixed center.
Homographies are to planes what playlists are to moods: one perfect mapping that makes everything coherent.
Geometry, But Make It Intuitive
- Homographies preserve straight lines but not lengths or angles. That’s why tilting a rectangle turns it into a keystone shape, yet lines remain lines.
- Under the hood, homographies live in projective geometry. They convert your “uhh that looks skewed” into a clean, rectified view where parallel lines may not stay parallel, but they stay straight.
- If you love camera matrices (we see you), the plane-induced homography between calibrated views is:
H = K2 (R - t n^T / d) K1^{-1}
- K1, K2: intrinsics of the two cameras
- R, t: relative rotation and translation
- n, d: normal of the plane and its distance in camera 1’s frame
Special case delight:
- If t = 0 (pure rotation), H = K2 R K1^{-1}. You can stitch panoramas like a boss.
From Features to H: Your Matches Grow Up
Remember our previous adventures: SIFT/ORB/whatever gave us correspondences; we evaluated robustness; we even did feature-based alignment. Now we pool many good matches into a single model that explains an entire planar region. That’s mid-level representation energy: compress a swarm of keypoints into one geometric sentence.
Estimation 101: DLT (Direct Linear Transform)
- Minimal sample: 4 non-collinear point correspondences.
- Practical recipe (with conditioning because we like stable numerics):
# Normalize points in both images (Hartley’s trick)
# - translate to centroid, scale so mean distance ≈ sqrt(2)
T1, T2 = normalize(points1), normalize(points2)
# Build A from correspondences (xi ↔ x'i)
# Each pair contributes two rows enforcing x' × (H x) = 0
for (x, y) ↔ (x', y'):
A.append([-x, -y, -1, 0, 0, 0, x*x', y*x', x'])
A.append([ 0, 0, 0, -x, -y, -1, x*y', y*y', y'])
# Solve Ah = 0 via SVD → h = last singular vector
h = svd(A).V[:, -1]
Hn = reshape(h, 3x3)
# Denormalize
H = T2^{-1} Hn T1
# Optional: scale so H[2,2] = 1 or det(R-part) positive
- Error metrics: symmetric transfer error (distance of x′ to Hx and x to H^{-1}x′), or Sampson approximation for a first-order feel.
Make It Robust: RANSAC Like You Mean It
bestH, bestInliers = None, []
for i in 1..N:
sample 4 matches → H_i via DLT
inliers = {j | symmetric_error(H_i, match_j) < τ}
if |inliers| > |bestInliers|:
bestH, bestInliers = H_i, inliers
# Refit H on all inliers (weighted least squares)
- τ ≈ 1–4 px depending on noise; scale with image resolution and descriptor uncertainty.
- Watch out for degeneracy: 4 points that are nearly collinear can gaslight your SVD.
RANSAC is that friend who says “trust no one” and still gets your group home safely.
Choosing the Right Model: Not Every Scene Is Flat
When should you use a homography vs a fundamental/essential matrix?
- If the scene is planar or the camera rotates in place: homography.
- If the scene is general 3D with translation: fundamental/essential matrix (epipolar geometry). A single H will fold space in cursed ways.
Pro tip: run both RANSACs and compare inlier counts and residuals. If H wins by a landslide, you’ve got a flat situation (or near-rotation). If F wins, back away from the flat-earther energy.
The Projective Family Drama (A Quick Comparison)
| Transform | DOF | Preserves | Use-case vibes |
|---|---|---|---|
| Euclidean | 3 | lengths, angles, orientation | pure rotations + translations in 2D |
| Similarity | 4 | angles, shape (up to scale) | scale + rotate + translate |
| Affine | 6 | parallelism, ratios on parallel lines | moderate viewpoint changes |
| Projective (Homography) | 8 | straightness, cross-ratio | extreme viewpoints, planar scenes |
- As you go down the list, you gain flexibility but lose metric niceties. Homography is the spicy one.
Applications You Actually Care About
- Image Stitching/Panoramas: Pure rotation? Compute H between overlaps, warp, then blend (feathering or multiband). Boom: vacation flex.
- Rectification: Unwarp a poster or whiteboard so text stops leaning like it’s in a noir film.
- Augmented Reality on Planes: Estimate H for a detected marker or tabletop; then render content that sticks convincingly.
- Metric upgrades: With known scene geometry (e.g., vanishing points/lines), use H to get measurements up to a similarity/affine frame.
Warping Without Tears
- Use backward mapping (inverse warp): for each pixel in the destination, map back to the source via H^{-1}; sample with bilinear interpolation.
- Handle boundaries and visibility; use masks to avoid ghosting.
- Blend overlapping regions:
- Quick: linear feathering.
- Fancy: multiband blending (pyramids) for seamless tones.
Forward warping yeets pixels into the void. Backward warping asks, “Who should live here?” and calmly populates the neighborhood.
Subtleties That Separate Wizards from Apprentices
- Normalization matters: Hartley normalization can cut your reprojection error dramatically. Unnormalized DLT is chaos.
- Collinearity is cursed: If most points lie on a line, your estimate is unstable. Diversify your correspondences.
- Check orientation: H can flip the world. If your plane orientation should be preserved, enforce it.
- Parallax is a snitch: In 3D scenes, one global H often fails. Try multiple homographies (piecewise), or switch to F + local warps.
- Consensus ≠ truth: Lots of inliers don’t guarantee the correct model if your scene has repeated patterns (hello, building windows). Use spatial consistency and descriptor ratios from earlier modules.
Threads to Previous Modules (Because Continuity Is Sexy)
- Evaluating Feature Robustness: Better invariances → better matches → fewer RANSAC iterations and a cleaner H. Illumination-invariant descriptors save you from false keystoning.
- Feature-based Alignment: We move from “align a patch or local window” to “explain the entire plane with one matrix.” It’s alignment, but upgraded to a global model.
- Feature Pooling / Mid-level: A homography is literally feature pooling into geometry: many correspondences compressed into one reliable, reusable transformation.
Quick Mental Checklist (Before You Hit Run)
- Is the scene mainly planar or the camera rotating? If unsure, test H vs F.
- Do I have ≥ 4 solid, non-collinear matches? Prefer 20–200 for robust RANSAC.
- Did I normalize points? If not, do that before SVD.
- Threshold tuned? Use data-driven tau and maybe MSAC/MLESAC for smarter scoring.
- Verified with symmetric transfer error and visual overlays? Trust, but verify.
TL;DR and One Big Thought
- A homography is a 3x3 projective transform linking two views of the same plane (or pure rotation).
- Estimate via normalized DLT + RANSAC; refine on inliers.
- Great for stitching, rectification, and AR-on-planes. Bad for heavy parallax.
- It preserves lines, not distances; respect the geometry’s limits.
Big insight: Homographies turn a chaotic crowd of features into a single geometric narrative. When the world is flat (enough), one matrix says it all.
Now go warp responsibly. The plane is flat — only in the ways that help you build cool stuff.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!