ML 01A · What does a 2 × 2 matrix do to a picture?
BeginnerML 01A · Linear Algebra for LearningImage lab
Description
Move the images of the two basis vectors and watch a real photograph follow. The determinant is the signed area scale, the singular values are the stretch along two perpendicular directions, and rank 1 flattens the picture onto a line.
Try this: The default is a shear: det A = 1, so areas are kept, yet σ1 = 1.62 and σ2 = 0.62 (κ = 2.62), and the unit circle becomes an ellipse. Keeping the area does not keep the shape. Now choose Stretch and slide k from 1 down through 0 to −1: at k = 0 the picture collapses onto a line (rank 1, κ = ∞), and for negative k it returns as a mirror image (det A < 0). Last, choose Projection and decide which points of the picture land on the same spot, and whether any matrix could undo that.
Explanation
Answer the prediction first, or open the explanation when you are ready.
Show the explanation
det A = 0·0 − 1·1 = −1. The absolute value 1 says areas are kept (both singular values are 1, so lengths are kept too), but the minus sign says orientation is reversed, which only a mirror does: going from Ae1 = (0, 1) to Ae2 = (1, 0) turns clockwise, while going from e1 to e2 turns counter-clockwise. A rotation always has det A = +1, and a flattening would have det A = 0. Try it: choose Reflection, k = 1 and θ = 45°.
Lab · ML 01A · What does a 2 × 2 matrix do to a picture?
Loading image…
Try this: The default is a shear: det A = 1, so areas are kept, yet σ1 = 1.62 and σ2 = 0.62 (κ = 2.62), and the unit circle becomes an ellipse. Keeping the area does not keep the shape. Now choose Stretch and slide k from 1 down through 0 to −1: at k = 0 the picture collapses onto a line (rank 1, κ = ∞), and for negative k it returns as a mirror image (det A < 0). Last, choose Projection and decide which points of the picture land on the same spot, and whether any matrix could undo that.
Real photograph: skimage.data.camera at 256 × 256 (credit below). The plane origin is the centre of the photo and 64 pixels are one unit, so the photo spans −2 to 2 in x and y, with y pointing up as in a maths figure. The right picture is made by inverse mapping: each output pixel looks up where it came from (the inverse of A applied to its position) with bilinear interpolation, and squeezed regions average several samples to avoid jagged edges; checkerboard marks places the picture does not reach. A rank-1 matrix has no inverse, so it is drawn as a line whose value at each spot is the mean of the photo along the whole line of points that collapsed onto it. Dashed cyan is the image of the unit circle, an ellipse whose semi-axes (solid cyan) have lengths σ1 and σ2; they are left out when σ1 = σ2. Controls: with u = (cos θ, sin θ), Shear is I + k·u·vT (v is u turned by 90°), Stretch is I + (k − 1)·u·uT (k = 1 is the identity), Rotation is k times a rotation by θ, Reflection is k times a mirror across the line along u, Projection is k·u·uT. Because they act along the direction θ, the two sliders move all four entries a, b, c, d. "Your own" has no restriction: drag the red and yellow tips on the right picture, or click it, or focus it and press 1 or 2 to choose an arrow and the arrow keys to move it (Shift for bigger steps). Any matrix with entries between −1.95 and 1.95 in steps of 0.01 is reachable; the sliders are switched off in that mode. Singular values use the closed-form 2 × 2 formula (Blinn), checked against numpy.linalg.svd; a matrix counts as singular when σ2 is below one billionth of σ1. Numbers are rounded to two decimals.
Method and image sources
- Gilbert Strang, Introduction to Linear Algebra, 6th ed., Wellesley-Cambridge Press, 2023 (determinant as signed area, SVD, rank)
- Jim Blinn, Consider the Lowly 2 × 2 Matrix, IEEE Computer Graphics and Applications 16(2), 82–88, 1996 (closed-form 2 × 2 SVD)
- SciPy documentation, scipy.ndimage.affine_transform (inverse mapping with bilinear interpolation; the reference for the warp)
- scikit-image test images (skimage.data): camera is CC0 by Lav Varshney; coins is from the Brooklyn Museum collection, no known copyright restrictions; astronaut is a NASA photograph in the public domain