How JPEG Quality 90 to 100 Affects Quantization Divisors
Increasing the JPEG quality setting from 90 to 100 drastically reduces the values of the quantization divisors, driving them down to their absolute minimum of 1 across almost the entire matrix. This article explains the mathematical mechanism behind this shift, how standard JPEG encoders scale quantization tables, and why transitioning from quality 90 to 100 causes a dramatic surge in file size with minimal visual improvement.
The Role of Quantization Divisors in JPEG
In JPEG compression, an image is divided into \(8 \times 8\) pixel blocks, converted to frequency space via the Discrete Cosine Transform (DCT), and then quantized. Quantization is the primary lossy step where each DCT coefficient is divided by a corresponding value from an \(8 \times 8\) quantization table and rounded to the nearest integer:
\[\text{Quantized Value} = \text{round}\left(\frac{\text{DCT Coefficient}}{\text{Divisor}}\right)\]
Larger divisors discard fine details and high-frequency noise by forcing small coefficients to zero, which enables high compression. Smaller divisors preserve more precise frequency data at the expense of compressibility.
The Standard Quality Scaling Formula
Most JPEG implementations, including those based on the Independent
JPEG Group (IJG) standard reference library (libjpeg),
determine quantization divisors by scaling a baseline quantization table
using a quality factor (\(Q\)) ranging
from 1 to 100.
For quality levels of 50 or higher, the scaling factor \(S\) is calculated as:
\[S = 200 - 2Q\]
The scaled divisor for each position \((i, j)\) in the table is then computed as:
\[\text{Divisor} = \text{clamp}\left(\left\lfloor \frac{\text{BaseDivisor} \times S + 50}{100} \right\rfloor, 1, 255\right)\]
Divisors at Quality 90
When \(Q = 90\), the scale factor is:
\[S = 200 - (2 \times 90) = 20\]
Because \(S = 20\), each entry in the baseline table is multiplied roughly by \(0.20\) (one-fifth of its standard value):
- Low-Frequency Coefficients: The smallest baseline values (often between 2 and 16) reduce down to divisors of 1, 2, or 3.
- High-Frequency Coefficients: Larger baseline values (often ranging from 40 to 99) reduce to divisors typically between 8 and 20.
At Quality 90, subtle low-frequency gradients are preserved without banding, while fine, high-frequency background noise is still divided by values greater than 1 and filtered out into zeros.
Divisors at Quality 100
When \(Q = 100\), the scale factor drops to zero:
\[S = 200 - (2 \times 100) = 0\]
Plugging \(S = 0\) into the formula yields:
\[\left\lfloor \frac{\text{BaseDivisor} \times 0 + 50}{100} \right\rfloor = 0\]
Because zero division is invalid, the clamping function enforces a minimum divisor value of 1. Consequently, every divisor in the quantization table becomes 1 for both luminance and chrominance channels.
Practical Impact of the Shift
Moving from Quality 90 to 100 alters compression dynamics significantly:
- Loss of Zero-Runs: At Quality 90, higher-frequency divisors produce extensive runs of zeros, which Huffman coding compresses efficiently. At Quality 100, dividing by 1 preserves every minute DCT coefficient, including imperceptible sensor noise.
- File Size Expansion: Because every frequency coefficient must now be explicitly encoded, file sizes often double or triple compared to Quality 90.
- Diminishing Returns: Because human vision is relatively insensitive to high-frequency variations, reducing divisors from modest integers down to 1 yields negligible perceptual gains despite the massive increase in storage and bandwidth requirements.