draft · v0.1.226
💬Comments welcome. To leave a note, select any text and click the note / highlight button that pops up — or open the panel with the tab at the top-right (‹). Notes are visible only inside our private review group.
💡 In a hurry? Jump to this chapter’s 3 big lessons ↓

4.11 Sampling, downsampling, and aliasing

A digital image is a sampling of a continuous scene — we record the value on a regular grid and throw away everything in between. Most of the time that is harmless. But when the scene carries detail finer than the grid can resolve, something counter-intuitive happens, and it is one of the most surprising facts in imaging. The previous chapter built the Fourier machinery; sampling is the thing that machinery explains most cleanly, because a sampling grid is just a comb of evenly shifted spikes. (We treat the reconstruction / upsampling direction — putting values between samples — in the next chapter, Resampling; here the concern is what goes wrong when we throw samples away.)

4.11.1 Aliasing: a high frequency in disguise

Picture photographing a building's facade — rows of fine windows, or a striped shirt — and shrinking the result. Where the stripes are finer than the output pixels, they do not melt into a uniform gray; they reorganize into bold, wrong, low-frequency bands and swirls that are not in the scene at all: moiré. Intuitively, when a pixel must summarize detail it cannot represent, it ought to return the local average — a neutral gray. Instead, the leftover high frequency gets misread as a low one.

The clean case is a single sine wave (Figure 4.11.1). Sample a high-frequency sine too coarsely — fewer than two samples per cycle — and the samples you collect fall into a pattern indistinguishable from a lower-frequency sine. The original travels in disguise as a different frequency; that impostor frequency is its alias. The damage is not blur (lost detail you could shrug off); it is corruption — energy that lands at the wrong frequency and masquerades as real structure. The same masquerade plays out in 2-D on a real photograph (Figure 4.11.2): a facade's regular window grid is a high spatial frequency, and sampling it too coarsely without a pre-filter folds that grid down into bold, slow moiré bands that are not in the building.

fig-aliasing
Figure 4.11.1. Sampling a sine too coarsely → aliasing. A high-frequency sinusoid (light) is sampled at too few points per cycle; the samples (dots) are consistent with a completely different, lower-frequency sinusoid (dark) — its alias. Below twice the signal's frequency (the Nyquist rate) the two are indistinguishable from the samples alone: the high frequency "folds" down and masquerades as a low one. This is the moiré / wagon-wheel effect.
fig-aliasing-photo
Figure 4.11.2. The same aliasing on a real photo. A building facade — a dense, near-periodic grid of windows, i.e. a high spatial frequency — sampled ×7 by simply dropping samples, with no pre-filter. The window frequency, above the coarse grid's Nyquist, folds back into bold, slow, curved moiré bands that are not in the building (center; zoom at the bottom). It is the one-dimensional sine of the previous figure acting in two dimensions on a real image — high frequency masquerading as low. The cure — pre-filter, then sample — is below.

4.11.2 Nyquist and the sampling theorem

The rule that prevents it is the Nyquist–Shannon sampling theorem: to represent a signal faithfully you must sample at more than twice its highest frequency. Equivalently, with a fixed sampling grid there is a top frequency — the Nyquist frequency, half the sampling rate — that the grid can represent; anything above it cannot be stored and, if present, folds (aliases) down onto a lower frequency and contaminates it. There is no recovering from aliasing after the fact: once a high frequency has folded onto a low one, the two are added together and can never be told apart.

💡 Big lesson (L4.12) — Nyquist–Shannon: sample above twice the highest frequency, or it aliases

To represent a signal from its samples you must sample at more than twice its highest frequency (the Nyquist rate). Sample any slower and the frequencies above the Nyquist limit (half the sampling rate) cannot be stored — they fold down and alias onto lower frequencies, masquerading as structure that is not there (the moiré on a fine facade, the backward wagon-wheel). This is the spatial root lesson of all sampling, and it is not confined to space: the very same theorem governs the time axis, where under-sampling a fast motion gives temporal aliasing — the wagon-wheel and rotor-freeze effects of film and video. The only cure is to band-limit before you sample: low-pass (blur / area-average) away everything above Nyquist first, then sample (the anti-aliasing prefilter, L16). The frequency-domain account of why — sampling replicates the spectrum and the copies overlap — is L4.13; the ideal band-limiting filter, the unreachable sinc, is L4.14.

