---
title: "Coded-Aperture Camera Interactive Lab | Sandbox Physics"
description: "How can a camera with a patterned mask instead of a lens form an image?"
canonical_url: "https://sandboxphysics.com/labs/coded-aperture-camera/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/coded-aperture-camera/"
last_modified: "2026-10-27"
---

Optics 069 · Diffraction, Fourier optics, and computational imaging

# Coded-Aperture Camera

**How can a camera with a patterned mask instead of a lens form an image?** Every point in the scene casts its own shifted copy of the mask's shadow on the detector, so the recording is all those shadows piled up. Correlating it with a matched decoding pattern, such as the decoder designed for a MURA mask, sorts the copies back into a picture of the scene. Noise and the mask's finite edges leave artifacts.

Decode a sky hidden in overlapping shadows. The mask has defined openings and the counts follow Poisson statistics; see where MURA reaches its limits and where the finite mask edge makes ghosts.

> Interactive simulation: open this page in a web browser to change the parameters and run the model.

Sources are ideal, incoherent and in the far field; shadows shift by whole grid steps, and the square mask cells match the detector pixels. Counts are synthetic with a calibrated background. Diffraction and penetration through the mask are not modeled, and no real telescope data are used.

Physics tutorial

## Audit the physics of Coded-Aperture Camera

**Background** A detector cannot record negative mask weights. Open cells let light through, closed cells absorb it, and light from separate incoherent sources simply adds: $D_i\sim\operatorname{Poisson}\!\left(E\sum_q H_{iq}f_q+b\right)$. The record can hold either the noiseless expected counts or Poisson counts drawn with a fixed seed. The decoder, which has negative weights, is applied only after the data are recorded.

**Why it matters** How can a camera with a patterned mask instead of a lens form an image?

Start with the essentials

- **Focus question**: How can a camera with a patterned mask instead of a lens form an image?
- **One-sentence intuition**: For a complete 13 by 13 MURA cycle, the mask and its special decoder satisfy $A\star G=K\delta,\qquad K=84$. Cutting the physical plate short breaks the cyclic model. The correction at the origin matters, because the plain autocorrelation is not a perfect single spike.

### Core mathematical model

#### Ray geometry and the real mask size

$$
\begin{aligned}\mathbf r_M&=\mathbf r_D-a\mathbf q\\
 \tan\boldsymbol\theta_{\rm ray}&=\frac{a\mathbf q}{d}\\
 N_D&=13,\quad N_M=25\text{ or }13\\
 a&=2\,\mathrm{mm}\end{aligned}
$$

On detector images, rows count downward and columns to the right. Rays travel from the mask to the detector, so the source lies opposite to the slope of the incoming rays. The full mosaic covers every sampled shift, so nothing wraps around outside the plate. At whole-cell shifts, pixel and hole areas match.

#### Recording counts that are never negative

$$
\begin{aligned}\mu_i&=E(H\mathbf f)_i+b\\
 D_i&\sim\operatorname{Poisson}(\mu_i)\\
 \mathbb E[D_i]&=\operatorname{Var}(D_i)=\mu_i\end{aligned}
$$

Flux is given in counts per open detector pixel from a unit source. The background is uniform and calibrated; it is not fitted using the true scene. With noise off, the record is the expected count and need not be a whole number. With noise on, the Lab draws exact Poisson samples with small means and sums them for large means.

#### Decoding the recorded shadow

$$
\begin{aligned}\widehat f_q&=\frac{\sum_i G_{i-q}(D_i-b)}{EK}\\
 G_{00}&=1,\quad G_{ij}=2A_{ij}-1\ (i,j)\ne(0,0)\end{aligned}
$$

With its special origin correction, a MURA gives a single-spike point response, but only for the full cycle. Other masks use a zero-mean matched correlation scaled to an on-axis peak of one. That loses the mean sky level and keeps the sidelobes. The Lab labels this and does not claim a perfect inversion for random masks.

#### Ridge reconstruction with the finite geometry

$$
\begin{aligned}\widehat{\mathbf f}&=\arg\min_{\mathbf f}\left\|H\mathbf f-\frac{\mathbf D-b}{E}\right\|^2+\lambda\|\mathbf f\|^2\\
 \lambda&=\rho\frac{\operatorname{tr}(H^TH)}{169}\end{aligned}
$$

Conjugate gradients work with the actual finite matrix and only the recorded data. This is ridge least squares that allows negative values. It has no positivity prior, it is not the optimal Poisson likelihood and it is not a true Wiener filter. It runs at most eighty iterations. Regularization can suppress noise, and it can also bias the scene.

### Common difficulties

#### Do more holes always mean a better image?

**Typical misconception** A brighter shadow on the detector guarantees a sharper reconstruction with a higher SNR.

**Better mental model** Every opening also lets in photons from the other sources, and subtraction does not remove their shot noise. The mask pattern, the background, the structure of the scene and a correct model of the finite geometry all matter. More counts do not automatically mean more information.

### Run the experiment

1. 01

   #### Scene 1: Complete MURA shadow

   Drag the bright source in the answer key. Look at the real openings and the detector face, and watch the two shadows overlap on one detector.

   **What to observe:** The MURA has 84 open cells out of 169, and that open fraction cannot be adjusted. The open-fraction slider changes only the random design.

2. 02

   #### Scene 2: Random mask with photon noise

   Keep the exposure fixed and switch between MURA, random masks, arrays and a single pinhole. Compare how many counts each one actually collects and the sidelobes of the decoded point response.

   **What to observe:** When the separation changes, the physical detector moves. The angular grid spacing shrinks, but a shadow shift of a fixed whole number of cells stays the same.

3. 03

   #### Scene 3: A missing mask edge

   Remove the outer mosaic and move a source to the edge. On the same record, compare cyclic decoding with the ridge reconstruction that knows the finite geometry. Then add Poisson noise and increase the exposure.

   **What to observe:** The true scene is used only to score the result. Correlation and ridge reconstruction can give negative estimates, regularization bias or ghost images, while the raw record stays nonnegative.

Physical conclusion

The shadow is the data. Decode it with the known geometry, compare the counts and point response of each mask, and keep noise, finite edges and the assumptions behind each reconstruction in view.

Waves & optics · Starter path

## From one ray to interference measurement

Start with refraction, find where the ray picture stops working, then use interference to measure tiny distances.

[Start here → **Optical Boundary Explorer** Turn the incident angle and watch reflected and transmitted power trade off. Then switch to the critical-angle scene. Observe · 11 min](https://sandboxphysics.com/labs/optical-boundary-explorer/)

1. [1 Optical Boundary Explorer](https://sandboxphysics.com/labs/optical-boundary-explorer/)
2. [2 Rainbow Caustic Observatory](https://sandboxphysics.com/labs/rainbow-laboratory/)
3. [3 Camera Obscura](https://sandboxphysics.com/labs/camera-obscura/)
4. [4 Coherent Wave Composer](https://sandboxphysics.com/labs/coherent-wave-composer/)
5. [5 Young Double-Slit Bench](https://sandboxphysics.com/labs/young-double-slit-bench/)
6. [6 Michelson Precision Lab](https://sandboxphysics.com/labs/michelson-precision-lab/)

[View the full path →](https://sandboxphysics.com/topics/waves-and-optics/#starter-path)
