YCrCb and friends (Colorspaces VII)

JPEG, MPEG, and other compression algorithms all use a colorspace other than RGB. The colorspaces they use are such that most of the perceptually useful information is concentrated into one component, essentially brightness, and the color information diffused into the remaining components. Furthermore, we hope that we can heavily quantize the color information. JPEG separates the image into brightness and two other components: brightness is coded full resolution, but the two other components are downsampled 4:1. Yet, it’s not visible in the reconstructed image, because our eyes are good at brightness, but not at chrominance.

But that’s not a surprise. All the colorspaces we’ve seen so far do this, and (are believed to) have the same properties, grosso modo.

JPEG uses the YCbCr colorspace:

\begin{bmatrix}  0.299 & 0.587 & 0.114\\  -0.169 & -0.331 & 0.5\\  0.5 & -0.419 & -0.081\\  \end{bmatrix}  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}  =  \begin{bmatrix}  Y\\  C_B\\  C_R\\  \end{bmatrix}

with inverse

\begin{bmatrix}  1 & 0 & 1.402\\  1 & -0.344 & -0.714\\  1 & 1.772 & 0\\  \end{bmatrix}  \begin{bmatrix}  Y\\  C_B\\  C_R\\  \end{bmatrix}  =  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}

* *

I proposed a variant of this colorspace for DjVu for fast decoding. Instead of starting from the “forward” transform, I started from the inverse:

\begin{bmatrix}  1 & 0 & \frac{3}{2}\\  1 & -\frac{1}{4} & -\frac{3}{4}\\  1 & \frac{7}{4} & 0\\  \end{bmatrix}  \begin{bmatrix}  \tilde{Y}\\  \tilde{C}_B\\  \tilde{C}_R\\  \end{bmatrix}  =  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}

The rationale is that multiplications using numbers such as \frac{3}{4} are easily re-rewritten as additions and shifts. \frac{3}{4} can be rewritten as \frac{1}{2}+\frac{1}{4} as well as 1-\frac{1}{4}, and so \frac{3}{4}x can be computed as x-(x>>2). The inverse can be computed all in integers. The forward transform is given by the inverse’s inverse:

\begin{bmatrix}  0.304 & 0.609 & 0.087\\  -0.174 & -0.348 & 0.522\\  0.464 & -0.406 & -0.058\\  \end{bmatrix}  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}  =  \begin{bmatrix}  \tilde{Y}\\  \tilde{C}_B\\  \tilde{C}_R\\  \end{bmatrix}

* *

The values in the brightness line, 0.299, 0.587, and 0.114, were chosen a longtime ago for various reasons: the standard response of displays—then phosphorus-based—and industry-imposed corrections at capture-time—the standard gamma corrections. Overtime TV went from analog to digital and so the whole process changed. CRT were replaced by flat screens that used completely different technologies with different colors. To address these changes, new colorspaces where introduced:


\begin{bmatrix}  0.2126 & 0.7152 & 0.0722\\  -0.1146 & -0.3854 & 0.5000\\  0.5000 & -0.4541 & -0.0458\\  \end{bmatrix}  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}  =  \begin{bmatrix}  Y\\  P_B\\  P_R\\  \end{bmatrix}

with inverse

\begin{bmatrix}  1 & 0 & 1.5748\\  1 & -0.1873 & -0.4681\\  1 & 1.8856 & 0\\  \end{bmatrix}  \begin{bmatrix}  Y\\  P_B\\  P_R\\  \end{bmatrix}  =  \begin{bmatrix}  r\\  g\\  b\\  \end{bmatrix}

There are other versions of this colorspace. Defined in BT.709, YPbPr is eventually modified by BT.2020 for Ultra HDTV, and BT.2100 for HDR Video.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: