CV Lab 18 · Module 7 — Geometric Transforms

Affine & Perspective Transforms

Every geometric transform is a matrix. Drag a handle, and you're editing that matrix live — the whole image follows instantly. Affine can only ever produce parallelograms; perspective can turn any quadrilateral into any other, which is exactly why document scanners need it.

A matrix bends the grid Rotation, scale, and shear are all the same idea — multiply every point's coordinates by a small matrix. This grid never stops being made of straight parallel lines under affine transforms; perspective is the one transform that can break that rule.
Source / draggable handle Transformed grid overlay Warped output image
Ready.
Live Explanation
Loading…

Drag any of the 3 cyan handles. Three points always uniquely define one affine transform — no more, no fewer.

2×3 Affine Matrix

Degrees of freedom decide what's possible

Affine — 6 unknowns, 3 points

a, b, c, d, tx, ty. Three point correspondences give exactly 6 equations — a unique solution, no more freedom left. Always maps a triangle to a triangle, a parallelogram to a parallelogram.

Perspective — 8 unknowns, 4 points

The extra 2 degrees of freedom (in the bottom row of the 3×3 matrix) are exactly what let a quadrilateral map to any other quadrilateral — including turning a trapezoid into a true rectangle.

Backward warping

Both playgrounds compute the inverse transform and, for every output pixel, ask "where did this come from in the source?" — sampled with bilinear interpolation. Forward-warping each source pixel individually would leave gaps.

Predict, then verify

You photograph a rectangular sheet of paper at a steep angle, so in the photo it looks like a trapezoid (narrower at the top). You want to digitally "flatten" it back into a true rectangle. Which transform actually works?