Probing JPEG Chroma Sampling

Many people have been confused by the different treatment of colour subsampling used in different programs JPEG compression codec. I have taken here a very simple model image chosen to maximise the effects of 2x2 block colour subsampling and show the effects at different frequencies and phases. The test image is 128x16 pixels wide and would occupy 6144 bytes if stored as uncompressed 24 bit RGB data. The colours red and blue are chosen to have roughly equal luminance of 128. I have to point out that this pattern is about as pathological as you can give to a JPEG encoder and the differences on real photographic images tend to be much less pronounced.

The test image consists of bands of red and blue vertical lines 8 pixels long arranged in blocks of 8 pixels with the same pitch looking a bit like a crazy piano keyboard. The subsampling wipes out the alternating component of alternating red, blue, red, blue lines to a purple, and perhaps less obviously also zaps the 2 pixel wide detail in the sequence red, blue, blue, red (or blue, red, red, blue). The various codecs give slightly different results but the results in my browser are closer to Photoshops decoder as the PaintShop Pro decoder attempts some dealliasing of the decoded JPEG. Generating single pixel wide border transitions around the coloured blocks.

It is pretty clear that between PhotoShop quality levels 4 and 5 the chroma subsampling jumps from 4:2:2 to 4:4:4 and the target is immediately rendered more accurately and in a smaller filesize. This is true for this line art example (and may well be true for similar line art images). The "baseline optimised" save option helps decreases file size on small files by making all quantisation coefficeints fit into a single byte. On large files it may not be advantegous to force "baseline optimised".

I did this series of tests to see how my new copy of Photoshop compares with my familiar older copy of PaintShop Pro v5. It seems there may be situations when one is superior to the other, but it isn't all one sided.

Photoshop has quality levels which preserve high frequency colour detail beyond anything offered in PSP v5. PSP v8 now includes options to save JPEGs with higher quality chroma subsampling. However this comes at a price, and all the JPEGs saved with PhotoShop are larger than those saved with PSPro. In part because even with "save for web" PhotoShop adds a small essay to every JPEG file saved.

Compression Size /bytes Actual size 4x zoom
Original GIF 1,035 comb.gif comb.gif
PhotoShop Q = 1 927 (2,296) comb_p1.jpg comb_p1.jpg
PhotoShop Q = 1 b 582 (1,951) comb_p1b.jpg comb_p1b.jpg
PhotoShop Q = 2 955 (2,324) comb_p2.jpg comb_p2.jpg
PhotoShop Q = 3 978 (2,347) comb_p3.jpg comb_p3.jpg
PhotoShop Q = 4 1141 (2,510) comb_p4.jpg comb_p4.jpg
PhotoShop Q = 5 1029 (2,398) comb_p5.jpg comb_p5.jpg
PhotoShop Q = 6 1070 (2,439) comb_p6.jpg comb_p6.jpg
PhotoShop Q = 7 1090 (2,459) comb_p7.jpg comb_p7.jpg
PhotoShop Q = 8 1129 (2,498) comb_p8.jpg comb_p8.jpg
PhotoShop Q = 9 1220 (2,589) comb_p9.jpg comb_p9.jpg
PhotoShop Q = 10 1355 (2,724) comb_p10.jpg comb_p10.jpg
PhotoShop Q = 10 b 700 (2,069) comb_p~2.jpg comb_p~2.jpg
PSPro v5 IJG Q' = 1 1,306 comb_1.jpg comb_1.jpg
PSPro v5 IJG Q' = 2 1,243 comb_2.jpg comb_2.jpg
PSPro v5 IJG Q' = 10 1,019 comb_10.jpg comb_10.jpg
PSPro v5 IJG Q' = 20 886 comb_10.jpg comb_20.jpg
PSPro v5 IJG Q' = 40 762 comb_40.jpg comb_40.jpg
PSPro v5 IJG Q' = 99 584 comb_99.jpg comb_99.jpg

Not all browsers display JPEGs with equal fidelity, and so that you can see what I am describing on a browser with a quick and dirty decoder the following images have been converted to GIFs inside PSPro and PhotoShop. The top line is the original JPEG as decoded by your browsers codec. The JPEG decoder in my Netscape 4.74 closely mimics the PhotoShop one but is slightly less flattering to the image. And the JPEG decoder in Internet Explorer 5 follows the PSPro / IJG anti aliassed edge behaviour.

Image saved by PaintShop Pro v5 with IJG JPEG Q' = 1 (highest quality) 1,306 bytes

Browser decoded JPEG comb_1.jpg
PSPro IJG decoded (GIF) comb_1j.gif
PhotoShop decoded (GIF) comb_1a.gif

To my eyes, and this is a highly subjective assessment, the overall image quality using Photoshop Q=4 and PaintShop Pro Q'=20 are roughly comparable. However the file sizes are significantly different due the additional baggage of a thumbnail in the PhotoShop JPEG header. I have shown the actual size containing the JPEG image and shown the physical filesize including all headers in brackets.

The file from PSPro being 3x more compact for the same level of visual quality with 4:2:2 chroma sampling.

I do not expect the size variation to be so pronounced with real photographic images.

Image saved by Paintshop Pro v5 with IJG JPEG Q' = 20 (typical quality) 886 bytes

Browser decoded JPEG comb_20.jpg
PSPro IJG decoded (GIF) comb_1j.gif
PhotoShop decoded (GIF) comb_1a.gif

Image saved by PhotoShop v5.0LE Q=4 (typical quality) 1141 bytes of JPEG stream in a file size 2,510 bytes

Browser decoded JPEG comb_1P.jpg
PSPro IJG decoded (GIF) comb_p1j.gif
PhotoShop decoded (GIF) comb_p1a.gif

When used at it's maximum quality setting PhotoShop can comfortably reproduce this nasty design with excellent fidelity and both PSPro and PhotoShop agree on how it decodes.

Image saved by PhotoShop v5.0 LE q=10 with baseline 700 bytes of JPEG stream in a filesize 2,069 bytes

Browser decoded JPEG comb_p10b.jpg
PSPro IJG decoded (GIF) comb_p10j.gif
PhotoShop decoded (GIF) comb_p10ba.gif

I can demonstrate clearly the cut in point of 4:4:4 vs 4:2:2 sampling with this test image. I pushed PSPro to the surreal end of the compression spectrum at Q'=99 the where results show that they are from a 16x16 block due to the colour subsampling. Another conclusion is that the default PhotoShop save as JPEG is a poor choice for making small images as there is a hidden thumbnail image in the header which may easily double the size of the resulting file.

Email to Martin Brown

Send feedback suggestions and comments to Martin Brown
Last modified 26th October 2003