The theorem cuts both ways, which is why it is so central. It tells you when sampling is safe — the signal is already band-limited below Nyquist, so nothing folds — and exactly what to do when it is not: kill the offending frequencies before they fold. And because it is a statement about any sampled signal, it reappears far beyond image shrinking: in audio (the 44.1 kHz CD rate is a little over twice the ~20 kHz of human hearing), in video frame rates, and — on the time rather than the space axis — as the temporal aliasing we just named.

4.11.3 In two dimensions, aliasing has a direction

Everything so far has been the 1-D story — a fast sine masquerading as a slow one — and in 1-D there is only one thing an alias can do: land at a lower frequency along the single axis. In two dimensions it is messier, because a spatial frequency carries not just a rate but a direction, and aliasing folds both. A 2-D high frequency does not simply drop to a lower 2-D frequency; it folds to a frequency with a possibly different orientation. So a perfectly regular pattern can alias into moiré that runs in an unexpected direction — diagonal bands from a vertical grille, swirling rosettes from concentric rings — bearing no obvious relation to the orientation of the detail that produced it. The aliases of a 2-D signal do not share a single direction the way the 1-D alias shares the lone axis, which is exactly why 2-D moiré looks so strange: each folded frequency arrives pointing its own way.

The canonical directional case is the humblest one: the stair-step or "jaggies" on a near-horizontal or near-vertical edge. A slightly slanted edge is, locally, a very low-frequency ramp crossed by a high-frequency component along the edge; sample it on the pixel grid without prefiltering and that high frequency folds, breaking the smooth slant into a staircase of horizontal and vertical pixel runs. The jaggy is aliasing wearing its plainest costume — and the reason anti-aliasing in rendering and rasterization is, at heart, the same band-limit-then-sample prefilter we are building here, applied to synthetic edges instead of a photographed facade.

fig-aliasing-2d
Figure 4.11.3. Aliasing is directional in 2-D. A regular 2-D pattern (a near-periodic grid and a slanted edge), point-sampled on a coarse grid without a prefilter, aliases in ways 1-D cannot: the grid's high spatial frequency folds to a low frequency of a different orientation, so the moiré bands run in a direction unrelated to the windows that caused them, while the slanted edge breaks into the canonical stair-step / "jaggies." A 2-D frequency carries a direction as well as a rate, and aliasing folds both — which is why 2-D moiré appears in unexpected directions. The cure is the same as in 1-D: prefilter (area-average) before sampling.

4.11.4 Sampling in the frequency domain: spectral replicas

In the frequency domain the mechanism is vivid. Sampling on a grid is multiplying the signal by a comb of spikes, and multiplying by a comb in space replicates the spectrum — it pastes shifted copies of the signal's spectrum at every multiple of the sampling rate. If the original spectrum is narrow enough (band-limited below Nyquist), the copies sit side by side without touching and the original can be isolated. If it is too wide, the copies overlap, the tails fold back over the genuine low frequencies, and that overlap is aliasing. Seen this way the fix is obvious: band-limit the signal before you sample it. Run a low-pass filter — a blur — first, to delete the frequencies above Nyquist that would otherwise fold, then sample. This pre-filter (anti-aliasing) trades a little sharpness for the removal of false structure, and it is why a well-written image-shrinking routine blurs before it downsamples. The space-versus-frequency tradeoff returns: a perfectly sharp cutoff in frequency is a sinc spread out forever in space, so practical pre-filters compromise.

💡 Big lesson (L4.13) — sampling replicates the spectrum; aliasing is the replicas overlapping

Sampling on a grid is multiplication by a comb (a train of deltas), and a comb's Fourier transform is another comb — so sampling replicates the signal's spectrum at every multiple of the sampling rate. If the spectrum is band-limited below Nyquist the copies sit side by side and the original is recoverable; if it is not, the copies overlap, and the folded-over tails land on top of the genuine low frequencies as aliasing — energy appearing at completely wrong frequencies (moiré, the backward wagon-wheel). The cure is to band-limit before sampling: low-pass away everything above Nyquist first, then sample.

4.11.5 Seeing it: sampling and pre-filtering, hands on

The demos below show this directly. The first demo is the one-dimensional story — a single signal, your hand on the sampling rate — and the second is the two-dimensional one, the same physics on a real photograph where aliasing shows up as moiré.

