Lossy compression

Lossy compression reduces the amount of data required to store a file. However, lossy compression also results in some loss of quality. JPEG images and MP3 sound files both make use of lossy compression. Despite a loss in quality, users are often unable to determine any major difference.

When an image is captured using a digital camera, it will be compressed and saved as a JPEG. Compressing images as JPEGs can reduce file size by more than 80 per cent, with little noticeable change visible to humans. Similarly, a compressed MP3 file may be one tenth the size of the original audio file and may sound almost identical.

Most lossy compression algorithms allow for various quality settings, which determine how much compression is applied to the file. The quality setting involves a trade-off between quality and file size. A file that uses greater compression will take up less space, but may not look or sound as good as a file with less compression applied.

Low compression image showing high detail contrasted with poor detail on high compression image.

Lossy techniques

It is important to know the following lossy compression techniques.

Perceptual coding

Perceptual coding is a lossy compression technique that is applied to sound. MP3 sound files make use of perceptual coding. Algorithms are used to remove some data from sound files. The algorithms focus on:

  • Removing sound captured at frequencies out with the dynamic range of human hearing
  • Removing frequencies that cannot be detected by the human ear because they play at the same time as higher more dominant frequencies

DCT encoding

Discrete Cosine Transform is a lossy compression technique that is applied to JPEG images. DCT encoding is a very difficult method to understand as it involves lots of mathematical complexity. It can be summarised as:

  • Converting an RGB (red, green, blue) image into three components known as YCbCr
  • The Y image will store data on brightness, the Cb and Cr images store data on colour

For each of the Y, Cb and Cr images the following steps are necessary:

  • Split the image into 8x8 pixel blocks
  • Apply cosine and huffman functions to eliminate frequencies used to represent colours that do not appear often in the 8x8 block

This happens for each of the Y, Cb and Cr images before they are combined and stored as a JPEG image. It is often the case that the data that has been removed will go unnoticed by users unless they apply a very high compression ratio at the time of DCT encoding.

Intraframe and Interframe compression

MPEG video files often make use of intraframe and interframe compression. Intraframe compression is simply the process of compressing each individual image (frame) in the video. In the case of MPEG videos, each individual JPEG frame is compressed using DCT encoding as described above. These frames are then known as i-frames.

Interframe compression is the process of only saving changes between i-frames. This is achieved by using p-frames and b-frames. A p-frame only stores the changes that exist between the previous i-frame and the current i-frame. It does this by disregarding any data that has not changed. A b-frame attempts to achieve greater compression by storing changes from both the previous and next i-frames, again by disregarding any data that does not change, either from the previous frame or in the next frame.