/Huffman-Code-Algorithm-V1

Implementation of Huffman Algorithm for encode and decode image using python

Primary LanguagePythonMIT LicenseMIT

Huffman Encoding for Image Compression

This comprehensive GitHub repository contains a Python implementation of the Huffman Encoding algorithm for compressing and decompressing images. Huffman Encoding is a lossless data compression technique that assigns variable-length codes to input characters, providing efficient compression for data with varying symbol frequencies.

Table of Contents

Overview

The primary goal of this project is to showcase the application of Huffman Encoding in image compression. The repository includes Python scripts and modules that demonstrate the compression and decompression processes, along with detailed implementation of the Huffman Coding algorithm.

Files in the Repository

  1. useHuffman.py: This script serves as an example of using Huffman Encoding to compress an image. It utilizes the HuffmanCoding class from the huffman_img.py module.

  2. huffman_img.py: The module contains the implementation of the Huffman Coding algorithm for image compression. It includes a HuffmanCoding class with methods for compressing and decompressing images.

  3. decompress_huffman_image.py: This script provides functionality to decompress a previously compressed image using the Huffman Coding algorithm.

  4. use_decompress.py: This script demonstrates how to decompress a previously compressed image using the decompress_huffman_image.py module.

  5. dataset_image1.jpg: Sample image for testing and experimentation.

Usage

Compression

To compress an image, run the useHuffman.py script:

python useHuffman.py

This script takes an input image (specified within the script) and generates a compressed binary file (dataset_image1_compressed.bin). The compressed file includes the Huffman tree structure, encoded pixel data, and metadata for decompression.

Decompression

To decompress the compressed image, run the use_decompress.py script:

python use_decompress.py

This script reads the compressed binary file, reconstructs the Huffman tree, decodes the pixel data, and saves the decompressed image (dataset_image1_decompressed.jpg).

Advantages and Disadvantages

Advantages

  1. Only need two file(image dataset, source code for compress and decompress).
  2. Output file from compression just a bin file. It's include binary code of image, pixels, python file for decompress and separated by unique code.

Disadvantages

  1. File decompress become bigger than before, i think there are something wrong with binary tree structure for get binary code
  2. Source code is untidy

Implementation Details

The Huffman Coding algorithm is implemented in the HuffmanCoding class within huffman_img.py. Key implementation details include:

  • Construction of a Huffman tree based on pixel frequency.
  • Generation of variable-length codes for each pixel.
  • Compression of pixel data into a binary format.
  • Decompression using the Huffman tree and encoded binary data.

Sample Execution

Here is a brief overview of a sample execution:

  1. Compression:

    • Run useHuffman.py.
    • Input: dataset_image1.jpg.
    • Output: dataset_image1_compressed.bin.
  2. Decompression:

    • Run use_decompress.py.
    • Input: dataset_image1_compressed.bin.
    • Output: dataset_image1_decompressed.jpg.

Continuous Integration

The repository is integrated with a continuous integration (CI) system, ensuring that changes made to the codebase are automatically tested. This helps maintain code quality and prevents regressions.

CI Pipeline

The CI pipeline consists of the following stages:

  1. Linting: Ensures code adheres to style guidelines and best practices.

  2. Unit Tests: Executes a suite of unit tests to validate the functionality of the Huffman Encoding implementation.

  3. Integration Tests: Performs integration tests to verify the interoperability of different components.

  4. Code Coverage: Measures the code coverage achieved by the tests, providing insights into the areas of the codebase that are thoroughly tested.

Documentation

The documentation is automatically generated and hosted, providing up-to-date information about the codebase. Users and contributors can refer to the documentation for detailed usage instructions, API references, and examples.

The documentation can be found at GitHub Pages.

Release Management

The repository follows a versioning scheme, and releases are managed through GitHub. Each release includes release notes, summarizing changes and improvements made in that version.

How to Contribute

Contributions to the project are welcomed. Whether it's fixing bugs, implementing new features, or improving documentation, every contribution is valuable. Refer to the Contribution Guidelines for details on how to get started.

Contact

For inquiries, feedback, or collaboration opportunities, feel free to contact the project maintainer:

License License: MIT

This project is licensed under the MIT License. By contributing to this project, you agree to abide by the terms of this license.

Thank you for your interest in the Huffman Encoding project. Together, let's make compression and decompression more efficient and accessible!