Quantization Lab
how quantization turns smooth tones into steps
compression often starts with quantization pain 🖖
Quantization is where continuous or high-precision values are rounded into a finite codebook. The error is usually small per sample, but smooth gradients expose it as contour bands because neighboring pixels round to the same few output values. Dither deliberately adds noise before rounding: it raises local noise, but breaks up coherent bands, which often looks better to human vision and compresses differently in codecs. โข Source vs Output Gradient: The top strip shows the mathematically smooth input gradient. The bottom strip shows the quantized output rounded to the selected levels. At low bit depths, this rounding creates visible contour bands. โข Quantization Error Graph: This plots the difference (output โ input) at each position across the gradient. The yellow line is the error, and the green line represents zero error. Large periodic error waves indicate banding, while adding dither randomizes this error into high-frequency noise.
Bits are just how many steps you get 🖖
A gradient in the real world is continuous, but a computer must pick from a fixed list of values. Bit depth sets how long that list is: each extra bit doubles the count, so 8 bits give 2โธ = 256 shades and 10 bits give 1024. Fewer steps means coarser rounding, which is why dropping to 6-bit (64 shades) makes a smooth sky break into visible stripes.
Every extra bit buys about 6 dB 🖖
A clean rule hides inside the SNR readout: for uniform quantization, each additional bit improves the signal-to-noise ratio by roughly 6.02 dB, following SNR โ 6.02ยทN + 1.76 dB for a full-scale sine. The same formula governs audio converters and image encoders alike, so a 16-bit audio track and a 16-bit image share the same theoretical quantization noise floor. Add a bit, gain 6 dB โ regardless of the medium.
Example problems
- cinema 10-bit - 10-bit grading-like setup with smooth tonal transitions
- web 8-bit - Standard 8-bit pipeline with moderate quantization steps
- low 6-bit - Low precision shows visible contour banding
- dithered 6-bit - Dither trades smooth noise for reduced banding