Computer Science
Image Compression Techniques

Data compression is all about squishing data into the a smaller number of bytes. A variety of techniques are used to reduce the size of a bitmap.

Run-Length Encoding

This technique is based on the repetition of colours in an image. If you read the image from the top left, reading a row of pixels at a time, you often get runs of pixels of the same colour. If there are 3 or more pixels in a row, storing the number in the run and the colour is more efficient.

rle image

The image above can be described as follows,

White 71
Orange 8
White 22
Orange 8
White 22
Orange 8
White 22

RLE is lossless compression. No information is lost in the image compression. RLE was used in the now defunct pcx format.

Compression techniques that involve the loss of information are known as lossy compression.

JPEG

Joint Photographic Experts Group created the standard. The standard specifies the algorithm used for compression and decompression (codec). Lossy compression - some visual quality is lost.

The jpg format is good with photographs. It is not so good with high contrast pictures like screenshots or computer art. It relies on the eye not being sensitive to tiny changes of colour.

Compression can be varied when the image is saved. This format recompresses each time it is saved and repeated saving may lose quality. You should always work with uncompressed formats before saving in the target format.

GIF

The Graphics Interchange Format is based on limiting the colours used in the image. Typically up to 256 colours are used to make the palette - a table assigning up to 256 colours to the number 0 - 255. The pixel data for the image is then stored using the 8 bit number that represents the colour's position in the table.

Good for cartoony stuff and computer art - supports transparency.

PNG

Portable Network Graphics uses lossless data compression. PNG is an open-source format that was created to improve upon the GIF. GIF was not open source and there were licensing costs to developers using the format. This was also a motivating factor in the uptake of the PNG.

SVG

Scalable Vector Graphics is a language for describing 2d graphics and graphical applications in XML. Principally used for vector graphics on the WWW.