PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabs
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry

More from Math Visualization

Other simulators in this category — or see all 52.

View category →
NewUniversity / research

PLL (Phase-Locked Loop)

Discrete-time analog-style PLL: multiplier PD e = K_d sin(φ_ref − φ_VCO), PI loop filter, VCO ω = ω_fr + K_v u; step ω_ref to explore lock, capture, and steady-state phase error.

Launch Simulator
NewUniversity / research

ΔΣ (1-bit) Modulator

First- and second-order discrete-time ΔΣ with ±1 quantizer: shaped quantization noise, sine test tone, boxcar reconstruction, and Hann-windowed error spectrum (last 1024 samples).

Launch Simulator
NewUniversity / research

Polyphase L/M Resampling

Zero-stuff by L, Hamming-windowed sinc FIR at the high rate with min(π/L,π/M) cutoff, then decimate by M; spectra in/out and Noble-identity polyphase intuition.

Launch Simulator
NewUniversity / research

Mandelbrot Deep Zoom

Drag/wheel deep zoom into the Mandelbrot set with smooth continuous coloring and named landmarks.

Launch Simulator
NewUniversity / research

Julia Set Explorer

Pick c by clicking the embedded mini-Mandelbrot or animate c along a circle; Fatou dust vs connected sets.

Launch Simulator
NewUniversity / research

Newton Fractal

Basins of attraction for Newton iteration on zⁿ−1 with adjustable relaxation ω.

Launch Simulator
PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Math Visualization/DCT & JPEG Quantization (8×8)

DCT & JPEG Quantization (8×8)

Baseline JPEG-style luminance coding is built from three ingredients on every 8×8 block: (1) subtract 128 from each sample so AC energy is centered; (2) apply a separable 8-point type-II DCT, implemented here with an orthonormal D matrix so inversion is exactly DᵀFD; (3) divide each frequency coefficient by an element of a scaled ISO luminance quantization table, round to an integer, and multiply back — the only lossy step in this toy pipeline. The simulator also offers a second pedagogy mode that skips Huffman coding entirely and simply zeroes trailing coefficients in the canonical JPEG zigzag order after the first K positions, which highlights how low-frequency DCT basis images carry most visible structure while high-frequency bins sharpen edges and fine texture. A 64×64 synthetic grayscale image is processed blockwise; you can click any block to inspect its coefficient heatmaps and a zigzag-ordered trace of the raw DCT before quantization.

Who it's for: Introductory image processing, multimedia, or signals-and-systems students learning why JPEG looks blocky at extreme compression and why chroma subsampling and perceptual weighting matter in full encoders.

Key terms

  • Discrete cosine transform
  • JPEG quantization matrix
  • Zigzag scan
  • PSNR
  • 8×8 block transform
  • Lossy compression
  • Luminance channel

8×8 block DCT

Test image

42

Click the left image to inspect another 8×8 block. Heatmaps show DCT coefficients before and after the lossy step for that block only.

Measured values

MSE (whole image)10.96
PSNR (dB)37.73
Nonzero AC-ish coeffs (count)700
Selected block(2, 3)

How it works

8×8 type-II DCT on luminance with a −128 level shift (same spirit as baseline JPEG). Choose JPEG quality to scale the standard luminance quantization matrix, or switch to zigzag truncation: keep the first K coefficients in JPEG zigzag order and zero the rest — the staircase you see in textbook AC energy plots. The bottom strip plots zigzag-ordered AC amplitudes for the selected block before any loss (raw DCT).

Key equations

F = D (X−128·1) Dᵀ (8×8)
JPEG: F̂ᵢ = Qᵢ · round(Fᵢ / Qᵢ)
Zigzag: zero F at indices K…63 in scan order

Frequently asked questions

Why subtract 128 before the DCT?
An 8-bit unsigned image lives in [0,255]. Centering around zero (pixel − 128) puts DC near zero for mid-gray regions and makes AC coefficients smaller on average, which improves quantization behavior and matches the spirit of the JPEG level shift.
Is this a full JPEG encoder?
No. Real JPEG adds chroma (often subsampled), different quant tables for chrominance, Huffman or arithmetic entropy coding of run-length / category symbols, optional progressive modes, and more. This page isolates the spatial transform + quantization story that creates most of the visible artifacts.
Why does aggressive quantization look blocky?
Each 8×8 block is reconstructed independently from a small set of surviving DCT modes. Neighboring blocks may disagree on edge placement across the shared boundary, so you see a grid of discontinuities — classic blocking artifacts.
What does the zigzag truncation mode represent?
It is a simplified “keep only the lowest spatial frequencies” knob. Real JPEG does not truncate a sharp K in zigzag order without quantization, but the mode matches textbook diagrams that explain energy compaction: early zigzag indices correspond mostly to low horizontal/vertical frequency combinations.