paulbebear.com

Your face in 10 layers

Your face, rebuilt from layers. A photo is a grid of numbers: a . One piece of maths, the , splits any matrix into layers ranked by importance. Stack the first few and your face appears from the blur.

loading
Use your own face

Your photo never leaves this device. Everything runs in this browser: no upload, nothing stored. Close the tab and it's gone.

Or try a painting

Rebuild it, one layer at a time

On the left, the picture as the computer sees it: a grid of numbers. On the right, the same picture rebuilt from only the first k layers. Drag the slider and watch it sharpen. Each layer costs one column of numbers, one row and one weight, so a few layers take far fewer numbers than the whole grid.

original
k = 1
Splitting into layers…
1layer of 205
Numbers stored–

kept–

Start at k = 1 and slide right. Tap the button the moment you recognise who it is.

"Save image" makes a picture card on this device. Nothing is uploaded.

What one layer looks like

Every layer is the simplest possible picture: one column of numbers (the teal and amber strip down the left) times one row of numbers (the strip along the top). So every row of a layer is the same pattern, just brighter or dimmer. One such pattern can't draw a face. Add them up, biggest first, and it appears. These are the first eight of the greyscale version.

layer 1

Layer 1

positive number negative number In layers 2 to 8, mid-grey is zero, light adds brightness, dark takes it away. Contrast is boosted so you can see them.

Layer 1 is a blurry average of the whole picture. Each later layer is a correction: it adds light in some places and takes it away in others. The weight in front of each layer, its σ, says how big that correction is. They always come out sorted, biggest first, and every layer is to the others: none repeats what another already said.

Why a few layers carry most of a face

This chart is the importance of each layer: its singular value σ, relative to the first. The scale is logarithmic: each gridline is ten times smaller than the one above. A face falls off a cliff. A few big layers, then a long tail of tiny ones you can drop without noticing. Random noise is different: after its first layer, which is just its average grey, every layer matters about as much as the next. There's no shortcut, so noise can't be compressed.

Your image Random noise, same size k, from the slider (tap the chart to move it)
Layers kept
–
Your image: detail kept beyond layer 1
–
Share of the energy in layers 2 and up that the first k layers keep.
Noise: detail kept beyond layer 1
–
Same measure for noise. It grows in a straight-ish line: every layer is worth about the same.
noise
k = 1

The same number of layers on random noise. It never "appears": it just gets slowly less wrong. Pick in the hero to try it at full size.

A matrix is a move

So far a matrix has been a picture. It is also an instruction: a way to move every point of a flat plane. A 2×2 matrix sends the arrow along the bottom edge (teal) to its first column, and the arrow up the side (amber) to its second. Everything else, your picture included, comes along for the ride. Drag the arrow tips, drag the numbers sideways, or type them.

drag the arrow tips

What it does to area

Every move is rotate, stretch, rotate

Here is the surprising part. Whatever numbers you put in, the move can be done in three simple steps: turn the picture, stretch it along the two straight axes, turn it again. That's the SVD of this little matrix. The circle shows it best: every matrix turns a circle into an ellipse, and the stretches are the ellipse's two half-widths, the .

step 3 of 3

In symbols, M = UΣVT: VT is the first turn, Σ the stretch, U the second turn. For a photo it's the same idea with hundreds of dimensions instead of two. If the matrix flips the picture, the flip is shown here as a negative stretch, to keep both turns as pure turns.

Where this is used

The SVD is one of the workhorses of data science. Wherever data sits in a table, the first few layers often carry the signal and the rest carry noise. Some honest examples, and one common myth.

Statistics

Principal component analysis (PCA)

Put a dataset in a table, one row per person and one column per measurement, and subtract each column's average. The SVD of that table gives its : the directions where the data varies most, ranked. It's how researchers squeeze 20,000 gene readings or 100 survey answers into a 2D map you can actually look at.

Jolliffe and Cadima (2016), Phil. Trans. R. Soc. A.

Face recognition, 1987 to 1991

Eigenfaces

This page splits one picture into layers. Eigenfaces did it across many: stack hundreds of face photos as rows of a table and the SVD finds the shared "face ingredients". Sirovich and Kirby showed in 1987 that a few dozen of them describe a face well; Turk and Pentland used them for recognition in 1991. Today's face recognition doesn't work this way: it uses deep neural networks. Eigenfaces is the classic stepping stone.

Sirovich and Kirby (1987), JOSA A; Turk and Pentland (1991), J. Cognitive Neuroscience.

Recommendations

The Netflix Prize

