YCC colour space and image compression

Written by Paul Bourke
April 2000


Introduction

There are an infinite number of possible colour spaces instead of the common RGB (Red, Green, Blue) system most commonly used in computer graphics. Many of these other colour spaces are derived by applying linear functions of r, g, b. So for example, a colour space based upon 3 coordinates v1, v2, and v3 can be written as:

   v1 = Ar1 R + Ag1 G + Ab1 B
   v2 = Ar2 R + Ag2 G + Ab2 B
   v3 = Ar3 R + Ag3 G + Ab3 B 

Where the Ar, Ag, Ab are constants for a particular colour space. Similarly for any such system there are linear functions to go back to RGB space. The coefficients Dr, Dg, Dc can be derived by solving the above equations for r,g,b. For example:

   R = Dr1 v1 + Dg1 v2 + Db1 v3
   G = Dr2 v1 + Dg2 v2 + Db2 v3
   B = Dr3 v1 + Dg3 v2 + Db3 v3

The human visual system has much less dynamic range (acuity) for spatial variation in colour than for brightness (luminance), in other words, we are acutely aware of changes in the brightness of details than of small changes in hue. So rather than saving as RGB it can be more efficient to encode luminance in one channel and colour information (that has had the luminance contribution removed) in two other channels. The two colour channels can be encoded with less bandwidth by using a number of techniques, predominantly by reducing the precision, or as will be discussed here, reducing the spatial resolution.

Since green dominates the luminance channel it makes sense to base the other two chrominance channels on luminance subtracted red and blue. Such luminance, red chrominance and blue chrominance systems are generally referred to as Y, Cr, and Cb. In what follows they will generally be referred this way or simply as YCC.

Example: Kodak PhotoCD YCC

The Kodak PhotoYCC colour space was designed for encoding images with the PhotoCD system. It is based on both CCIR Recommendations 709 and 601-1, having a colour gamut defined by the CCIR 709 primaries and a luminance - chrominance representation of colour like CCIR 601-1's YCbCr.

To convert from RGB to PhotoCD YCC, the following matrix operation is used (after appropriate gamma correction has been applied). Notice the major contribution to the Cr value is red and the main contribution to the Cb value is blue. The unbalanced scale difference between Chroma1 and Chroma2 is designed, according to Kodak, to follow the typical distribution of colours in real scenes.

  Y  =  0.299 R + 0.587 G + 0.114 B
  Cr =  0.701 R - 0.587 G - 0.114 B
  Cb = -0.299 R - 0.587 G + 0.886 B

The rationale behind these coefficients can be found by considering that the luminance subtracted blue (B-Y) signal reaches its extreme values at blue (R=0, G=0, B=1, Y=0.114, B-Y=0.886) and at yellow (R=1, G=1, B=0, Y=0.886, B-Y=-0.886). Similarly, the extrema of the luminance subtracted red (R-Y), +-0.701, occur at red and cyan.

In a similar way there is a matrix for creating RGB colour values from any colour space created as discussed above. Note that in many cases and this applies to YCC colour spaces, it is possible to represent colours that cannot be represented in RGB space. For the Kodak system the reverse mapping from YCC into RGB is:

Application to image compression

Given the human visual systems "preference" for luminance information, one can design an image compression system around YCC colour space. Consider an RGB image with Nx horizontal pixels and Ny vertical pixels. If each pixel is repreented as one byte the the image size in bytes is Nx Ny 3. Consider storing the image in YCC space where the luminance channel Y is stored as one byte for each pixel but the two chrominance channels are only stored for each block of say 4x4 pixels. The resulting image would be Nx Ny + 2 (Nx/4 + Ny/4), this is an image 2 and 2/3rds smaller. Put another way, instead of using on average 3 bytes (24 bits) per pixel we would only be using 9 bits per pixel.

Note the chrominance is averaged over each 4x4 block. There is nothing particularly special about a 4x4 block instead of a 3x3 or 5x5 or other sizes. A 2x2 by two results in a factor 2 saving, a 3x3 grid results in a saving of 2.45. Larger grids give ever decreasing rates of return and soon impact on the image quality.

The YCC colour space used follows that used by TIFF and JPEG (Rec 601-1)
   Y  =  0.2989 R + 0.5866 G + 0.1145 B
   Cb = -0.1687 R - 0.3312 G + 0.5000 B
   Cr =  0.5000 R - 0.4183 G - 0.0816 B

RGB values are normally on the scale of 0 to 1, or since they are stored as unsigned single bytes, 0 to 255. The resulting luminance value is also on the scale of 0 to 255, the chrominance values need 127.5 added to them so they can saved in an unsigned byte.