fig-sampling-1d-demo
Figure 4.11.4. Interactive (1-D): sampling, aliasing, and the pre-filter. A continuous signal (a periodic function — sine, square, or sawtooth — a chirp, shaped noise, or a real image scanline) is shown with its samples; drag the sampling rate and watch the reconstructed signal alias to a lower frequency the moment you drop below Nyquist (two samples per cycle), with both the signal and its spectrum (the replicated spectral copies) drawn side by side. Toggle the anti-aliasing pre-filter (a low-pass blur applied before sampling) and watch the offending high frequencies removed before they can fold — the alias disappears, at the cost of a little blur. Tick marks mark the sample locations.
fig-sampling-2d-demo
Figure 4.11.5. Interactive (2-D): downsampling, aliasing, and the pre-filter. Choose a source — a high-frequency zone-plate (the default; concentric rings that get finer toward the edge), a resolution chart, or a real photo — and downsample it by an adjustable factor, shown three ways side by side. Original: the true rings. No pre-filter: point-sampling the coarse grid folds the fine outer rings into bold, spurious moiré rosettes that are nowhere in the pattern — 2-D aliasing. With pre-filter: band-limiting each cell before decimating removes the moiré entirely. Choose the filter — box (area average), bilinear, the bicubic (Mitchell–Netravali) family, or Lanczos (windowed sinc, the sharpest) — and raise the factor to watch the middle's moiré grow while the right just softens. The panels are cropped to the valid interior so every pixel shown had the pre-filter's full support: a kernel near the image edge reaches past it and the demo edge-clamps those reads, which would bias the border — so the artifact you might worry about there is boundary handling, not kernel truncation (the truncated kernel is renormalised), and cropping to full-support pixels removes it from the display.

The full sampling pipeline generalizes to two dimensions just as cleanly, and the spectral picture is the most revealing part: in 2-D, sampling replicates the spectrum on a whole lattice of copies, and aliasing is a copy drifting in to overlap the baseband.

fig-sampling-2d-pipeline
Figure 4.11.6. Interactive (2-D pipeline): the planar version of the 1-D figure, four columns — input → pre-filtered → sampled → reconstructed — each shown both as an image (top) and as its 2-D Fourier magnitude (bottom, DC centered). The input is a 2-D sine (set frequency and orientation) or a curved edge (set curvature and slope). Sampling on a coarse grid tiles the spectrum on a lattice: drop the rate and the replicas march inward until one overlaps the baseband — 2-D aliasing, which the reconstruction then renders as a wrong, lower-frequency moiré. A pre-filter shrinks the baseband so the copies clear; the reconstruction filter interpolates the samples back. Real 2-D FFT throughout.
Sidebar — aliasing without Fourier

You do not strictly need Fourier to feel why sampling fails. A pixel records the signal at a single point, not the average over its little footprint, so two scenes that happen to agree at every sample point produce identical images even if they differ wildly in between — a fast wiggle and a slow one can thread the same dots. The correct "what should a pixel be?" answer is the average over the pixel's area (the integral of the scene under the pixel's footprint), and computing that average is the pre-filtering blur described above, dressed in primal-domain clothes. Fourier merely turns this geometric coincidence into a precise statement about which frequencies survive.

Sidebar — aliasing on purpose

Everything so far has treated aliasing as a nuisance to be suppressed. But the same effect can be engineered to carry information. Print a fine micro-pattern, photograph it with a camera, and the camera's own pixel grid samples that pattern too coarsely — producing a moiré that is no longer in the print at all but emerges from the beat between the print's spatial frequency and the sensor's sampling grid. Because that beat pattern is exquisitely sensitive to the exact sampling geometry, it shifts dramatically with the slightest change in viewpoint — so the moiré effectively encodes the relative camera pose or motion, reading out information that the bare pixels never recorded. MIT's KinéCam dynamic prints exploit exactly this: a static printed micro-pattern that animates and reports camera motion entirely through engineered moiré (hcie.csail.mit.edu/research/kinecam). It is the same physics as the wagon wheel and the striped shirt, turned from a bug into a channel — and it rhymes with the structured / coded patterns that recur elsewhere in the book.

4.11.6 The ideal reconstruction filter: sinc, and why it is unreachable

