Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lossless Color Image Compression using Huffman Coding

A Python-based implementation of the Huffman Coding algorithm for efficient, lossless compression and decompression of color images. This project demonstrates how frequency-based encoding can reduce file size without losing a single pixel of quality.

🚀 Features

  • True Lossless Compression: Recovers the original image pixel-for-pixel.
  • Color Support: Handles RGB color tuples using custom Huffman Tree logic.
  • Modular Architecture: Separated logic for the algorithm, file handling, and main execution.
  • Real-time Statistics: Calculates original vs. compressed size and saving percentage.
  • Accuracy Verification: Built-in check to verify decompressed data integrity.

🛠️ Project Structure

  • main.py: The entry point that orchestrates the compression and decompression flow.
  • huffman_logic.py: Contains the core algorithm, Node class, and tree traversal logic.
  • file_handler.py: Manages bit-packing, padding, and binary file I/O operations.
  • test_image.jpg: Sample input image for testing.

📊 How It Works

  1. Frequency Analysis: The script reads the image and counts the occurrences of each unique (R, G, B) pixel tuple.
  2. Building the Tree: A Min-Heap is used to build a Huffman Tree where frequent colors get shorter binary codes.
  3. Encoding: Every pixel is replaced by its corresponding Huffman bit-string.
  4. Bit-Packing: Since bits cannot be saved directly, the bits are padded and packed into 8-bit bytes for storage in a .bin file.
  5. Decompression: The binary file is read, padding is removed, and the Huffman Tree is traversed to reconstruct the original pixels.

💻 Installation & Usage

Prerequisites

  • Python 3.x
  • OpenCV & NumPy
pip install opencv-python numpy
git clone [https://github.com/true-brace05/huffman_coding.git](https://github.com/true-brace05/huffman_coding.git)
cd huffman_coding
python3 main.py

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages