Encyclopedia of Graphics File Formats

Compression Demo

There are many methods of compressing graphics files. This page attempts to demonstrate how lossless and lossy compression compare. The test data for this demonstration is a 24-bit color image. The bar graph in the last column of these tables is intended to provide a visual comparison of the relative file sizes.

First, we compare several lossless techniques:

Compression Method Resulting Size Resulting Percent Visual Comparison
Uncompressed image 4,261,256 bytes n/a (100%) [bar graphic: 100%]
24 bit PNG 2,081,345 bytes 52% [bar graphic: 48%]
8 bit PNG 620,254 bytes 86% [bar graphic: 14%]
JPEG 100% 967,111 bytes 78% [bar graphic: 22%]

Note: Comparing 8 bit PNG to the 24-bit raw data is misleading. Although PNG is a lossless compression method, using only 8 bits of color represents a loss of 16 bits per pixel. Note also: strictly speaking, the JPEG method, even at 100%, is a lossy compression method.

Lossy compression can have a much more significant payoff, but always at the expense of some image quality:

Image Compression
Method
Resulting
Size
Resulting
Percent
# Colors Visual
Comparison
[Thumbnail] JPEG 100% 967,111 n/a (100%) 287,723 [bar graphic: 100%]
[Thumbnail] JPEG 75% 154,091 84% 302,429 [bar graphic: 16%]
[Thumbnail] JPEG 50% 99,819 90% 282,068 [bar graphic: 10%]
[Thumbnail] JPEG 25% 65,376 93.2% 207,908 [bar graphic: 6%]
[Thumbnail] JPEG 1% 24,173 97.7% 90 [bar graphic: 2%]

Note: the uncompressed 24-bit image uses 130,851 colors.

Selecting the best compression method for any particular image depends on many factors: the number and distribution of colors, the image quality required by your application, and the nature of the tools that must manipulate or display the image. Running comparisons similar to the ones shown above on your real images will provide a better indication of the payoff for your particular application than we can provide in the general case.

For further information on compression of all kinds, see the comp.compression newsgroup FAQ.


Copyright © 1996 O'Reilly & Associates, Inc. All Rights Reserved.

Hosted by uCoz