Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moontaz/huffman-code-algorithm-v1
Implementation of Huffman Algorithm for encode and decode image using python
https://github.com/moontaz/huffman-code-algorithm-v1
binary-search-tree binary-tree huffman-coding huffman-compression-algorithm huffman-decoder huffman-decompression huffman-encoder image-compression
Last synced: about 12 hours ago
JSON representation
Implementation of Huffman Algorithm for encode and decode image using python
- Host: GitHub
- URL: https://github.com/moontaz/huffman-code-algorithm-v1
- Owner: Moontaz
- License: mit
- Created: 2023-12-21T06:43:41.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-22T07:28:18.000Z (about 1 year ago)
- Last Synced: 2024-11-05T10:15:14.944Z (about 2 months ago)
- Topics: binary-search-tree, binary-tree, huffman-coding, huffman-compression-algorithm, huffman-decoder, huffman-decompression, huffman-encoder, image-compression
- Language: Python
- Homepage:
- Size: 731 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](#overview)
- [Files in the Repository](#files-in-the-repository)
- [Usage](#usage)
- [Implementation Details](#implementation-details)
- [Sample Execution](#sample-execution)
- [Continuous Integration](#continuous-integration)
- [Documentation](#documentation)
- [Release Management](#release-management)
- [How to Contribute](#how-to-contribute)
- [Contact](#contact)
- [License](#license)## 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:
```bash
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:
```bash
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](https://moontaz.github.io/huffman-encoding-V1).
## 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](CONTRIBUTING.md) for details on how to get started.
## Contact
For inquiries, feedback, or collaboration opportunities, feel free to contact the project maintainer:
- Maintainer Name: Muhammad Mumtaz
- Maintainer Email: [email protected]## License [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
This project is licensed under the [MIT License](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!