liveBook · Manning

Projective transformation

As explained in Geometry for Programmers

A projective transformation is a mapping of projective-space points represented by homogeneous linear coordinates that preserves incidence but may not preserve parallelism.

A projective transformation maps points using homogeneous coordinates. Its practical payoff is that translation, rotation, scaling, shear, and perspective can share one matrix-based representation. Unlike affine transformations, it need not preserve parallel lines: a square can become an arbitrary convex quadrilateral. section 4.2.3 section 4.3.2

In homogeneous form, a point is represented by coordinates such as (x, y, w), where scaling every coordinate describes the same projective point: (1, 0, 1) and (2, 0, 2) coincide. A projective matrix transforms these coordinates in one multiplication, then the resulting ratio recovers Euclidean position when w is nonzero. section 4.3.2 section 4.7

This single representation makes several useful operations uniform:

  • Compose several transformations by multiplying their matrices, producing one transformation matrix rather than applying each step per point. section 4.3.3
  • Undo a transformation with an inverse; homogeneous-coordinate equivalence permits an inverse transformation wider than one particular inverse matrix. section 4.7
  • Build a custom four-point transformation by solving linear equations for matrix coefficients. section 4.2.3 section 4.7
  • Extend the same approach to 3D with four-coordinate points and 4 × 4 matrices. section 4.3.2

Flattening a photographed page

To undo a page’s perspective in a camera image, select its four photographed corners and map a target rectangle into that quadrilateral. For each target pixel, transform backward to locate the source pixel color. Using a standard unit square as an intermediate step makes the coefficient equations smaller; the direction matters because sampling needs target-to-source coordinates. section 4.4.1

Figure 4.20 Before and after: undoing the natural perspective in a picture
04-20

The before-and-after image makes the core visual result concrete: a perspective-distorted photograph is remapped into a flat rectangular view. section 4.4.1

Projective transformations are powerful, but not automatically the best choice. They can reduce duplicated code, combine stages, and support fast robust workflows; when a simpler transformation meets the need, it may be faster and easier to implement. section 4.0 section 4.4.3

How Geometry for Programmers covers it

How deep it goes
Develops homogeneous matrix form, composition, inversion, and four-point coefficient construction rather than treating transformations as framework calls.
Examples
Uses square-to-quadrilateral mappings, composed rectangle transformations, a phone scanner, picking, and 3D five-point transformations.
What you can do after
Build it from scratch by composing matrices, deriving four-point mappings, and applying inverse mappings for image sampling.
How it connects
Connects homogeneous coordinates, projective space, matrix multiplication, affine transformations, perspective, and inverse transformations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.