Return to Digital Photography Articles
JPEG Chroma Subsampling
The JPEG (JFIF) compressed file format can produce significant reductions in file size through lossy compression. The techniques used to achieve these levels of JPEG compression take advantage of the limitations of the human eye. The compression algorithm saves space by discarding additional image information / detail that may not be as noticeable to the human observer.
It is widely known that we are much more sensitive to changes in luminance (brightness) than we are to chrominance (color) differences. Because of this, the JPEG format can discard a lot more color information than luminance in the compression process. To facilitate the different compression requirements of the two "channels" of image information, the JPEG file format translates 8-bit RGB data (Red, Green, Blue) into 8-bit YCbCr data (Luminance, Chroma Blue, Chroma Red). Now, with the brightness seperated into a separate data channel, it is much easier to change the compression algorithm used for one channel versus the others.
Chroma subsampling is the process whereby the color information in the image is sampled at a lower resolution than the original. The images below show various types of chroma subsampling (from 1x1 to 2x2) and the effect it has on reducing the color information. Pay special attention to the horizontal and vertical stripes.
|1x1 (No Subsampling)||2x1 (Subsampling)|
|1x2 (Subsampling)||2x2 (Subsampling)|
NOTE: The above images depict the results of enlargement with nearest neighbour algorithm after decompressing the chroma-subsampled JPEG images. Therefore, what you observe is the actual impact of the subsampling process.
In the above series, a series of red and blue stripes were drawn with exactly the same Y value (after conversion from RGB to YCbCr) or intensity. When the JPEG compression algorithm performs the chroma subsampling step, it averages out the color information across pairs of pixel, but still preserves the luminance. By choosing RGB values for Red (RGB=97,0,0) and Blue (RGB=0,0,255) that have the same converted Y (luminance component), the resulting stripes will disappear (after "averaging"). Note that the red phosphors are significantly "brighter" than the blue phosphors given the same input stimulation (RGB value).
You can also see the more unpleasant artifacts due to chroma subsampling in regions of significant color changes in adjacent pixels. This is particularly noticeable on the green circle.
Digital Cameras and Chroma Subsampling
Most digital SLR cameras use 2x1 chroma sub-sampling, while some point and shoot digicams use 2x2. The Sigma / Foveon dSLR cameras are one of the few that don't do any chroma subsampling. The color channels from a typical 6 megapixel image (3072x2048 pixels) is first converted into a 3 megapixel image (1536x2048 pixels). In the case of 2x1 (4:2:2) chroma subsampling -- only one for every 2 pixels is used in the horizontal direction, but every pixel in the vertical direction is retained. Some graphics programs (such as Photoshop) often use 2x2 (4:2:0) chroma subsampling, which would further reduce the color information to 1536x1024 pixels.
With the reduction in color "detail", one has less information to compress, resulting in a smaller JPEG file. When it comes time to display the compressed JPEG, the compressed color channel information is uncompressed and then duplicated (doubled) across the adjacent pixels before being merged with the luminance channel for display.
The existence of chroma subsampling in JPEG compression also explains why one can achieve better compression ratios (ratio between original file size and compressed file size) with color photos than with grayscale photos. With chroma subsampling, one gets better compression out of the chrominance channels than the luminance channel. The overall compression ratio for a color photo is therefore somewhere between the two ratios. As a grayscale image has no color information to discard, the overall compression ratio is dictated purely by the lower luminance compression ratio.
Various levels of YCbCr subsampling:
- 4:4:4 - The resolution of chrominance information (Cb & Cr) is preserved at the same rate as the luminance (Y) information. Also known as 1x1 (or subsampling disabled).
- 4:2:2 - Half of the horizontal resolution in the chrominance is dropped (Cb & Cr), while the full resolution is retained in the vertical direction, with respect to the luminance. This is also known as 2x1 chroma subsampling, and is quite common for digital cameras.
- 4:1:1 - Only a quarter of the chrominance information is preserved in the horizontal direction with respect to the luminance information. I don't think this format is nearly as common as the other variations.
- 4:2:0 - With respect to the information in the luminance channel (Y), the chrominance resolution in both the horizontal and vertical directions is cut in half. This form is also known as 2x2 chroma subsampling.
Steps in JPEG Compression Chroma Subsampling
In order for a JPEG Encoder to take advantage of the file size savings through chroma subsampling, it performs the following basic steps:
- Convert color space from RGB to YCbCr
- For each component Cb and Cr: If horizontal chroma subsampling is specified, output Cb and Cr channels are generated from the average of each adjacent pairs of pixels in the horizontal direction. Similar process for vertical subsampling. In each case, the output channel resolution is halved.
- For the luminance component, Y, the output channel is identical to the input, irrespective of the chroma subsampling configuration.
- Remaining JPEG compression steps. But, the SOF0 (Baseline DCT) JPEG marker will now show that components 2 and 3 have a sampling factor other than 1x1.
Please see the relevant section in the JPEG Decoder Design page for more details on how the different subsampled channels are encoded in a JPEG file.
When is Chroma Subsampling is bad
The fact that JPEG chroma subsampling relies on the limitations of the human eye means that it is not a particularly good mechanism for compressing images used by other "sensors" (such as in the medical field, etc.), where the chrominance may be equally as important as the luminance.
Photoshop Quality and subsampling:
As an aside, note that Photoshop CS2 uses different chroma subsampling levels depending on the Save JPEG Quality settings:
- Photoshop Save As Quality 0-6 - 2x2 Chroma Subsampling
- Photoshop Save As Quality 7-12 - 1x1 No Chroma Subsampling
- Photoshop Save For Web Quality 0-50 - 2x2 Chroma Subsampling
- Photoshop Save For Web Quality 51-100 - 1x1 No Chroma Subsampling