The World Is Smooth, the Image Is Chunky
In the first two guides you learned what a digital image actually is: a finite grid of pixels, each holding a small set of numbers that encode brightness and color. But step outside that grid for a moment. The light that an optical lens focuses onto a camera's sensor is not made of little squares. It is perfectly smooth — at every point in the image plane there is some brightness, and that brightness can take any value along a continuous range, with no gaps. Nature does not round, and nature does not snap to a grid.
So there is a real tension here. The optical image is a continuous function in two distinct senses. It is continuous over space: between any two points you care to name, there are infinitely many more points, each with its own brightness. And it is continuous in value: the brightness at a single point can be 0.4137… or 0.4138… or anything in between, a real number with endless precision. A computer cannot store either of those infinities. It has a finite number of memory cells, and each cell holds a number with finite precision.
Turning that smooth optical image into a storable array is called digitization, and the key idea of this whole guide is that digitization is really two separate acts, one for each kind of continuity. The first is sampling: deciding where in space we will actually measure the brightness — picking the grid points. The second is quantization: deciding what number we are allowed to store for each measurement — rounding the brightness to one of a finite list of allowed levels. Sampling tames space; quantization tames value.
Sampling: Reading the Image on a Grid
Sampling is the act of measuring the continuous brightness only at a regular set of discrete points — the intersections of an imaginary grid laid over the image plane. We do not, and cannot, record the brightness everywhere. We pick a grid, and at each grid point we read off one brightness value. Every reading becomes one pixel. Everything that happened between the grid points is simply not measured; it must be guessed, or ignored.
A continuous gradient scene overlaid with a grid; sample points sit at the grid intersections and become discrete pixels.
A clean way to feel this: imagine you want to map the temperature across an entire country, but you can only read thermometers at official weather stations. If there are just a handful of stations, you get a crude picture — a warm blob here, a cool blob there — and you completely miss the cold pocket in a valley that has no station. Add hundreds more stations, and the fine local variations start to appear. The stations are your sample points; a denser network captures more of the real variation. The optical image is the true, smooth temperature field; sampling is the network of stations.
This connects straight to resolution from guide 1. The spacing between sample points is the resolution: a finer grid means smaller spacing, which means more samples across the same scene, which means more pixels, which means a more faithful copy of the original light. When someone says a photo is "higher resolution," they are really saying "the world was sampled on a denser grid." Halve the spacing in each direction and you take four times as many samples — twice as many across and twice as many down.
Quantization: Rounding Brightness to Levels
Sampling told us where to read. But each reading is still a real number with endless decimals, and a memory cell cannot hold endless decimals. Quantization is the second act: rounding each sampled brightness to the nearest value in a finite list of allowed levels. Picture a staircase laid over the smooth ramp of possible brightnesses. The true brightness can be anywhere on the ramp, but you are only allowed to report which step it is closest to.
How many steps are on the staircase? That is exactly bit depth from guide 1. With b bits per channel you get 2^b distinct levels: 1 bit gives 2 levels (black or white), 8 bits gives 256 levels (the usual photo), and so on. More bits means more, finer steps, so the staircase hugs the smooth ramp more tightly. Let us make the rounding rule precise.
Snap the true intensity to the nearest storable level.
Read it left to right. I is the true, continuous intensity that sampling handed us (say a brightness anywhere from 0% to 100%). Δ ("delta", the step size) is the gap between two adjacent storable levels. We first divide, I/Δ, which asks "how many whole steps high is this brightness?"; we round that to the nearest whole number, snapping to a specific step; then we multiply by Δ again to turn that step number back into an actual brightness, q, which is what we store. The step size itself is Δ = range / 2^b: take the full brightness range and cut it into 2^b equal steps, where b is the bit depth, so 2^b is the number of levels. Fewer bits → bigger Δ → coarser staircase.
# Worked example: quantize brightness (0-100%) to b = 2 bits -> 4 levels
range_ = 100.0
b = 2
delta = range_ / (2 ** b) # = 100 / 4 = 25% -> levels at 0, 25, 50, 75
readings = [12, 31, 58, 87] # true sampled brightnesses, in %
for I in readings:
q = round(I / delta) * delta # snap to nearest level
error = abs(I - q) # how much we lost by rounding
print(f"I={I:>3}% -> q={q:>3.0f}% error={error:>4.1f}%")
# I= 12% -> q= 0% error=12.0%
# I= 31% -> q= 25% error= 6.0%
# I= 58% -> q= 50% error= 8.0%
# I= 87% -> q= 75% error=12.0%
# Largest possible error = delta/2 = 12.5%Notice every error in the example is at most 12.5%, which is exactly Δ/2 = 25%/2. That is no accident: because we round to the nearest step, the true value is never more than half a step away from the one we keep. This worst-case gap, Δ/2, is the quantization error. The chain is now obvious — more bits → 2^b larger → Δ smaller → Δ/2 smaller → less error. If we had used 8 bits instead of 2, Δ would be 100%/256 ≈ 0.39%, and the worst error would be a nearly invisible 0.2%.
When Sampling Goes Wrong: Aliasing
Now back to space. What happens if the scene contains detail finer than the sampling grid can represent — stripes packed tighter than the gap between sample points? You might hope the detail simply gets lost or blurred. It does not. Something stranger and worse happens: the unrecordable fine detail does not vanish, it masquerades as a false, coarser pattern that was never really there. This impostor pattern is called an aliasing artifact, and it is the classic way sampling goes wrong.
You have almost certainly seen this. A person on TV wears a finely striped or checked shirt, and the fabric erupts into swirling, shimmering rainbow ripples that move as they move — that is moiré, an aliasing artifact, because the shirt's weave is finer than the camera's pixel grid. A diagonal line or a circle on a low-resolution screen turns into a chunky "staircase" of jagged steps — that is aliasing of edges, sometimes called "jaggies," because a slanted edge carries detail finer than one pixel can place. The grid can only put an edge at whole-pixel positions, so a smooth slope becomes a flight of stairs.
Aliasing is not only about space. The famous wagon-wheel illusion — where a spinning wheel's spokes appear to slow, stop, or even rotate backward in a film — is the very same phenomenon along the time axis. A movie samples the world only 24 times a second. If a spoke moves almost a full spoke-spacing between frames, each snapshot lands it just shy of where the last spoke was, so your brain stitches the frames into a slow backward crawl. The true fast motion was sampled too slowly, and it reappears disguised as a slow motion.
Nyquist & Anti-Aliasing: The Cure
To turn that one-liner into a rule we need one friendly word: frequency. Here, frequency just means how rapidly brightness changes as you move across space. A clear blue sky changes slowly — low spatial frequency. A finely striped shirt or a sharp edge changes very rapidly over a tiny distance — high spatial frequency. "Detail" and "high frequency" are two names for the same thing. The finest detail in a scene corresponds to its highest frequency.
The master idea is the Nyquist sampling principle: to honestly capture detail up to some finest wiggle rate, you must sample at least twice as fast as that rate. Anything finer than the limit your sampling allows will alias. Here it is in symbols.
Sample more than twice as fast as the finest detail you want to keep.
Symbol by symbol: f_s is the sampling rate — how densely we place grid points (samples per millimeter on the sensor, say). f_max is the highest spatial frequency actually present in the scene — the finest, fastest-changing detail. The factor 2 is the heart of it: you need at least two samples per cycle of a wiggle (one to catch a peak, one to catch the following trough) just to tell that wiggle apart from a flat line. Equivalently, your sample spacing must be smaller than half the period of the finest detail. Catch fewer than two samples per cycle and the wiggle collapses into a slower impostor — exactly the aliasing of the previous section.
But what if the scene simply has detail finer than your fixed grid can ever satisfy — a real shirt with a real fine weave, and a sensor you cannot change? Here is the elegant cure: anti-aliasing. Before sampling, deliberately blur the image with a smoothing (low-pass) filter that removes the frequencies above what your grid can honestly capture. "Low-pass" means it lets the low frequencies pass through and suppresses the high ones. With the un-capturable fine detail gone before sampling, there is nothing left to masquerade as a fake pattern.
# Why we blur BEFORE shrinking an image (downsampling) # Wrong: just throw away pixels -> high frequencies alias into moire small_bad = image[::4, ::4] # keep every 4th pixel, no blur # Right: low-pass (blur) first, removing detail the small grid can't hold, # THEN sample on the coarser grid blurred = gaussian_blur(image, sigma=2) small_good = blurred[::4, ::4] # small_good has no fake patterns; small_bad shimmers with aliasing
The Full Digitization Pipeline
Let us assemble everything from guides 1–3 into one clean chain. The smooth optical image arrives at the sensor; we tame its two infinities in turn — first space, then value — and out the other end falls the finite array of numbers you met on day one.
- Continuous optical image: smooth brightness over every point in space, with values along a continuous range — nature's input, storing infinitely much information.
- Anti-alias blur: a low-pass filter strips out detail finer than the grid can honestly hold, so it cannot reappear as a fake pattern (the cure for aliasing).
- Sample on a grid (sampling): read the brightness only at discrete grid points; the spacing sets the resolution. Space is now discrete.
- Quantize each sample (quantization): round every reading to the nearest of 2^b levels set by the bit depth. Value is now discrete too.
- Finished digital image: a finite grid of pixels, each a small set of finite numbers — ready to store, display, and compute on.
Step back and the reassurance is complete: every concept from the first two guides — the pixel as a single cell, the resolution as how many of them, the bit depth as how finely each is recorded, and the color channels that hold a hue — is precisely the output of this pipeline. Pixels are sampled points. Resolution is sample spacing. Bit depth is the number of quantization levels. The grid of numbers is not where photography starts; it is where digitization ends.