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

Related simulators

Continue with similar topics in this category — or all 85 in Math Visualization.

View category →
NewUniversity / research

2D Phase Portrait (ODE)

Launch Simulator

Direction field and click-to-trace trajectories for planar systems: harmonic, damped, saddle, nodes, foci, pendulum (RK4).

NewUniversity / research

ΔΣ (1-bit) Modulator

Launch Simulator

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).

NewUniversity / research

Butterworth / Chebyshev IIR

Launch Simulator

Design Butterworth, Chebyshev I/II LP/HP filters: |H(f)|, phase, impulse response, and z-plane pole–zero plot via bilinear transform.

NewUniversity / research

Morlet Wavelet (CWT)

Launch Simulator

Continuous wavelet transform with the complex Morlet wavelet: scaleogram |W(s,t)|, log-frequency axis, cone of influence, adjustable ω₀ and scale range.

NewUniversity / research

Conjugate Gradient Solver

Launch Simulator

SPD system Ax=b as quadratic minimization: contour geometry, CG vs steepest descent path, residual norm, and condition number.

NewUniversity / research

Logistic Map Bifurcation

Launch Simulator

x_{n+1}=rx_n(1−x_n): scan r, plot attractors — period doubling to chaos (Feigenbaum cascade).

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)

64×64 luma: 8×8 DCT with −128 shift, ISO luminance quant table scaled by JPEG quality, or zigzag AC truncation (keep K). Click a block for coefficient heatmaps and zigzag trace.

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)

About this model

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

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.