Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Image sampling and quantisation

Notes on image sampling (spatial/temporal discretisation) and quantisation (amplitude discretisation): definitions, Nyquist sampling theorem for 1D and 2D, aliasing and anti-aliasing, uniform quantisers and error/SNR/PSNR, with worked numerical examples and exam guidance.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Digital images are created and processed by discretising a continuous light field in two ways: by sampling (making a grid of pixels) and by quantisation (assigning each pixel an integer intensity). Engineers design cameras, sensors, and image-processing systems to avoid aliasing, choose sensor resolution, select bit-depth, and evaluate image quality (PSNR, SNR). Good choices reduce visible artifacts and improve downstream tasks such as compression and segmentation.

Key ideas

  • Band-limited — a signal is band-limited if its Fourier transform is zero for spatial/temporal frequencies above some finite maximum f_max. This is an important assumption in the sampling theorem.

  • 1D Sampling theorem (Nyquist–Shannon, exact statement): Let f(t) be a continuous-time signal with Fourier transform F(ω) = ∫{−∞}^{∞} f(t) e^{−jωt} dt, and suppose F(ω) = 0 for |ω| > ω_m (band-limited to ω_m). Sample f(t) at period T (sampling angular frequency ω_s = 2π/T) to obtain f_s(t) = f(t)·Σ{n=−∞}^{∞} δ(t − nT). Then the Fourier transform of the sampled signal is F_s(ω) = (1/T) · Σ_{k=−∞}^{∞} F(ω − k·ω_s). If ω_s > 2·ω_m (equivalently sampling frequency f_s = 1/T > 2·f_m), the spectral replicas do not overlap and f(t) can be perfectly reconstructed by an ideal low-pass filter that selects the baseband component. Assumption: ideal low-pass filter and exact band-limiting; practical signals are not perfectly band-limited so pre-filtering (anti-aliasing) is used.

    Derivation sketch (standard exam derivation):

    1. Write sampling impulse train p_T(t) = Σ δ(t − nT).
    2. Sampled signal f_s(t) = f(t) p_T(t).
    3. Use Fourier transform property: multiplication in time → convolution in frequency. The FT of p_T(t) is (2π/T) Σ δ(ω − k·ω_s) (or with convention-dependent constant; use the convention stated above so you keep the 1/T factor in final formula).
    4. Convolution of F(ω) with that delta comb produces a periodic sum of shifted copies of F(ω): F_s(ω) = (1/T) Σ F(ω − k·ω_s).
    5. For perfect reconstruction, the shifted copies must not overlap; hence ω_s > 2ω_m.

    What to draw for an exam diagram:

    • Draw a 1D frequency axis (ω); draw the baseband spectrum F(ω) as a finite-width block from −ω_m to +ω_m.
    • Draw periodic replicas centered at k·ω_s for k = ±1, ±2.
    • Label ω_s and ω_m and show the non-overlap condition ω_s > 2ω_m (replicas separated by gap) and the overlap case (aliasing).
  • Aliasing — when spectral replicas overlap during sampling, high frequencies fold into lower frequencies producing distortions (moiré patterns in images). Prevent by ensuring sampling satisfies Nyquist or by pre-filtering (optical or electronic low-pass) before sampling. In practice, sensors have limited modulation transfer and lenses act as anti-aliasing to some degree.

  • 2D sampling (images): For a separable rectangular (square) sampling grid with sampling intervals Δx and Δy, the 2D spectrum is replicated on a 2D lattice with spacing 1/Δx in fx and 1/Δy in fy. For no aliasing we require the image’s spatial frequency content to be limited so that replicas in both directions do not overlap. A simple sufficient condition: f_xmax < 1/(2Δx) and f_ymax < 1/(2Δy), where f_x, f_y are cycles per unit distance.

  • Reconstruction — ideal reconstruction of a band-limited sampled signal is by convolution with a sinc (1D) or separable sinc (2D) kernel. In practice we use finite-support interpolators (bilinear, bicubic) and accept approximation.

  • Uniform quantiser — divides the input amplitude range [X_min, X_max] into equal intervals of width Δ. For a b-bit quantiser, L = 2^b. If both endpoints X_min and X_max are representable output levels (e.g., codes 0..L−1), the quantisation step (LSB) is Δ = (X_max − X_min)/(L − 1). For a mid-rise design whose decision thresholds span [X_min, X_max] while reproduction levels exclude the endpoints, use Δ = (X_max − X_min)/L. The quantiser maps any input in an interval to a representative level. Two common designs: mid-rise and mid-tread (difference affects whether zero maps to a level or midpoint).

  • Quantisation error e = x − Q(x). For a uniform quantiser and assuming the input is uniformly distributed within each quantisation interval (common exam assumption), the quantisation error is approximately a random variable with zero mean and variance σ_e^2 = Δ^2/12. The maximum absolute error ≤ Δ/2 (worst-case bound).

  • Signal-to-quantisation-noise ratio (SNR): For a full-scale sinusoidal input and a uniform quantiser with b bits, the theoretical SNR (in dB) is approximately SNR ≈ 6.02·b + 1.76 dB. This follows from computing signal power of a sine and the uniform quantisation noise variance under the uniform-distribution assumption.

  • MSE and PSNR — For images, Mean Squared Error (MSE) between original and quantised image (or reconstructed image) is MSE = (1/N) Σ (I_orig − I_rec)^2. Peak Signal-to-Noise Ratio (PSNR) is PSNR = 10·log10 (MAX_I^2 / MSE) dB, where MAX_I is the maximum possible pixel value (for 8-bit images MAX_I = 255).

