JPEG data compression ot multiple quality levels

25 October 1997, Hans-Werner Braun

Inspired by http://www-cse.ucsd.edu/users/polyzos/hjpeg.html with a more thorough analysis available in http://www-csl.ucsd.edu/CSL/pubs/journal/rti97.ps, the following is a short sumamry of some JPEG compression performance by image quality, reflecting the image loss allowance that the JPEG format offers.

The work started out with a 1090*731 pixel 2.4Mbit image in PPM format of the United States from the National Geophysical Data Center. The PPM format was chosen for easy conversion as a 24-bit format and it being a non-compressed, hence non-lossy format. The image conversions were done on a with the following script:

#!/bin/zsh

/bin/rm *.gif
for i in 001 002 004 008 016 032 064 075 090 095 100
do
 echo $i
 cjpeg -quality $i us.ppm >! $i.jpg
 djpeg $i.jpg >! $i.ppm
 pnmcut 200 280 100 100 $i.ppm >! $i-cut.ppm
 pnmscale 3 $i-cut.ppm >! $i-cut3.ppm
 ppmquant 256 $i-cut3.ppm | ppmtogif > $i-cut3.gif
done
whirlgif -l 0 -o cut3.gif *.gif

This utilizes a public domain JPEG library and programs, and considers compressions at the 1, 2, 4, 8, 16, 32, 64, 90, 95 and 100 percentile levels. For size reasons, the pnmcut commands extracted 100*100 pixel samples of the overall images, after compressing with defined quality levels into JPEG format files, and decompressing the images back into PPM format files. Scaling it up by replicating pixels to three times the size makes the resulting image more viewable in this presentation. The ppmquant and ppmtogif commands were used to convert to the 8-bit GIF format, to then with whirlgif create a GIF animation of the image sample result.

For size reasons the following image icons are in the 8-bit GIF format as well, though clicking them allows for viewing of the whole JPEG image at the specific quality/compression rates:

Note that if the 2,390,429 original image gets compressed with the standard data comression program gzip, the resulting image was still 1,833,968 bytes in size, worse than the 1.2MB of even the 100% JPEG compression, and significantly worse than the "reasonably good" 75% JPEG compression, which resulted in a 0.3MB file.

The following graphic displays the relationship of file sizes over image qualities for the file used here:

It is curious that even the very small 2% quality/compression, with 18,456 bytes being about 1/130th of the uncompressed image size, still yields information enough for a viewer to in many cases prefer such an image over no image at all, including as it still exposes many edges, something the human eye focuses on more than the appropriate colors, being more permissive with false colorization than missing edges.