Skip to main content
Open In Colab This section was written by Kaushik Kachireddy (pull request #74), with help from an AI coding agent (Claude Code) on the code. It reproduces the ideas of Chapter 38 of Foundations of Computer Vision by Antonio Torralba, Phillip Isola, and William T. Freeman. This section builds on homogeneous coordinates and applies them to lines and to image pixels. Three ideas drive it:
  1. The transformation matrices from that section act on whole images, and the way you apply them to a pixel grid decides whether the result has holes.
  2. Lines and points are dual under the cross product in homogeneous form: joining two points and intersecting two lines are the same operation.
  3. Implicit image representations (SIREN-style networks that map (x,y)→intensity(x,y)\to \text{intensity}) let you read an image at any sub-pixel location without an interpolation kernel, so a geometric transformation becomes an evaluation at inverse-transformed coordinates.
The figures are regenerated in PyTorch. One of them reframes warping as a 1D convolution on coordinates, and the last one replaces the pixel grid with a neural network.

Heterogeneous and homogeneous coordinates

The homogeneous coordinates section introduced the extra coordinate. The book calls (x,y)(x, y) the heterogeneous form of a 2D point and (x,y,1)(x, y, 1) its homogeneous form. Every vector (λx,λy,λ)(\lambda x, \lambda y, \lambda) with λ≠0\lambda \ne 0 lies on the same ray through the origin and stands for the same 2D point, and dividing by ww recovers (x,y)(x, y). The figure below draws that ray where it crosses the plane w=1w = 1. The two helpers below convert between the forms, and the rest of the section uses them.
Output from cell 5

2D image transformations

Every transformation that follows is a 3×33\times 3 matrix acting on homogeneous points. The homogeneous coordinates section sorts these matrices into rigid, similarity, affine and projective families and lists what each family keeps. Here the same matrices act on an image. The book applies them to a photograph of a clock. A wall-clock image stands in for it, and each matrix warps the actual pixels (first figure below). The second figure collects the elementary matrices in one place: translation, scaling, rotation and shear.
Output from cell 10 Output from cell 11

Geometric transformation as a convolution

If you represent an image as a set of triples {(ℓi,xi,yi)}\{(\ell_i, x_i, y_i)\} (intensity plus explicit position), then a rotation is a 1D convolution on the position channels: [x′y′]=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]⏟kernels wx,wy[xy].\begin{bmatrix}x'\\y'\end{bmatrix} = \underbrace{\begin{bmatrix}\cos\theta & -\sin\theta\\\sin\theta & \cos\theta\end{bmatrix}}_{\text{kernels } w_x, w_y} \begin{bmatrix}x\\y\end{bmatrix}. Intensity passes through untouched; only the coordinate channels are mixed, as the figure below shows. This framing makes it natural to learn warps with neural networks that operate on coordinate channels, and the rest of the section builds that bridge. Output from cell 12

Lines and points: cross-product duality

In homogeneous coordinates, a 2D line ax+by+c=0ax + by + c = 0 is the vector l=(a,b,c)\mathbf{l} = (a, b, c), and incidence is l⊤p=0\mathbf{l}^\top \mathbf{p} = 0. Two operations turn out to be the same cross product: l=p1×p2(line through two points)p=l1×l2(intersection of two lines)\begin{aligned} \mathbf{l} &= \mathbf{p}_1 \times \mathbf{p}_2 && \text{(line through two points)} \\ \mathbf{p} &= \mathbf{l}_1 \times \mathbf{l}_2 && \text{(intersection of two lines)} \end{aligned} Parallel lines intersect at a point with w=0w = 0. This is the point at infinity that the homogeneous coordinates section calls an ideal point, and it is the homogeneous form of a vanishing point. The section on 3D motion and its 2D projection uses exactly this construction. Output from cell 13

Image warping: forward and backward mapping

Applying a transformation MM to an image should give you a new image. The naive way, forward mapping, walks the input pixels, transforms each location, and writes its intensity to the nearest target pixel. That leaves holes, because an expansion spreads the input pixels too thinly to cover the target grid. The correct way, backward mapping, walks the target pixels and pulls each back through M−1M^{-1}, so every output pixel gets one well-defined intensity. A small checkerboard makes the artifacts easy to see.
Output from cell 15 Output from cell 15

Differentiable warping with Kornia

The hand-written backward_warp above shows the principle. In practice you use Kornia, a differentiable computer vision library built on PyTorch. Its warp_affine performs the same backward mapping, but with bilinear interpolation (so no nearest-neighbor aliasing), in batches, and differentiably end to end. The next cell feeds it the same matrix MM and compares the result with the hand-written version.
Output from cell 17

Implicit image representations (SIREN)

Backward mapping at sub-pixel locations needs an interpolation kernel, but only because the image is stored as a discrete grid. SIREN (Sitzmann et al., NeurIPS 2020) does away with the grid: it represents an image as a small network fθ:(x,y)→intensityf_\theta : (x, y) \to \text{intensity} whose layers use sin⁡\sin activations. The trained network is the image, and you can evaluate it at any continuous coordinate. Geometric warping then becomes a coordinate transform with no interpolation kernel: ℓ^(x,y)=fθ(M−1(x,y,1)⊤).\hat\ell(x, y) = f_\theta(M^{-1}(x, y, 1)^\top). The next cells train a small SIREN on the cameraman test image and warp it by feeding pre-transformed coordinates. The training is deliberately short: the point is to demonstrate the representation, not to maximize reconstruction quality.
Output from cell 20

Concluding remarks

The section moves forward one step at a time:
  • From matrices to warps: the transformation matrices act on images, and backward mapping applies them without leaving holes.
  • From points and lines to cross-product duality: incidence, joins, and intersections collapse into one operation. Parallel lines meet at points with w=0w=0, so vanishing points get a coordinate.
  • From a discrete grid to an implicit function: with SIREN, the image is its parameters. Warping becomes an inverse-coordinate query and interpolation kernels disappear.
Every later geometry chapter of the book (perspective projection in 39, stereo in 40, homographies in 41, single-view metrology in 42, structure from motion in 44, radiance fields in 45) reuses the homogeneous algebra and the point and line duality.
Found an error on this page? Report an issue.