UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
DIGITAL IMAGE PROCESSING
LAB MANUAL 12
Python-based implementation of image compression techniques
1. Fundamentals of Image Compression
2. Data VS Information
3. Data Redundancy
4. Coding Redundancy
5. Interpixel Redundancy
6. Psychovisual Redundancy
7. Fidelity Criteria
8. Image Compression Model
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
LAB OBJECTIVE:
The objective of this lab is to understand the Python-based implementation of image compression
techniques:
1. Fundamentals of Image Compression
2. Background
3. Overview
4. Data VS Information
5. Data Redundancy
6. Coding Redundancy
7. Interpixel Redundancy
8. Psychovisual Redundancy
9. Fidelity Criteria
10. Image Compression Model
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Fundamentals of Image Compression
Image compression is the process of reducing the size of an image file without excessively
compromising its quality.
Goal: Reduce storage and bandwidth usage.
Lossless Compression: No data is lost. Eg: PNG.
Lossy Compression: Some data is lost. Eg: JPEG.
Compression influences redundancy in image data to reduce file size.
Pixels in images often share similarities which can be exploitedexploited). repeated pixels can be
used
Overview
The image compression process involves:
Transformation : Transforms the image into a domain where redundancy can be better
exploited. (e.g., DCT, Wavelet)
Quantization Reduces the precision of transformed coefficients to remove less-important
[Link] only lossy step in JPEG!
Encoding (e.g., Huffman, Run Length) Encodes the quantized coefficients into a compact
bitstream.
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Traditional Image Compression Models
1. Run-Length Encoding (RLE) — Lossless
RLE compresses data by identifying consecutive repeated values and storing them as a single value
and count.
Example:
Original: AAAABBBCCDAA
RLE: (A,4)(B,3)(C,2)(D,1)(A,2)
In images: Best used on binary or simple-color images (e.g., icons, faxes, scans).
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Advantages:
Simple and fast.
Efficient for images with large areas of flat color.
Disadvantages:
Poor compression on high-detail or noisy images.
2. Huffman Coding — Lossless
Concept:
Huffman builds a variable-length prefix code based on pixel frequency.
More frequent values get shorter codes.
Steps:
Count pixel frequencies.
Build a binary tree (Huffman Tree).
Assign binary codes.
Encode image using these codes.
In images: Often used as part of other formats (e.g., JPEG, PNG internally use it).
Advantages:
Good compression for natural images.
Always lossless.
Disadvantages:
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Overhead in storing the codebook.
Inefficient for small images or uniformly distributed values.
3. PNG (Portable Network Graphics) — Lossless
Model: Uses LZ77 + Huffman Coding.
First, it applies filtering (prediction).
Then compresses using DEFLATE (LZ77 + Huffman).
Advantages:
Perfect image quality.
Supports transparency (alpha channel).
Great for line art, screenshots, logos.
Disadvantages:
Larger file sizes than lossy formats (e.g., JPEG).
Slower compression.
4. JPEG (Joint Photographic Experts Group) — Lossy
Model:
Convert image to YCbCr color space.
Downsample chroma channels.
Divide image into 8×8 blocks.
Apply Discrete Cosine Transform (DCT).
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Quantize the DCT coefficients (lossy step).
Apply Zigzag scan + Huffman Coding
Advantages:
High compression ratio.
Ideal for photographs.
Disadvantages:
Loss of quality (especially after multiple saves).
Not good for sharp edges or text.
Data Redundancy
There are three main types of redundancies:
Coding Redundancy
Interpixel Redundancy
Psychovisual Redundancy
Coding Redundancy
Occurs when more bits than necessary are used to represent data.
Huffman Coding
Huffman encoding is ideal for images where pixel values have skewed frequency distributions.
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
It means that some pixel values occur much more frequently than others.
An image where 70% of the pixels are shades of gray (e.g., value 128), and only a few pixels
are very dark or very bright.
Image compression reduces file size by removing redundant information.
Huffman encoding is a form of lossless compression that assigns shorter binary codes to more
frequent data values.
Huffman coding builds a binary prefix tree where:
Frequent values get shorter codes (e.g., 0, 10)
Rare values get longer codes (e.g., 11101)
Huffman Encoding for Image Compression in Python
Upload Grayscale Image (with preview)
Analyze Pixel Frequency (bar chart)
Build Huffman Tree & Codebook
Encode Image using Huffman
Show Compression Ratio
Visualize Huffman Code Length
import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image, ImageTk
from collections import Counter
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
import heapq
import [Link] as plt
import os
import json
import pickle
class HuffmanApp:
def __init__(self, root):
[Link] = root
[Link]("Huffman Image Compression")
[Link]("800x700")
[Link] = None
self.reconstructed_img = None
[Link] = []
[Link] = []
self.encoded_data = ""
self.original_bits = 0
self.compressed_bits = 0
self.setup_gui()
def setup_gui(self):
title = [Link]([Link], text=" Huffman Image Compression
Tool", font=("Arial", 16, "bold"))
[Link](pady=10)
self.image_label = [Link]([Link])
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
self.image_label.pack(pady=5)
self.reconstructed_label = [Link]([Link])
self.reconstructed_label.pack(pady=5)
btn_frame = [Link]([Link])
btn_frame.pack(pady=10)
buttons = [
(" Upload Image", self.upload_image),
(" Pixel Frequency", self.pixel_frequency),
(" Build Huffman Codebook", self.build_codebook),
(" Encode Image", self.encode_image),
(" Show Compression Ratio", self.show_compression),
(" Show Code Lengths", self.show_code_lengths),
(" Save Compressed File", self.save_compressed),
(" Load & Decode File", self.load_compressed),
(" Decode & Reconstruct Image", self.decode_image),
(" Export Compression Report", self.export_report)
]
for i, (text, command) in enumerate(buttons):
[Link](btn_frame, text=text, command=command, width=35,
height=2).grid(row=i, column=0, pady=5)
def upload_image(self):
file_path = [Link](filetypes=[("Images",
"*.jpg *.jpeg *.png *.bmp")])
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
if not file_path:
return
[Link] = [Link](file_path).convert("L")
[Link] = list([Link]())
img_display = [Link]((200, 200))
self.tk_img = [Link](img_display)
self.image_label.configure(image=self.tk_img)
self.reconstructed_label.configure(image="")
[Link]("Image Uploaded", "Grayscale image loaded
successfully!")
def pixel_frequency(self):
if not [Link]:
[Link]("Error", "Please upload an image
first.")
return
freq = Counter([Link])
[Link](figsize=(10, 4))
[Link]([Link](), [Link](), width=1.0)
[Link]("Pixel Frequency Distribution")
[Link]("Pixel Value (0-255)")
[Link]("Frequency")
[Link](True, linestyle='--', alpha=0.4)
plt.tight_layout()
[Link]()
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
def huffman_encode(self, data):
freq = Counter(data)
heap = [[weight, [symbol, ""]] for symbol, weight in
[Link]()]
[Link](heap)
while len(heap) > 1:
lo = [Link](heap)
hi = [Link](heap)
for pair in lo[1:]:
pair[1] = '0' + pair[1]
for pair in hi[1:]:
pair[1] = '1' + pair[1]
[Link](heap, [lo[0] + hi[0]] + lo[1:] + hi[1:])
return sorted([Link](heap)[1:], key=lambda p: (len(p[1]),
p[0]))
def build_codebook(self):
if not [Link]:
[Link]("Error", "Please upload an image
first.")
return
[Link] = self.huffman_encode([Link])
top_codes = "\n".join([f"Pixel {symbol}: {code}" for symbol,
code in [Link][:10]])
[Link]("Top 10 Huffman Codes", top_codes)
def encode_image(self):
if not [Link]:
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
[Link]("Error", "Build Huffman codebook
first.")
return
huff_dict = {symbol: code for symbol, code in [Link]}
self.encoded_data = ''.join(huff_dict[p] for p in [Link])
self.original_bits = len([Link]) * 8
self.compressed_bits = len(self.encoded_data)
[Link]("Encoded", "Image has been Huffman encoded.")
def show_compression(self):
if not self.encoded_data:
[Link]("Error", "Please encode the image
first.")
return
ratio = self.original_bits / self.compressed_bits if
self.compressed_bits != 0 else 0
info = f"Original Bits: {self.original_bits}\n" \
f"Compressed Bits: {self.compressed_bits}\n" \
f"Compression Ratio: {ratio:.2f}"
[Link]("Compression Results", info)
def show_code_lengths(self):
if not [Link]:
[Link]("Error", "Generate Huffman codebook
first.")
return
code_lengths = [len(code) for _, code in [Link]]
symbols = [symbol for symbol, _ in [Link]]
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
[Link](figsize=(10, 4))
[Link](symbols, code_lengths, width=1.0)
[Link]("Huffman Code Lengths per Pixel")
[Link]("Pixel Value")
[Link]("Code Length (bits)")
[Link](True, linestyle='--', alpha=0.4)
plt.tight_layout()
[Link]()
def save_compressed(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please encode the image
first.")
return
file = [Link](defaultextension=".huff",
filetypes=[("Huffman Compressed", "*.huff")])
if not file:
return
data = {
"encoded": self.encoded_data,
"codebook": [Link],
"size": [Link]
}
with open(file, "wb") as f:
[Link](data, f)
[Link]("Saved", "Compressed file saved
successfully.")
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
def load_compressed(self):
file = [Link](filetypes=[("Huffman
Compressed", "*.huff")])
if not file:
return
with open(file, "rb") as f:
data = [Link](f)
self.encoded_data = data["encoded"]
[Link] = data["codebook"]
self.img_size = data["size"]
[Link]("Loaded", "Compressed file loaded. Ready to
decode.")
def decode_image(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please load compressed data
first.")
return
reverse_codebook = {code: symbol for symbol, code in
[Link]}
temp_code = ""
decoded_pixels = []
for bit in self.encoded_data:
temp_code += bit
if temp_code in reverse_codebook:
decoded_pixels.append(reverse_codebook[temp_code])
temp_code = ""
self.reconstructed_img = [Link]("L", self.img_size)
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
self.reconstructed_img.putdata(decoded_pixels)
img_disp = self.reconstructed_img.resize((200, 200))
self.tk_reconstructed = [Link](img_disp)
self.reconstructed_label.configure(image=self.tk_reconstructed)
[Link]("Reconstructed", "Image successfully
reconstructed.")
def export_report(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please encode the image
first.")
return
file = [Link](defaultextension=".txt",
filetypes=[("Text files", "*.txt")])
if not file:
return
with open(file, "w") as f:
[Link](f"Original Bits: {self.original_bits}\n")
[Link](f"Compressed Bits: {self.compressed_bits}\n")
[Link](f"Compression Ratio: {self.original_bits /
self.compressed_bits:.2f}\n")
[Link]("\nTop 10 Huffman Codes:\n")
for symbol, code in [Link][:10]:
[Link](f"Pixel {symbol}: {code}\n")
[Link]("Exported", "Compression report saved
successfully.")
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
if __name__ == "__main__":
root = [Link]()
app = HuffmanApp(root)
[Link]()
1. Import Libraries
from PIL import Image
from collections import Counter
import heapq
import [Link] as plt
import numpy as np
2. Load and Convert Image to Grayscale
img = [Link]("[Link]").convert("L")
img_array = [Link](img)
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
4. Analyze Pixel Frequency
This function calculates the frequency of each pixel value using Counter([Link]) and displays a
histogram using matplotlib.
pixels = list([Link]())
pixel_counts = Counter(pixels)
5. Building the Huffman Codebook
def huffman_encode(self, data):
freq = Counter(data)
heap = [[weight, [symbol, ""]] for symbol, weight in [Link]()]
[Link](heap)
while len(heap) > 1:
lo = [Link](heap)
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
hi = [Link](heap)
for pair in lo[1:]:
pair[1] = '0' + pair[1]
for pair in hi[1:]:
pair[1] = '1' + pair[1]
[Link](heap, [lo[0] + hi[0]] + lo[1:] + hi[1:])
return sorted([Link](heap)[1:], key=lambda p: (len(p[1]),
p[0]))
This function builds a Huffman codebook from the pixel data
It calculates the frequency of each pixel, builds a priority queue (min-heap) using heapq, and
iteratively merges the least frequent symbols to form the Huffman tree.
The final result is a sorted list of pixel symbols with their corresponding Huffman codes.
6. Encoding the Image
def encode_image(self):
if not [Link]:
[Link]("Error", "Build Huffman codebook first.")
return
huff_dict = {symbol: code for symbol, code in [Link]}
self.encoded_data = ''.join(huff_dict[p] for p in [Link])
self.original_bits = len([Link]) * 8
self.compressed_bits = len(self.encoded_data)
[Link]("Encoded", "Image has been Huffman encoded.")
This function encodes the image by replacing each pixel value with its corresponding Huffman
code from the codebook.
It calculates the number of bits in the original and encoded data to determine the compression
ratio.
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
7. Saving the Compressed File
def save_compressed(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please encode the image first.")
return
file = [Link](defaultextension=".huff",
filetypes=[("Huffman Compressed", "*.huff")])
if not file:
return
data = {
"encoded": self.encoded_data,
"codebook": [Link],
"size": [Link]
}
with open(file, "wb") as f:
[Link](data, f)
[Link]("Saved", "Compressed file saved successfully.")
Save Compressed Data: The function saves the encoded image, codebook, and image size
into a .huff file using pickle.
This allows the user to store the compressed data for future use.
8. Loading and Decoding the Compressed File
def load_compressed(self):
file = [Link](filetypes=[("Huffman Compressed",
"*.huff")])
if not file:
return
with open(file, "rb") as f:
data = [Link](f)
self.encoded_data = data["encoded"]
[Link] = data["codebook"]
self.img_size = data["size"]
[Link]("Loaded", "Compressed file loaded. Ready to
decode.")
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Load Compressed Data: The function allows users to load a previously saved compressed file.
The encoded data, codebook, and image size are extracted and stored.
9. Decoding the Image
def decode_image(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please load compressed data
first.")
return
reverse_codebook = {code: symbol for symbol, code in [Link]}
temp_code = ""
decoded_pixels = []
for bit in self.encoded_data:
temp_code += bit
if temp_code in reverse_codebook:
decoded_pixels.append(reverse_codebook[temp_code])
temp_code = ""
self.reconstructed_img = [Link]("L", self.img_size)
self.reconstructed_img.putdata(decoded_pixels)
img_disp = self.reconstructed_img.resize((200, 200))
self.tk_reconstructed = [Link](img_disp)
self.reconstructed_label.configure(image=self.tk_reconstructed)
[Link]("Reconstructed", "Image successfully
reconstructed.")
Decode Image: This function decodes the compressed image using the Huffman codebook.
It iterates through the encoded data, mapping Huffman codes back to pixel values.
It reconstructs the image and displays it.
10. Exporting the Compression Report
def export_report(self):
if not self.encoded_data or not [Link]:
[Link]("Error", "Please encode the image first.")
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
return
file = [Link](defaultextension=".txt",
filetypes=[("Text files", "*.txt")])
if not file:
return
with open(file, "w") as f:
[Link](f"Original Bits: {self.original_bits}\n")
[Link](f"Compressed Bits: {self.compressed_bits}\n")
[Link](f"Compression Ratio: {self.original_bits /
self.compressed_bits:.2f}\n")
[Link]("\nTop 10 Huffman Codes:\n")
for symbol, code in [Link][:10]:
[Link](f"Pixel {symbol}: {code}\n")
[Link]("Exported", "Compression report saved
successfully.")
Export Report: This function allows the user to export a report summarizing the compression stats
(original bits, compressed bits, ratio) and the top 10 Huffman codes in a .txt file.
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Output
step-by-step process for uploading an image, compressing it with Huffman encoding,
saving/loading the compressed file, and decoding/reconstructing the image. Additionally, it allows
for exporting a detailed compression report.
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
1. Interpixel Redundancy
Neighboring pixels in an image are often similar.
Technique: Predictive coding (store differences rather than actual values).
import numpy as np
def predictive_encode(image):
height, width = [Link]
diff_img = np.zeros_like(image)
for i in range(height):
for j in range(1, width):
diff_img[i, j] = image[i, j] - image[i, j-1]
return diff_img
2. Psychovisual Redundancy
Human vision is less sensitive to certain frequencies.
Solution: Remove or reduce visually less important information (as in JPEG using DCT and
quantization).
from [Link] import dct, idct
def apply_dct(block):
return dct(dct(block.T, norm='ortho').T, norm='ortho')
def quantize(block, q_matrix):
return [Link](block / q_matrix)
# JPEG-like 8x8 block compression
q_matrix = [Link]([[16,11,10,16,24,40,51,61],
[12,12,14,19,26,58,60,55],
[14,13,16,24,40,57,69,56],
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
[14,17,22,29,51,87,80,62],
[18,22,37,56,68,109,103,77],
[24,35,55,64,81,104,113,92],
[49,64,78,87,103,121,120,101],
[72,92,95,98,112,100,103,99]])
Fidelity Criteria
Used to evaluate image quality after compression.
It measure how much the image has degraded or preserved its original quality.
MSE (Mean Squared Error) average squared differences between corresponding pixel values
in the original and compressed images
PSNR (Peak Signal-to-Noise Ratio) measures the ratio between the maximum possible power
of a signal (the original image) and the power of noise (the error introduced by compression).
def psnr(original, compressed):
mse = [Link]((original - compressed) ** 2)
if mse == 0:
return float('inf')
max_pixel = 255.0
return 20 * np.log10(max_pixel / [Link](mse))
Digital Image Processing 6th Term-SE UET Taxila
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Lab Task
Design a Tkinter-based GUI Image Compression App that:
1. Upload an image (grayscale).
2. Analyze pixel frequency and visualize it.
3. Build Huffman codebook and encode the image using Huffman.
4. Encode the image using RLE.
5. Decode and reconstruct the image from Huffman and RLE.
6. Save the compressed bitstream to a file.
7. Compare compression ratios between Huffman and RLE.
8. Visualize Huffman code lengths.
Digital Image Processing 6th Term-SE UET Taxila