Formulas

L = 2^b — L is number of quantisation levels, b is bits per sample (no units). Applies to uniform quantisers.

Δ = (X_max − X_min) / (L − 1) — Δ is the LSB step when both endpoints are representable (e.g., 0–255). For a mid-rise quantiser whose reproduction levels exclude the endpoints, use Δ = (X_max − X_min) / L.

|e| ≤ Δ/2 — quantisation error bound (same units). Worst-case for mid-rise/mid-tread type quantisers.

σ_e^2 = Δ^2 / 12 — variance of quantisation error under the common assumption that error is uniformly distributed on (−Δ/2, Δ/2) (units: squared signal units). Assumes uniform distribution of error.

f_s ≥ 2·f_max — Nyquist condition (Hz). For continuous-time sampling with highest frequency f_max (Hz). Equality is critical (no margin); usually choose f_s > 2·f_max.

F_s(ω) = (1/T) · Σ_{k=−∞}^{∞} F(ω − k·ω_s) — relation between Fourier transforms of sampled and continuous signals. ω_s = 2π/T (rad/s). Assumes FT defined as F(ω)=∫ f(t)e^{−jωt} dt and impulse-train sampling.

MSE = (1/N) Σ_{i=1..N} (x_i − x̂_i)^2 — mean squared error (units: squared pixel units). Applies to discrete images of N pixels.

PSNR = 10 · log10( MAX_I^2 / MSE ) — PSNR in dB. MAX_I is maximum possible pixel value (unit: same as pixel values).

SNR (dB) ≈ 6.02·b + 1.76 — approximate SNR for a full-scale sinusoidal signal quantised with b bits. Assumes uniform quantiser and full-scale sine input.

