Practical Compression (Lab 6)

Published on December 25, 2023.

Practical compression refers to the process of reducing the size of digital data, such as files, images, audio, or video, to save storage space and enable more efficient transmission over networks. The primary goal is to minimize the amount of space required to store or transmit information while preserving its essential quality and content.

Compression algorithms employ various techniques, such as dictionary-based encoding, run-length encoding, Huffman coding, and discrete cosine transformation, to analyze and represent data more efficiently.


Uses Of Compression

Compression has several benefits that it offers to the digital world. Some of the benefits that I find noteworthy are;

  • Reduced Storage Requirements.

  • Faster Data Transfer.

  • Bandwidth Optimization.

  • Cost Savings

  • Preservation of data integrity.

Lab Practice

The following exercises demonstrate my participation in the lab for this lecture.

Before we get into the practice, the following paragraph explains how to calculate file compression ratio;

  • To determine the Compression Ratio for file conversions, you need to have the original image file size and divide it by the compressed image file size. I.e original_image_size / compressed_image_size.

Folder Compression

In this exercise, I will be working with a ZIP file provided for this lab on the Middlesex lab page for students.

The provided demo ZIP file has a size of 173KB as shown in the following image;

I will proceed to unzip the file to determine how much space was saved by zipping the file and its compression ratio. After unzipping, we can see the ZIP folder contains a Word document in .docx format.

QUESTIONS

  • How much space do we save by zipping a file?

The Word document extracted from the ZIP file had a size of 204KB as shown in the following image;

Doing the maths of subtracting the original ZIP file size from the extracted file size will give the exact amount of the space saved.

original file size = 173KB

extracted file size = 205KB

extracted_file_size - original_file_size = 205 - 173 = 32KB.

Thus, 32KB was saved by compressing the Word document into a ZIP file.


  • What is the compression ratio?

There was an increase in the original file size after unzipping rather than compression. The following calculation shows the ratio;


Original image size = 173 KB

Compressed image size = 205 KB

Compression Ratio = 173 KB / 205 KB

Compression Ratio ≈ 0.8439


Image Compression

First, I need to open a photo taken with my mobile phone into GIMP on my MacBook.

I will be using the photo I took recently of a Meaty Lasagne meal that I had at an Italian restaurant. The image has a size of 3.3MB and is in .png format.

I will open the same image using the GNU Image Manipulation Program (GIMP). GIMP offers various features to manipulate images.

Next, I will use the Export As feature of GIMP to export the meal image into a Bitmap (.bmp) format derive answers to the following questions. We need to select the Windows BMP Image option from the Select File Type dropdown.


QUESTIONS

  • How much larger is the file after converting to Bitmap?

Before converting, the image file had an original size of 3.33MB. After converting, the image file size grew to a whopping 36.6MB 😱🤯!

The increase in the image above was expected to happen as Bitmap is a lossless format, and it does not use any compression, unlike PNG. Converting the image back from Bitmap to PNG will drastically reduce the size.

  • What is the compression ratio?

Using our understanding of how to derive compression ratio, the compression ratio for the conversion above is;

Original image size = 3.33MB

Compressed image size = 36.6MB

original_image_size / compressed_image_size = 0.0909

Thus, the compression ratio here is 0.0909.

Tutorial On Image Compression

An amazing tutorial on image compression is the one below that explains how the JPEF format works and why images stored in it have smaller sizes;

Further Resources