Sunday, December 4, 2011

Benefits of PNG Files

Recently while scanning some old paper work, I spotted something that beautifully illustrates one of the properties of PNG files.  After scanning a batch of images and converting them to PNG format I then ordered them by size in Windows Explorer.  A clear pattern immediately became visible by looking at the preview icons.  A cut down version of this is shown below.

File Preview Icons

A PNG file is simply an image file that uses loss less compression to reduce the file size, and the simpler the image is, the better the compression algorithm works.  By looking at the image above you can see that as the files become smaller they become simpler in structure, ie less variations in colour and less detail.  From this group of images the best compression ratio obtained was about 3 to 1, but much higher compression ratios can be obtained.

The map image below from Open Street Map for example has a compression ratio of about 20 to 1.  It is made up of only a handful of colours and has large patches of continuous colour, making it a perfect candidate for PNG compression.

Highly Compressed PNG File
This property was useful in the OpenGL map viewer software that I wrote.  The main factor limiting the update rate of map tiles was the speed at which they could be read from the disk drive.  By reading the compressed files from the disk and decompressing them in memory a speed increase was obtained.

I have to admit that I quite like using PNG files.  When compared to a BMP file they win nearly all the time, you get the added feature of an alpha (transparency) channel, and the space saving via compression that they offer.  I would only use a BMP file if I needed something that was really easy to read.  So for archiving images, PNG is the way to go.

When comparing JPEG and PNG files it really depends on the image.  If the image is photo like and has lots of detail, then JPEG is the way to go if you don't mind a slight loss of quality through compression, otherwise PNG may be a good choice.

No comments:

Post a Comment