RGB to YCbCr Conversion Matrix in JPEG

JPEG image compression relies on color space transformation to separate brightness from chromatic information, enabling efficient compression via chroma subsampling. This article covers the standard mathematical matrix defined by the ITU-R BT.601 standard and adopted by the JPEG File Interchange Format (JFIF) specification to convert digital RGB color components into the YCbCr color space.

The Role of YCbCr in JPEG

Digital images are natively captured and displayed using the RGB (Red, Green, Blue) color model. However, the human visual system is significantly more sensitive to variations in brightness (luminance) than to subtle variations in color (chrominance).

To exploit this biological characteristic, the JPEG pipeline converts RGB values into YCbCr before performing Discrete Cosine Transform (DCT) and quantization:

Once separated, the Cb and Cr components can be subsampled (e.g., 4:2:0 or 4:2:2) with virtually no perceptible loss in visual quality.

The Standard Forward Conversion Matrix

The JFIF standard utilizes full-range conversion based on the ITU-R BT.601 (formerly CCIR 601) standard coefficients. Assuming standard 8-bit inputs where \(R, G, B \in [0, 255]\), the mathematical transformation is represented as follows:

\[ \begin{bmatrix} Y \\ Cb \\ Cr \end{bmatrix} = \begin{bmatrix} 0.299 & 0.587 & 0.114 \\ -0.168736 & -0.331264 & 0.5 \\ 0.5 & -0.418688 & -0.081312 \end{bmatrix} \begin{bmatrix} R \\ G \\ B \end{bmatrix} + \begin{bmatrix} 0 \\ 128 \\ 128 \end{bmatrix} \]

Component Breakdown

Expressed as linear scalar equations, the conversion corresponds to:

In this transformation:

  1. The weighting factors (\(0.299\), \(0.587\), and \(0.114\)) reflect the human eye’s relative sensitivity to red, green, and blue light respectively.
  2. The \(+128\) bias added to \(Cb\) and \(Cr\) centers the signed chrominance values into an unsigned 8-bit range (\([0, 255]\)), where a value of \(128\) denotes neutral chrominance.

The Inverse Conversion Matrix (Decoding)

During decompression, the JPEG decoder reconstructs the RGB values by subtracting the 128 offset and multiplying the components by the inverted matrix:

\[ \begin{bmatrix} R \\ G \\ B \end{bmatrix} = \begin{bmatrix} 1 & 0 & 1.402 \\ 1 & -0.344136 & -0.714136 \\ 1 & 1.772 & 0 \end{bmatrix} \begin{bmatrix} Y \\ Cb - 128 \\ Cr - 128 \end{bmatrix} \]

Expressed as scalar equations:

Calculated values are then clamped to the valid integer range of \(0\) to \(255\) to eliminate any rounding artifacts before being displayed on an RGB device.