0% found this document useful (0 votes)
42 views5 pages

Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Image Compression Using DCT and Huffman

Encoding:
A Comprehensive Analysis
Hardik Gohil
November 25, 2024

Contents
1 Introduction 2
1.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Problem Statement 2

3 Algorithm Description 2
3.1 Compression Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 Decompression Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

4 Datasets 3

5 Results 3
5.1 Evaluation Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.2 Visual Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.3 Graphs of RMSE vs BPP . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.4 Compression Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

6 Conclusion 5
6.1 Strengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
6.2 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1
1 Introduction
Image compression is an essential part of modern computing, aimed at reducing file size
while retaining image quality. This project implements and analyzes an image compres-
sion pipeline based on the Discrete Cosine Transform (DCT) and Huffman Encoding,
which are key components of the JPEG compression standard. The focus is on grayscale
images, and the algorithm’s performance is evaluated using metrics such as Bits Per Pixel
(BPP) and Root Mean Squared Error (RMSE).

1.1 Objectives
The primary goals of the project are:

• To implement an efficient image compression pipeline using DCT and Huffman


Encoding.

• To test the algorithm on a diverse set of grayscale images.

• To analyze the trade-off between compression efficiency and image quality across
varying quality factors.

• To highlight the strengths and limitations of the implemented algorithm.

2 Problem Statement
The challenge is to efficiently compress grayscale images by reducing their file sizes while
maintaining an acceptable level of visual quality. The compression process must also
accommodate varying levels of detail in images by allowing adjustable quality factors.

3 Algorithm Description
The implemented compression algorithm consists of the following steps:

3.1 Compression Pipeline


1. Preprocessing:

• Convert the image to single-channel grayscale.


• Apply zero-padding to ensure the dimensions are divisible by 8.

2. Block Processing:

• Divide the image into 8 × 8 blocks.


• Normalize the pixel values by subtracting 128 to center them around 0.

3. Discrete Cosine Transform (DCT):

• Compute the 2D DCT of each block to transform spatial data into the fre-
quency domain.

2
• This step concentrates most of the image’s energy into low-frequency coeffi-
cients.

4. Quantization:

• Apply a quality-factor-dependent quantization matrix to the DCT coefficients.


• High-frequency coefficients, which are less perceptually significant, are more
aggressively quantized.

5. Zigzag Ordering and Run-Length Encoding (RLE):

• Rearrange the quantized coefficients in zigzag order to prioritize low-frequency


coefficients.
• Use RLE to encode sequences of zeros efficiently.

6. Huffman Encoding:

• Apply Huffman Encoding to both DC and AC coefficients to further compress


the data.

7. Storage:

• Save the encoded data, Huffman dictionaries, and metadata in a binary format
using Python’s pickle module.

3.2 Decompression Pipeline


The decompression pipeline reverses the above steps:
1. Decode the Huffman bitstreams to retrieve DC and AC coefficients.

2. Reconstruct the quantized blocks using inverse zigzag ordering.

3. Dequantize the coefficients and apply the Inverse DCT (IDCT) to restore the image
blocks.

4. Combine the blocks to reconstruct the full image.

5. Crop the image to the original dimensions if padding was applied.

4 Datasets
The algorithm was tested on a dataset of 19 grayscale images from diverse sources. Each
image was preprocessed to ensure compatibility with the compression algorithm:
• Converted to single-channel grayscale format.

• Zero-padded to make dimensions divisible by 8.

5 Results
The detailed results for all images and all corresponding plots are stored here: https://drive.google.com/d

3
5.1 Evaluation Metrics
• Bits Per Pixel (BPP): Measures the compression efficiency by dividing the total
size of the compressed file by the number of pixels in the image.

• Root Mean Squared Error (RMSE): Quantifies the difference between the
original and decompressed images, indicating the quality of reconstruction.

5.2 Visual Results

Figure 1: Decompressed versions of an image at Q=10 (left) and Q=50 (right).

Figure 2: Other compressed image at Q = 100

4
Figure 3: BPP vs RMSE graph for Image 2.

5.3 Graphs of RMSE vs BPP


5.4 Compression Efficiency
The table below summarizes the compression results for a sample image:

Quality Factor BPP RMSE


10 0.3 7.2
50 1.38 6.1
100 1.9 4.1

Table 1: Summary of compression results for a sample image.

6 Conclusion
6.1 Strengths
• The algorithm effectively balances compression efficiency and image quality for low
to moderate quality factors.

• It is robust and compatible with various grayscale images.

6.2 Limitations
• For high-quality factors, the compressed file size can exceed the original size due to
metadata overhead.

• Compression artifacts are noticeable at very low quality factors.

• The algorithm does not currently support color images.

You might also like