← All Base Form Math projects
BM-08NOT STARTEDBASE FORM · LINEAR ALGEBRAMATHPYTHON

Photo shrinker

Compress images with your own SVD and drag a slider to trade file size for quality, live.

EST.6 h
REWARD+100 XP
AFTERoriginal

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
singular values; quality at 10% size
GOAL · values within 1e-4; report PSNR vs JPEG
numpy.linalg.svd · JPEG measured locally—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

A grayscale photo is a matrix of brightness values. This project compresses it by writing that matrix as a sum of simple layers and keeping only the most important ones. Then you put a slider on it and watch the photo sharpen as you add layers.

The tool is the singular value decomposition. Any m×nm \times n matrix AA can be written as

A=UΣV⊤=∑i=1rσi uivi⊤A = U \Sigma V^\top = \sum_{i=1}^{r} \sigma_i \, u_i v_i^\top

Each term σiuivi⊤\sigma_i u_i v_i^\top is an outer product: a column times a row, one layer with the same shape as the photo. The singular values σ1≥σ2≥⋯≥0\sigma_1 \ge \sigma_2 \ge \dots \ge 0 say how much each layer matters. Keep the first kk and you have a rank-kk approximation. It stores k(m+n+1)k(m + n + 1) numbers instead of mnmn, and no other rank-kk matrix is closer to the original.

You compute it with tools you already have. The right singular vectors viv_i are the eigenvectors of A⊤AA^\top A, and its eigenvalues are σi2\sigma_i^2. So the power iteration from BM-07 finds v1v_1, and u1=Av1/σ1u_1 = A v_1 / \sigma_1 follows.

VISUALFig. 1
rank 1 error 42% stores 17 numbers rank 2 error 33% stores 34 numbers rank 3 error 21% stores 51 numbers rank 6 error 0% stores 102 numbers
An 8 × 8 image rebuilt from its SVD. Rank 3 already shows the shape; rank 6 is exact but stores more numbers than the 64 pixels. Why it's here: Shows the trade the slider makes: each layer adds detail and costs m + n + 1 numbers.
HINT · OBJECTIVE 3
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 6
Stuck? Hints stay hidden until you ask.

DATA · your photos

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. Your top 50 singular values match numpy.linalg.svd within 1e-4, recorded with `python tools/mlarena.py record BM-08 "<largest difference>"`.
  2. A table with your PSNR and JPEG's PSNR at 10% size for at least three photos, and one sentence on which wins and why.
  3. The slider redraws in well under a second at 512 pixels wide, because nothing is recomputed except the sum of k layers.

Side quests

Plot the singular values on a log scale for a photo, a screenshot of text and random noise. Explain why noise barely compresses.
Split the image into 8×8 or 32×32 blocks and compress each block separately. Compare PSNR at the same size.

Terms in plain words

Singular value decomposition (SVD)
Any matrix can be written as A = UΣVᵀ, where U and V have perpendicular unit columns and Σ is diagonal with non-negative entries in decreasing order.
Singular value
One diagonal entry of Σ. It says how much that layer of the image contributes; most photos have a few big ones and a long tail of small ones.
Low-rank approximation
Keep only the first k layers of the SVD. By the Eckart-Young theorem, no other rank-k matrix is closer to A.
Rank
The number of independent rows (or columns) in a matrix. A rank-k image is a sum of k outer products.
Deflation
After finding the top eigenvector, remove its part from the matrix so power iteration finds the next one.