Worked examples

  1. 1D sampling (audio-style numerical) Problem: A continuous signal has highest frequency f_max = 4.0 kHz. Find the minimum sampling frequency f_s (Nyquist) and corresponding sampling period T. Solution:
  • Formula: f_s ≥ 2·f_max.
  • Compute: f_s_min = 2 * 4.0 kHz = 8.0 kHz.
  • Sampling period: T = 1 / f_s = 1 / 8000 Hz = 0.000125 s = 125 µs. Answer: Minimum sampling frequency is 8.0 kHz, sampling period 125 µs.
  1. 2D spatial sampling (pixels) Problem: An imaging system must capture spatial frequencies up to 1.2 cycles/mm in both x and y. What is the maximum allowable square pixel pitch Δ (in mm) to avoid aliasing (Nyquist) assuming ideal band-limited image content? Solution:
  • Nyquist in x-direction: f_xmax < 1/(2·Δ) ⇒ Δ ≤ 1/(2·f_xmax).
  • Compute: Δ_max = 1 / (2 * 1.2 cycles/mm) = 1 / 2.4 mm^{-1} = 0.416666... mm ≈ 0.417 mm. Answer: Maximum pixel pitch should be 0.417 mm or smaller to avoid aliasing.
  1. Quantisation and PSNR (image) Problem: 8-bit uniform quantisation on a greyscale image with range 0–255 (full scale). Assume quantisation behaves like uniform noise with variance Δ^2/12. Compute Δ, quantisation noise variance, and PSNR assuming the MSE equals the quantisation noise variance under this model. Solution:
  • b = 8 ⇒ L = 2^8 = 256.
  • Δ = (255 − 0) / (256 − 1) = 255/255 = 1.0 (greyscale level unit).
  • Noise variance σ_e^2 = Δ^2 / 12 = 1^2 / 12 = 0.08333....{
  • PSNR: PSNR = 10 log10( MAX_I^2 / MSE ) with MAX_I = 255 and MSE ≈ σ_e^2. Compute numerator: 255^2 = 65025. Ratio: 65025 / (1/12) = 65025 * 12 = 780,300.{ PSNR = 10 * log10(780300) ≈ 10 * 5.892 = 58.92 dB.{ Answer: Δ = 1.0, quantisation noise variance = 0.08333, PSNR ≈ 58.9 dB.

(Notes: small differences arise with rounding. The common SNR approximation for a full-scale sine gives ≈ 6.02·8 + 1.76 = 48.16 + 1.76 = 49.92 dB; PSNR differs because it uses peak value whereas SNR here uses sine RMS.)

Common mistakes

  • Confusing spatial frequency units (cycles/mm) with pixel frequency (cycles/pixel); always state units.
  • Using PSNR and SNR interchangeably without noting definitions (PSNR uses peak value; SNR uses signal power).
  • Forgetting that σ_e^2 = Δ^2/12 assumes a uniform distribution of the error; it is not exact for all inputs.
  • Assuming ideal band-limited images — real images are not perfectly band-limited and need anti-aliasing filters.

For your exam

Types of questions asked:

  • Definitions: sampling, quantisation, aliasing, Nyquist rate, band-limited.
  • Derivations: prove the sampled-signal FT formula and derive the Nyquist condition (step-by-step derivation expected, draw frequency diagrams).
  • Numericals: compute minimum sampling rate/period, pixel pitch from spatial frequency, Δ and PSNR for b-bit quantiser.
  • Short notes: advantages/limitations of uniform quantisers, anti-aliasing filters and practical reconstruction filters (sinc vs bilinear).
  • Diagrams: draw frequency-domain replicas and label ω_s, ω_m, show aliasing vs non-aliasing.

What a full-marks answer includes:

  • Clear definitions (bold the term and define), explicit assumptions (band-limited, FT convention), a correct derivation with each step justified, a labelled diagram when requested, and numerical answers with units and working.

Quick check

  1. State the Nyquist sampling rate for a signal with highest frequency 10 kHz.
  2. For a 6-bit uniform quantiser with range 0–63, what is Δ?
  3. What is the maximum absolute quantisation error for step Δ? Answers: 1) 20 kHz (sampling period 50 µs). 2) L = 2^6 = 64, Δ = (63 − 0)/(64 − 1) = 63/63 = 1.0. 3) Δ/2.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?