C03 · From light to pixels
Sampling and quantization
Where to measure and how many distinct values to store are different decisions with different losses.
Background if needed
Theory
Position and level
Spatial sampling replaces a continuous field with a grid; quantization replaces a value with a valid code. More megapixels do not add levels; more bits do not add spatial detail. A screen square depicts a number, not the exact photosite response area.
One stripe cycle goes from bright through dark to bright again. Frequency 0.25 means one cycle per four output-grid steps; 0.75 means three cycles in those same four steps. Phase shifts the pattern against the grid without changing cycle count. The 0.5 limit means two samples per cycle; an unfortunate phase can still hide a signal exactly at that limit.
Fine patterns impersonate coarse ones
The Nyquist limit is half the sampling rate. Exact recovery needs a band limit and idealized conditions; phase can hide a pattern at the limit itself. After aliasing, different source structures cannot be distinguished from samples.
A prefilter attenuates troublesome frequencies before downsampling. Area averaging helps, but a finite footprint is not an ideal frequency limiter. Enlarging an ambiguous image cannot recover information.
Stripes that were not there
Raise frequency above 0.5, change phase and angle. Enable area averaging and compare the false pattern.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
The dense curve is the source between pixel centres; the polyline uses only retained samples. It can look slow while the source oscillates rapidly. The vertical marker matches the selected pixel.
- Source signal
- Another source with identical samples
- Retained samples
- Selected sample: 8.5
Different source frequencies can give identical samples. A prefilter attenuates troublesome frequencies before measurement.
Parameters and details
Frequency is cycles per output-grid spacing. The prefilter averages 8 × 8 subsamples within each pixel: it attenuates high frequencies but is not an ideal band limiter. The dense view is also discrete and is only a visual reference.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Codes and dither
One bit gives two levels; two give four. Including endpoints 0 and 1 gives spacing 1/(2ᵇ−1). Rounding creates gradient bands; range clipping separately loses over-range values.
Dither is added before rounding, exchanging regular bands for noise. Individual points may become less exact and there are no extra valid codes. Fixed noise keeps comparisons on one input.
How many levels remain?
Choose two bits and enable dither. Compare bands and noise: there are still four valid codes.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Input + dither
- Clamp to [0, 1]
- Round to an integer code
- Return to the [0, 1] scale
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
Each curve point is a pixel value on the marked horizontal line. Select another image row to move the graph. Compare edge width and preservation of detail.
- Input
- Output
Dither changes error structure, not the number of levels.
Parameters and details
b bits give 2ᵇ levels including both endpoints. Fixed uniform dither is added before rounding: it reduces banding at the cost of noise, without recovering original values. This is non-subtractive dither, so the endpoints can be biased.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Practice
Test the idea under another condition. Follow the task above the images; point inspection helps explain the result. This exploration is not scored.
Two sources, identical samples
The starting pattern has 0.75 cycles per spacing and phase 0.5. A slower curve passes through the same samples. Set 0.25 and phase 0: the saved grid matches despite a different source. Return and enable prefiltering: ambiguity must be prevented before sampling.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
The dense curve is the source between pixel centres; the polyline uses only retained samples. It can look slow while the source oscillates rapidly. The vertical marker matches the selected pixel.
- Source signal
- Another source with identical samples
- Retained samples
- Selected sample: 8.5
Different source frequencies can give identical samples. A prefilter attenuates troublesome frequencies before measurement.
Parameters and details
Frequency is cycles per output-grid spacing. The prefilter averages 8 × 8 subsamples within each pixel: it attenuates high frequencies but is not an ideal band limiter. The dense view is also discrete and is only a visual reference.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Games
Test your explanation
Question 1 of 5
A sparse grid has already recorded an aliased pattern. Can later blur replace filtering before acquisition?
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Choose one answer. It is checked immediately.
Limitations and references
Limits of this example
Analytic pattern and 64 × 64 dense view. The prefilter uses finite subsamples, not sinc; dither is non-subtractive.