Of course when the YCC values are turned back into RGB, then 127.5 must be first subtracted from the two chrominance values. The reverse transform is

   R = Y             + 1.4022 Cr
   G = Y - 0.3456 Cb - 0.7145 Cr
   B = Y + 1.7710 Cb

The full chrominance range of +-0.5 maps into a larger colour space than supported by RGB. The above equations can yield RGB values outside the 0 to 255 (or 0 to 1) range, these typically relate to very light or dark colours. The RGB values should be clipped so they lie within the allowed range after the transform from YCC to RGB is calculated.

An image compressed this way is obviously degraded but could one tell the difference? Below are two images, the one on the left uses 24 bits per pixel and the one on the right uses 9 bits per pixel as described above.

Before

The above is the original image that is used as an example in what follows. It was captured as a single from a digital movie camera.

 
After

The above is the image that results from a 1 byte Y channel and 4x4 subsampled Cr, Cc channels.


Y channel

First C channel (Cr)

Second C channel (Cb)

The compression scheme above is most noticeable when there are rapid changes in hue but little change in luminance, in this case the 4x4 subsampling of the Cr and Cb channels is most noticeable. For images of real world scenes this happens surprisingly rarely, in the before and after example above it is virtually impossible to zoom in and find examples of the 4x4 subsampling. Similarly one would not generally use this sort of compression for low colour images, in that case other compression techniques are available.

Appendix: Other standard colour space conversions

RGB -> CIE XYZitu (D65)
   X = 0.431 R + 0.342 G + 0.178 B
   Y = 0.222 R + 0.707 G + 0.071 B
   Z = 0.020 R + 0.130 G + 0.939 B
CIE XYZitu (D65) -> RGB
   R =  3.063 X - 1.393 Y - 0.476 Z
   G = -0.969 X + 1.876 Y + 0.042 Z
   B =  0.068 X - 0.229 Y + 1.069 Z

RGB -> CIE XYZrec601-1 (C illuminant)
   X = 0.607 R + 0.174 G + 0.200 B
   Y = 0.299 R + 0.587 G + 0.114 B
   Z = 0.000 R + 0.066 G + 1.116 B
CIE XYZrec601-1 (C illuminant) -> RGB
   R =  1.910 X - 0.532 Y - 0.288 Z
   G = -0.985 X + 1.999 Y - 0.028 Z
   B =  0.058 X - 0.118 Y + 0.898 Z

RGB -> CIE XYZccir709 (D65)
    X = 0.412 R + 0.358 G + 0.180 B
    Y = 0.213 R + 0.715 G + 0.072 B
    Z = 0.019 R + 0.119 G + 0.950 B
CIE XYZccir709 (D65) -> RGB
   R =  3.241 X - 1.537 Y - 0.499 Z
   G = -0.969 X + 1.876 Y + 0.042 Z
   B =  0.056 X - 0.204 Y + 1.057 Z

PAL television standard
RGB -> YUV
    Y =  0.299 R + 0.587 G + 0.114 B
    U = -0.147 R - 0.289 G + 0.436 B
    V =  0.615 R - 0.515 G - 0.100 B
YUV -> RGB
   R = Y + 0.000 U + 1.140 V
   G = Y - 0.396 U - 0.581 V
   B = Y + 2.029 U + 0.000 V

NTSC television standard
RGB -> YIQ
    Y =  0.299 R + 0.587 G + 0.114 B
    I =  0.596 R - 0.274 G - 0.322 B
    Q =  0.212 R - 0.523 G + 0.311 B
YIQ -> RGB
   R = Y + 0.956 I + 0.621 Q
   G = Y - 0.272 I - 0.647 Q
   B = Y - 1.105 I + 1.702 Q
References

Color Monitor Colorimetry
SMPTE Recommended Practice RP 145-1987

CIE Colorimetry
Official recommendations of the International Commission on Illumination, Publication 15.2 1986

Effective Color Displays. Theory and Practice
D. Travis, Academic Press, 1991. ISBN 0-12-697690-2

Measuring Colour (Second edition)
R.W.G. Hunt, Ellis Horwood 1991, ISBN 0-13-567686-x

Precision requirements for digital color reproduction
M. Stokes, M.D. Fairchild, R.S. Berns, ACM Transactions on graphics, v11 n4 1992

The Reproduction of Colour in Photography, Printing and Television
R.W.G. Hunt, Fountain Press, Tolworth, England, 1987