In 2006 Netflix offered $1 million to anyone who could beat its film recommender by 10%. Picture a table of users and films with each star rating filled in. The big idea that spread through the contest: explain that table with a few hidden layers, like "how much of a thriller is it" and "how much does this person like thrillers". Strictly, it's an SVD-like factorisation, because most of the table is empty and a true SVD needs every cell. A team won in 2009 by blending hundreds of models. Netflix said it put the two strongest early models, a factorisation and another method, into production, but not the full winning blend.

Koren, Bell and Volinsky (2009), IEEE Computer; Funk (2006), "Try this at home"; Netflix (2012), tech blog.

Signal processing

Removing noise

If the signal lives in a few big layers and noise is spread evenly across all of them (the flat amber line above), then throwing away the small layers throws away mostly noise. Gavish and Donoho worked out exactly where to cut: for an n×n table with noise of known size σ, keep the singular values above (4/√3)·√n·σ and drop the rest. Used in sensors, medical imaging and data cleaning. For everyday photos, dedicated denoisers do better.

Gavish and Donoho (2014), IEEE Trans. Information Theory.

Myth

"This is how JPEG works"

It isn't. JPEG cuts a photo into 8×8 blocks and uses the . That uses the same fixed set of wave patterns for every photo, so the patterns never need to be stored. The SVD finds the best patterns for your photo, but then you must store them: that's the k×(m+n+1) on the meter above, and it's why the SVD loses at compression.

Wallace (1992), "The JPEG still picture compression standard".

The guarantee

Why the first k layers are the best k

The Eckart–Young theorem (1936) says that no picture of k is closer to the original than the first k SVD layers, measured by the sum of squared pixel errors. So the slider above isn't just one way to compress: by that measure it's the best way with k layers.

Eckart and Young (1936), Psychometrika.

How it works

A photo is a matrix

A greyscale photo is a grid of brightness numbers, one per , from 0 (black) to 1 (white). That grid is a , with m rows and n columns. A colour photo is three of them, one each for red, green and blue. This page shrinks your photo so its long side is 256 pixels, then works on each colour separately (or on one grey matrix, with "Grey").

Any matrix splits into layers

The singular value decomposition says that any matrix A, of any shape, can be written as

Ayour image, m×n
=
Ucolumns: patterns down the image
Σweights, biggest first
VTrows: patterns across the image

U and V are : their columns are at right angles to each other and have length 1, so they only turn things, never stretch them. All the stretching is in Σ, a diagonal list of σ1 ≥ σ2 ≥ … ≥ 0. Multiply it out and the same thing reads as a sum of layers:

A
=
σ1u1v1Tlayer 1
+
σ2u2v2Tlayer 2
+
…
+
σrurvrTlayer r

Each uiviT is a column times a row: a . The number of layers, r, is the of the matrix. For a photo it's almost always the length of the shorter side: 205 for the paintings here.

Counting the numbers

The full image stores m×n numbers. Keeping k layers stores k columns of m numbers, k rows of n numbers and k weights: k×(m+n+1). For a 256×205 picture, 10 layers is 4,620 numbers instead of 52,480, under 9%. Keep every layer and you store more than the image itself, which is one reason nobody compresses photos this way (see the JPEG card).

Energy

Square every pixel value and add them up: that's the image's . Because the layers are orthogonal, it splits exactly: layer i holds σi2 of it. So "energy kept" on the meter is σ12 + … + σk2 divided by the total. The part left over is exactly the squared error of the rebuilt picture. Energy is not the same as "looks right": layer 1 alone usually holds most of the energy (about 80% for the Vermeer), because it carries the overall brightness, yet it looks like a smudge. Your eyes care about edges, which live in the small layers.

How the page computes it

The decomposition runs in a background thread (a Web Worker) so the page never freezes. It uses the classic Golub–Kahan–Reinsch algorithm, ported from JAMA, a public-domain maths library from NIST. It takes a fraction of a second on a laptop and a second or two on a phone, for four matrices: red, green, blue and grey. After that, moving the slider only adds or removes layers from a running total, so it stays smooth. Your photo, its numbers and the layers stay in this tab's memory and vanish when you close it.

Words used on this page

Underlined words can also be tapped anywhere on the page.

Sources and credits

Every reference, sample image and piece of code behind this page, what it's used for and its licence.

Sample images

Johannes Vermeer, Girl with a Pearl Earring (about 1665)

Mauritshuis, The Hague. Photograph via Wikimedia Commons.

Used for: the default sample and the page thumbnail. Cropped and downscaled.

Licence: public domain (faithful reproduction of a public-domain painting).

Leonardo da Vinci, Mona Lisa (1503 to 1506)

Musée du Louvre, Paris. Photograph by the C2RMF, retouched, via Wikimedia Commons.

Used for: a sample image. Cropped and downscaled.

Licence: public domain.

Vincent van Gogh, Self-Portrait (1887)

Art Institute of Chicago. Photograph via Google Arts & Culture and Wikimedia Commons.

Used for: a sample image. Cropped and downscaled.

Licence: public domain.

Random noise

Used for: the noise sample and the comparison curve. Generated in your browser from a fixed random seed.

Licence: made for this page.

Maths and algorithm

JAMA: A Java Matrix Package, version 1.0.3

Hicklin, Moler, Webb, Boisvert, Miller, Pozo and Remington; The MathWorks and NIST.

Used for: the SVD algorithm, ported line by line to JavaScript in svd-worker.js, with one added guard for numbers too small for the computer to divide by. Checked against NumPy: singular values agree to about 15 decimal places.

Licence: released to the public domain by its authors.

Golub and Reinsch (1970)

"Singular value decomposition and least squares solutions", Numerische Mathematik 14, 403–420. Builds on Golub and Kahan (1965), SIAM J. Numerical Analysis.

Used for: the algorithm JAMA implements.

Licence: published papers, cited here.

Eckart and Young (1936)

"The approximation of one matrix by another of lower rank", Psychometrika 1, 211–218.

Used for: the claim that the first k layers are the best rank-k picture.

Licence: published paper, cited here.

Strang, Introduction to Linear Algebra

Gilbert Strang, Wellesley-Cambridge Press, 6th edition (2023), chapter 7.

Used for: the plain-language framing of the SVD as rotate, stretch, rotate.

Licence: book, cited here.

Where it's used

Jolliffe and Cadima (2016)

"Principal component analysis: a review and recent developments", Phil. Trans. R. Soc. A 374, 20150202.

Used for: PCA and its link to the SVD.

Licence: open-access paper, cited here.

Sirovich and Kirby (1987)

"Low-dimensional procedure for the characterization of human faces", JOSA A 4(3), 519–524.

Used for: the eigenfaces card.

Licence: published paper, cited here.

Turk and Pentland (1991)

"Eigenfaces for recognition", Journal of Cognitive Neuroscience 3(1), 71–86.

Used for: the eigenfaces card.

Licence: published paper, cited here.

Koren, Bell and Volinsky (2009)

"Matrix factorization techniques for recommender systems", IEEE Computer 42(8), 30–37.

Used for: the Netflix Prize card.

Licence: published paper, cited here.

Simon Funk (2006), "Netflix Update: Try This at Home"

Used for: the SVD-style factorisation that spread through the Netflix Prize.

Licence: blog post, cited here.

Amatriain and Basilico (2012), Netflix Technology Blog

"Netflix Recommendations: Beyond the 5 stars (Part 1)".

Used for: what Netflix did and didn't put into production.

Licence: blog post, cited here.

Gavish and Donoho (2014)

"The optimal hard threshold for singular values is 4/√3", IEEE Trans. Information Theory 60(8), 5040–5053.

Used for: the noise removal card.

Licence: published paper, cited here.

Wallace (1992)

"The JPEG still picture compression standard", IEEE Trans. Consumer Electronics 38(1), xviii–xxxiv. The standard itself is ITU-T T.81.

Used for: JPEG uses the DCT, not the SVD.

Licence: published paper and standard, cited here.

Type

Geist and Geist Mono

Used for: the typefaces, served by Google Fonts.

Licence: SIL Open Font License 1.1.

No other libraries

Everything else on the page (the charts, the matrix playground, the picture card) is plain JavaScript written for it.

Licence: the page's own code, © Paul Bébéar.

Method. Your image is drawn into a canvas with its long side at most 256 pixels and read as numbers from 0 to 1 per colour channel. Grey is 0.299 red + 0.587 green + 0.114 blue (the ITU-R BT.601 weights). Each channel's full SVD is computed in double precision in a Web Worker, then kept in single precision for rebuilding. The colour rebuild adds the first k layers of red, green and blue separately; energy in colour mode sums all three channels. No mean is subtracted, so layer 1 carries the overall brightness. "Numbers stored" counts k×(m+n+1) per channel against m×n; it ignores how many bits each number would need. The noise comparison is uniform random grey of the same size as your image.

Privacy. Your photo is read by this page in your browser and never sent anywhere: there is no server code behind this page. Nothing is saved, not even on your device, unless you press "Save image". Analytics records page views only. Version 1, October 2026.

← → step · R record · Esc leave