Brief
You will build a photo editor that knows only one trick: multiply by a matrix. Rotate, zoom, shear, mirror and shift all become 3×3 matrices, and a chain of edits is just their product. Undo is the inverse matrix.
The trick for shifting is homogeneous coordinates. A pixel position becomes , and an edit is
The top-left block rotates, scales, shears or mirrors. The last column shifts.
The new idea is the determinant. For the block above it is , and it tells you how much the edit scales area. A determinant of 2 doubles area. A negative determinant means the picture is mirrored. A determinant of 0 squashes the photo onto a line, and no inverse can bring it back. When the determinant is not zero, the inverse undoes the edit, and undoes a chain in reverse order.
One practical surprise: you warp a photo backwards. Pushing each input pixel forward leaves holes. Instead, loop over output pixels, apply to ask "where did this one come from?", and blend the nearest input pixels.
DATA · your photos
Objectives
Read-only. Log in to update progress.
VICTORY CONDITIONS
- Every one of the 10 edits scores PSNR ≥ 40 dB against scipy.ndimage.affine_transform (order=1), recorded with `python tools/mlarena.py record BM-03 "<lowest PSNR> dB"`.
- Your determinant and inverse match NumPy within 1e-9 for every matrix you use.
- Undo works on a chain of at least three edits, and the README shows before, after and undone photos side by side.
Side quests
Terms in plain words
- Homogeneous coordinates
- Write a 2-D point (x, y) as (x, y, 1). Then a 3×3 matrix can rotate, scale and also shift the point with one multiplication.
- Determinant
- One number from a square matrix that says how much it scales area. Negative means the image is mirrored; zero means the map squashes everything flat.
- Inverse matrix
- The matrix that undoes another one, so that M⁻¹M is the identity. It exists only when the determinant is not zero.
- Bilinear interpolation
- When a pixel lands between four source pixels, blend those four, weighted by how close each one is.
- PSNR
- Peak signal-to-noise ratio, a score in decibels for how close two images are. Higher is closer; 40 dB means the difference is hard to see.