From Photon to Pixel

The Long Way from Light to JPEG

A plain-language, code-first tour of the RAW-to-JPEG pipeline — from photon to pixel.

Vijay Mathew — a companion book to Lumen, the photo editor.

Every algorithm in plain, explicit code. Every figure generated by the book's own code, against a simulated camera whose ground truth is always known. Eleven chapters and three appendices — the whole way, from photon to JPEG.

  1. 0SetupWhy this book, the toolkit, and the contract every line of code in it obeys.
  2. 1The Simulated Camera SystemScenes as spectra, fictional lenses, a noisy sensor — ground truth for the whole book.
  3. 2From Photons to a Bayer ArrayExposure, noise, black level, and why the sensor sees a mosaic instead of a picture.
  4. 3White Balance Comes FirstUndoing the illuminant on the raw mosaic — and proving the pipeline's order matters.
  5. 4DemosaicingFrom one value per pixel to three: bilinear, edge-aware, and AHD, measured against truth.
  6. 5Getting the Color RightCamera RGB is not a color space; the matrix that maps it toward one, derived from spectral ground truth.
  7. 6Undoing the LensVignetting, chromatic aberration, and distortion, inverted from known coefficients.
  8. 7ToneGamma, curves, highlight reconstruction, and local tone mapping.
  9. 8Detail and NoiseSharpening and noise reduction, from unsharp mask to Non-Local Means.
  10. 9Output EncodingResampling, chroma subsampling, and a from-scratch JPEG encoder.
  11. 10Closing the LoopA real raw file through the reader's own pipeline — and why no two renderings agree.
  12. AThe pxp PackageThe simulated camera and pipeline as a standalone package — API reference.
  13. BGlossaryOECF, CFA, PSF, gamut, and the rest of the pipeline's vocabulary.
  14. CFurther ReadingSources by pipeline stage — split into 'safe to reimplement' and 'read for understanding only'.