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.
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: random projections with far below the pixel count , 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 -sparse if only of its 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 with an random matrix (). Assume with -sparse. Solve subject to via iterative thresholding or linear programming. Theory (restricted isometry: nearly preserves lengths of sparse vectors) says measurements suffice — far below Nyquist's . Practice designs in hardware (coded apertures, micromirror patterns, k-space trajectories) and 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 with nonzeros (values at position , at position ). Measurement budget , so – projections should suffice — half the Nyquist .
Soft thresholding shows the sparsity mechanism on a noisy coefficient vector at threshold : survivors keep magnitude-minus-threshold with sign (), and anything below dies (, ). 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 . 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 random projections and reconstructs via sparsity-seeking L1.
- The worked fixture budgets – measurements for spikes in length , versus 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.