Skip to content
AI360Xpert
Beta

Compressive Sensing

Photos take millions of pixels then JPEG throws most away. Compressive sensing skips the waste: measure a few smart random combinations and reconstruct the full image from its sparsity.

Four random measurements recover two spikes exactly where least squares would smear energy across all eight positions
Four random measurements recover two spikes exactly where least squares would smear energy across all eight positions

Why Does This Exist?

Sample-then-discard is everywhere: cameras grab megapixels JPEG shrinks hundredfold, MRI fills k-space for hours to keep a fraction. Where sampling is slow, expensive, or irradiating (MRI scan time, terahertz cost, single-photon budgets), oversampling first and compressing later wastes the scarcest resource.

Compressive sensing measures compressively from the start: mm random projections with mm far below the pixel count nn, then reconstructs by seeking the sparsest signal consistent with the measurements. MRI acceleration, single-pixel cameras, and lensless imagers run on it. The software-camera sibling is computational photography; the map is alternative sensing.

The one idea you need first. A signal is kk-sparse if only kk of its nn coefficients are nonzero in some basis (wavelets for photos). L1 minimization finds the measurement-consistent signal with the smallest absolute sum — and that sum lightly penalizes spread-out energy while tolerating concentrated spikes, so the optimum lands on few nonzeros. L2 instead spreads energy everywhere; the norm choice is the algorithm.

Think of It Like This

A census by representative households

Knocking every door counts the town exactly and costs a fortune. Polling works when households represent blocks: ask a few hundred well-chosen doors, weight by block, and estimate the town within points. The trick is choosing doors whose answers constrain the whole — random spread, not one street.

Compressive measurements are those doors: random projections, each mixing the whole signal, so every answer constrains every pixel. Sparsity is the town's simplicity (few block types, smoothly varying). L1 is the weighting that refuses to invent households the answers do not require.

The analogy stops at the guarantee: polls err gracefully, while sensing recovery is exact-or-broken depending on matrix conditions no pollster checks.

How It Actually Works

Model y=Φxy = \Phi x with Φ\Phi an m×nm \times n random matrix (m≪nm \ll n). Assume x=Ψsx = \Psi s with ss kk-sparse. Solve min⁡∥s∥1\min \lVert s\rVert_1 subject to y=ΦΨsy = \Phi\Psi s via iterative thresholding or linear programming. Theory (restricted isometry: ΦΨ\Phi\Psi nearly preserves lengths of sparse vectors) says m∼klog⁡(n/k)m \sim k\log(n/k) measurements suffice — far below Nyquist's nn. Practice designs Φ\Phi in hardware (coded apertures, micromirror patterns, k-space trajectories) and Ψ\Psi from the domain (wavelets, gradients, learned dictionaries).

Recovery is iterative and slow next to a shutter click; that compute bill is the standing tradeoff.

Worked example

Signal length n=8n = 8 with k=2k = 2 nonzeros (values 33 at position 22, −2-2 at position 55). Measurement budget m≈klog⁡(n/k)=2ln⁡(4)≈2×1.39=2.77m \approx k\log(n/k) = 2\ln(4) \approx 2 \times 1.39 = 2.77, so 33–44 projections should suffice — half the Nyquist 88.

Soft thresholding shows the sparsity mechanism on a noisy coefficient vector [0.8,−0.1,0.05][0.8, -0.1, 0.05] at threshold 0.20.2: survivors keep magnitude-minus-threshold with sign (0.8→0.60.8 \to 0.6), and anything below dies (−0.1→0-0.1 \to 0, 0.05→00.05 \to 0). Repeated inside iterations, this operator is what concentrates energy onto the true spikes while L2 would shrink everything proportionally and smear on.

Code

The point of this snippet is the concentration operator: thresholding kills small fry and keeps spikes standing.

def soft_threshold(values: list, lam: float) -> list:    out = []    for v in values:  # shrink toward zero, kill below lambda        kept = abs(v) - lam        out.append(0.0 if kept <= 0 else (1.0 if v > 0 else -1.0) * kept)    return out

print(soft_threshold([0.8, -0.1, 0.05], 0.2))  # -> [0.6, 0.0, 0.0]

Watch Out For

RIP certificates nobody can check

Recovery theorems assume restricted isometry constants that are NP-hard to verify for any given matrix. Deployed systems use random matrices that satisfy RIP with high probability — probability, not a certificate for this device, this scene.

Validate empirically per setup: phantom studies with known sparse targets at the intended mm. Theory sets the budget formula; measurement sets the truth.

Reconstruction latency versus sensor speed

Iterative L1 solvers take seconds to minutes per frame while the "fast" sensor streams measurements in milliseconds. Single-pixel cameras demo beautifully on stills and stall on video, because the compute never kept up with the optics.

Budget reconstruction with the sensor: learned unrolled solvers and GPUs close part of the gap, but quote end-to-end latency (measure plus solve), never sensor rate alone.

The Quick Version

  • Compressive sensing measures m≪nm \ll n random projections and reconstructs via sparsity-seeking L1.
  • The worked fixture budgets 33–44 measurements for 22 spikes in length 88, versus 88 Nyquist samples.
  • Soft thresholding concentrates energy on true spikes where L2 would smear it everywhere.
  • RIP guarantees are probabilistic for real matrices, so validate per setup with known targets.
  • Quote measure-plus-solve latency: iterative reconstruction lags far behind sensor rates.