The deepest reconstruction filter, the one Nyquist's theorem secretly invokes, is the sinc: in the frequency domain it is a perfect box — keep everything below Nyquist, kill everything above, with a vertical wall in between. The sinc reconstructs a band-limited signal exactly. But that vertical frequency wall costs a kernel that ripples on forever in space (the space–frequency tradeoff again), and infinitely wide kernels are neither practical nor well-behaved — they ring. So real systems use approximations to the sinc with finite support (Figure 4.11.7), each striking its own bargain between losing a little mid-frequency contrast and letting a little high-frequency aliasing through. We will meet the practical menagerie — bilinear, bicubic, Lanczos — in the resampling chapter; here the point is only that the ideal exists, that it is unreachable, and that every real filter is a compromise away from it.

💡 Big lesson (L4.14) — the ideal sampling filter is a sinc, which does not exist in practice

Both jobs sampling demands — the anti-alias pre-filter (a perfect low-pass before sampling) and the reconstruction filter (a perfect low-pass to interpolate between samples) — have the same mathematically ideal answer: the sinc, a perfect brick-wall box in frequency. But a vertical wall in frequency is an infinitely wide, forever-ringing kernel in space (the space–frequency tradeoff again), so the ideal is physically unreachable: you cannot store or convolve an infinite kernel, and truncating it makes it ring. Every real pre-filter and every real resampling kernel — box, bilinear, bicubic, Lanczos — is therefore a compromise away from the sinc, trading a little lost mid-frequency contrast against a little leaked aliasing. There is no free lunch and no perfect filter; choosing one is choosing which error to tolerate.

fig-sinc-vs-practical
Figure 4.11.7. Ideal sinc vs a practical filter, in both domains. Top row (space): the ideal sinc reconstruction kernel ripples on forever, while a practical filter has finite support. Bottom row (frequency): the sinc is a perfect box — flat passband, vertical cutoff at Nyquist, zero beyond — whereas the practical filter rolls off gradually, slightly softening mid-frequencies and leaking a little past Nyquist. The vertical wall in frequency is exactly what forces the infinite ripple in space.

Recap: big lessons of this chapter

(L4.12) — Nyquist–Shannon: sample above twice the highest frequency, or it aliases

To represent a signal from its samples you must sample at more than twice its highest frequency (the Nyquist rate). Sample any slower and the frequencies above the Nyquist limit (half the sampling rate) cannot be stored — they fold down and alias onto lower frequencies, masquerading as structure that is not there (the moiré on a fine facade, the backward wagon-wheel). This is the spatial root lesson of all sampling, and it is not confined to space: the very same theorem governs the time axis, where under-sampling a fast motion gives temporal aliasing — the wagon-wheel and rotor-freeze effects of film and video. The only cure is to band-limit before you sample: low-pass (blur / area-average) away everything above Nyquist first, then sample (the anti-aliasing prefilter, L16). The frequency-domain account of why — sampling replicates the spectrum and the copies overlap — is L4.13; the ideal band-limiting filter, the unreachable sinc, is L4.14.

(L4.13) — sampling replicates the spectrum; aliasing is the replicas overlapping

Sampling on a grid is multiplication by a comb (a train of deltas), and a comb's Fourier transform is another comb — so sampling replicates the signal's spectrum at every multiple of the sampling rate. If the spectrum is band-limited below Nyquist the copies sit side by side and the original is recoverable; if it is not, the copies overlap, and the folded-over tails land on top of the genuine low frequencies as aliasing — energy appearing at completely wrong frequencies (moiré, the backward wagon-wheel). The cure is to band-limit before sampling: low-pass away everything above Nyquist first, then sample.

(L4.14) — the ideal sampling filter is a sinc, which does not exist in practice

Both jobs sampling demands — the anti-alias pre-filter (a perfect low-pass before sampling) and the reconstruction filter (a perfect low-pass to interpolate between samples) — have the same mathematically ideal answer: the sinc, a perfect brick-wall box in frequency. But a vertical wall in frequency is an infinitely wide, forever-ringing kernel in space (the space–frequency tradeoff again), so the ideal is physically unreachable: you cannot store or convolve an infinite kernel, and truncating it makes it ring. Every real pre-filter and every real resampling kernel — box, bilinear, bicubic, Lanczos — is therefore a compromise away from the sinc, trading a little lost mid-frequency contrast against a little leaked aliasing. There is no free lunch and no perfect filter; choosing one is choosing which error to tolerate.