JPEG Color Space Conversion and Precision Loss
Every time an image undergoes repeated JPEG encoding, converting between the standard RGB representation and the YCbCr color space introduces significant numerical precision loss. This generation loss is caused by rounding errors during forward and inverse matrix transformations, chroma subsampling artifacts, and the subsequent compounding effects of Discrete Cosine Transform (DCT) quantization. Over successive save-and-load cycles, these combined factors cause color drift, reduced saturation, and edge degradation.
The RGB to YCbCr Mathematical Transformation
JPEG natively processes image data in the YCbCr color space to isolate perceived brightness (luma, \(Y\)) from color information (chroma, \(Cb\) and \(Cr\)). The transformation from standard 8-bit RGB to YCbCr relies on floating-point matrix multiplication defined by standards such as ITU-R BT.601:
- \(Y = 0.299R + 0.587G + 0.114B\)
- \(Cb = -0.1687R - 0.3313G + 0.5B + 128\)
- \(Cr = 0.5R - 0.4187G - 0.0813B + 128\)
Because RGB inputs are integers bounded between 0 and 255, the continuous results of these linear equations must be rounded and clamped back into 8-bit integer coordinates. Converting back to RGB upon decompression requires an inverse floating-point calculation, which is likewise subject to integer rounding:
- \(R = Y + 1.402(Cr - 128)\)
- \(G = Y - 0.34414(Cb - 128) - 0.71414(Cr - 128)\)
- \(B = Y + 1.772(Cb - 128)\)
Because the transformation matrices do not create a bijective (one-to-one) integer mapping, values routinely drift by \(\pm 1\) per cycle purely through floating-point truncation and integer rounding, even without DCT quantization.
Chroma Subsampling Losses
To optimize compression, JPEG implementations frequently apply chroma subsampling—commonly 4:2:0 or 4:2:2. In 4:2:0 subsampling, the color resolution is halved both horizontally and vertically, retaining only one color sample for every \(2 \times 2\) block of luminance pixels.
During repeated save cycles, the decoder interpolates these missing color values back to full resolution, and the subsequent encoder averages them down again. This continuous spatial downsampling and upsampling severely attenuates high-frequency chroma details, producing color bleeding around high-contrast edges and gradually washing out saturated boundaries.
Interaction with Quantization and Accumulation
Color space conversion does not happen in isolation; it directly feeds the frequency-domain quantization step. When integer values shift due to color conversion errors, the spatial pixel differences yield modified DCT coefficients:
- Shifted Coefficients: Small numerical changes in the spatial domain cause high- and mid-frequency DCT coefficients to cross quantization thresholds, leading to unnecessary zeroing or altered step-sizes.
- Boundary Clipping: Colors near the extreme ends of the gamut (values near 0 or 255) undergo repeated clamping, causing irreversible gamut clipping and localized posterization.
- Chroma Drift: Subtle rounding biases in non-symmetric implementations push neutral gray tones toward green or magenta tints over dozens of generations.
Even when saving at maximum quality (quality level 100), standard JPEG encoding is not mathematically idempotent. The continuous round-trip transformations between RGB and YCbCr ensure that spatial precision steadily declines with each successive generation until the pixel grid settles into a degraded, visually degraded state.