0% found this document useful (0 votes)
9 views9 pages

FOSIP_10_ImageCompression

The document outlines an experiment aimed at performing image compression using the Gzip algorithm, which combines LZ77 and Huffman techniques. The objective is to reduce data redundancy and file size while maintaining quality during compression and decompression. The implementation includes Python code for compressing images, calculating metrics, and displaying comparisons between original and compressed images.

Uploaded by

varsha bojja
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)
9 views9 pages

FOSIP_10_ImageCompression

The document outlines an experiment aimed at performing image compression using the Gzip algorithm, which combines LZ77 and Huffman techniques. The objective is to reduce data redundancy and file size while maintaining quality during compression and decompression. The implementation includes Python code for compressing images, calculating metrics, and displaying comparisons between original and compressed images.

Uploaded by

varsha bojja
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
You are on page 1/ 9

Name Tejas Billava (2022300009)

Sushant Bodade (2022300010)


Varsha Bojja (2022300012)

Class: TE Comps A

Experiment 10

AIM : Perform Image Compression Operation

OBJECTIVE: ● To reduce data redundancy in files (images and documents) during


compression.
● To conserve more hardware space and transmission bandwidth by reducing the
file size through compression.
● To enable faster and efficient data transfer without loss of quality by
maintaining the quality of the file after decompression.
● To perform compression and decompression of files without losing any data or
compromising the quality of the original file.

INTRODUCTION: This paper proposes using the Gzip algorithm for image and document compression,
which combines Lz77 and Huffman techniques. Compression and decompression are
vital in document management and communication systems. Image compression,
particularly, is advantageous in digital image processing. The goal is to reduce
redundancy in images and documents to efficiently store or transmit data. This
approach conserves hardware space and bandwidth. In our proposed system, we
achieve reduced data size without quality loss.
BLOCK
DIAGRAM:
Block Diagram
IMPLEMENTATION: from PIL import Image
import os
import numpy as np
import matplotlib.pyplot as plt

# List your manually uploaded image filenames here


input_images = ['image1.jpg', 'image2.jpg']

# Create output directory for saving compressed images


os.makedirs('outputs', exist_ok=True)

def compress_image(input_image_path,
compressed_image_path, quality=80):
original_image = Image.open(input_image_path)
original_size = os.path.getsize(input_image_path)

original_image.save(compressed_image_path, 'JPEG',
quality=quality, optimize=True)
compressed_size =
os.path.getsize(compressed_image_path)

return original_size, compressed_size

def calculate_metrics(original_image_path,
compressed_image_path):
original_image =
Image.open(original_image_path).convert('RGB')
compressed_image =
Image.open(compressed_image_path).convert('RGB')

original_array = np.array(original_image)
compressed_array = np.array(compressed_image)
mse = np.mean((original_array - compressed_array) **
2)
max_pixel = 255.0
psnr = 20 * np.log10(max_pixel / np.sqrt(mse)) if mse
!= 0 else float('inf')

original_size = os.path.getsize(original_image_path)
compressed_size =
os.path.getsize(compressed_image_path)
bpp_original = (original_size * 8) /
(original_image.size[0] * original_image.size[1])
bpp_compressed = (compressed_size * 8) /
(compressed_image.size[0] * compressed_image.size[1])

return mse, psnr, bpp_original, bpp_compressed

def display_images(original_path, compressed_path,


title=''):
original_img = Image.open(original_path)
compressed_img = Image.open(compressed_path)

fig, axes = plt.subplots(1, 2, figsize=(10, 5))


axes[0].imshow(original_img)
axes[0].set_title('Original')
axes[0].axis('off')

axes[1].imshow(compressed_img)
axes[1].set_title('Compressed')
axes[1].axis('off')

plt.suptitle(title)
plt.tight_layout()
plt.show()

# Process each image


for img in input_images:
print(f"\nProcessing {img}...")

compressed_path = f'outputs/compressed_{img}'

original_size, compressed_size = compress_image(img,


compressed_path)

print(f'Original size: {original_size} bytes')


print(f'Compressed size: {compressed_size} bytes')

mse, psnr, bpp_orig, bpp_comp =


calculate_metrics(img, compressed_path)
print(f'MSE: {mse:.2f}')
print(f'PSNR: {psnr:.2f} dB')
print(f'BPP (Original): {bpp_orig:.2f}')
print(f'BPP (Compressed): {bpp_comp:.2f}')

display_images(img, compressed_path,
title=f'Comparison for {img}')
OUTPUT:
REFERENCE: K. Anand, M. Priyadharshini and K. Priyadharshini, "Compression And
Decompression Of Files Without Loss Of Quality," 2023 International Conference on
Networking and Communications (ICNWC), Chennai, India, 2023, pp. 1-6, doi:
10.1109/ICNWC57852.2023.10127236. keywords: {Image quality;Image
coding;Communication systems;Digital images;Redundancy;Data
compression;Bandwidth;Lz77;Gzip;Hybrid algorithm},

https://ieeexplore.ieee.org/document/10127236

CONCLUSION:
The proposed Gzip algorithm, integrating LZ77 and Huffman coding, efficiently compresses and decompresses
images and documents without sacrificing quality. It reduces data redundancy, conserves space, boosts
bandwidth, and maintains file integrity, offering a practical solution for compression and decompression needs.

You might also like