{"id":21140217,"url":"https://github.com/mrinankmj/lossless_image_compression","last_synced_at":"2025-03-14T13:11:11.322Z","repository":{"id":263234810,"uuid":"889755538","full_name":"mrinankmj/Lossless_Image_compression","owner":"mrinankmj","description":"A MATLAB project for lossless image compression using Huffman Encoding. It efficiently compresses images without quality loss, preserving original data while reducing file size.","archived":false,"fork":false,"pushed_at":"2024-11-17T06:23:46.000Z","size":773,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T06:43:56.958Z","etag":null,"topics":["huffman-coding","imagecompression","matlab"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrinankmj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-17T06:21:41.000Z","updated_at":"2024-11-17T06:29:32.000Z","dependencies_parsed_at":"2024-11-17T07:38:42.058Z","dependency_job_id":null,"html_url":"https://github.com/mrinankmj/Lossless_Image_compression","commit_stats":null,"previous_names":["mrinankmj/lossless_image_compression"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrinankmj%2FLossless_Image_compression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrinankmj%2FLossless_Image_compression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrinankmj%2FLossless_Image_compression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrinankmj%2FLossless_Image_compression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrinankmj","download_url":"https://codeload.github.com/mrinankmj/Lossless_Image_compression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243581088,"owners_count":20314167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["huffman-coding","imagecompression","matlab"],"created_at":"2024-11-20T07:08:51.789Z","updated_at":"2025-03-14T13:11:11.293Z","avatar_url":"https://github.com/mrinankmj.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Lossless Color Image Compression Using PNG and Huffman Coding\n\n## Overview\nThis MATLAB project implements **lossless color image compression** by combining the PNG format and **Huffman coding** for further optimization. The aim is to reduce the image size while maintaining the original quality. Additionally, the **PSNR (Peak Signal-to-Noise Ratio)** is calculated to measure the quality of the decoded image compared to the original.\n\n### Features:\n- **PNG Compression**: Saves the image in PNG format, a widely used lossless compression method.\n- **Huffman Coding**: Each color channel (Red, Green, Blue) is encoded separately using Huffman coding, further compressing the image data.\n- **Compression Ratio**: Displays the ratio of the original image size to the compressed image size.\n- **PSNR Calculation**: Provides the PSNR value to evaluate the quality of the decompressed image.\n\n## Steps Involved\n1. **Image Selection**: The user selects an image file from their system (supports PNG, JPG, BMP, TIFF).\n2. **PNG Compression**: The selected image is compressed using the PNG format.\n3. **Huffman Coding**: Each color channel (R, G, B) of the image is encoded using Huffman coding.\n4. **Huffman Decoding**: The encoded image is decoded to restore the original image.\n5. **Comparison**: The script compares the original image, compressed PNG, and Huffman-encoded data sizes.\n6. **PSNR Calculation**: The Peak Signal-to-Noise Ratio is calculated to measure the similarity between the original and decoded images.\n\n## File Descriptions\n- **Main Script**: Contains the complete code for reading, compressing, encoding, decoding, and calculating the PSNR of the image.\n- **encoded_image.mat**: Stores the Huffman-encoded data and dictionaries for each color channel.\n- **compressed_image.png**: The PNG-compressed version of the selected image.\n- **decoded_image.png**: The image after Huffman decoding, saved as PNG for comparison.\n\n## Usage Instructions\n\n### Prerequisites\nYou need **MATLAB** installed on your system to run this project.\n\n### Running the Code\n1. Clone this repository:\n   ```bash\n   git clone https://github.com/mrinankmj/lossless_image_compression.git\n   ```\n2. Navigate to the project directory in MATLAB.\n3. Run the `LOSS.m` script:\n   ```matlab\n   LOSS\n   ```\n4. A file selector window will appear, prompting you to select an image from your system (PNG, JPG, BMP, or TIFF).\n5. After selecting the image, the script will:\n   - Display the original and decoded images.\n   - Show the compression ratio and the PSNR of the decoded image.\n   - Save the compressed and decoded images in the project folder.\n\n### Example Output:\n```bash\nCompression Ratio: 1.45\nOriginal image size: 156.24 KB\nCompressed image size (PNG): 108.75 KB\nEncoded Huffman data size: 98.34 KB\nDecoded image size: 156.22 KB\nPSNR: 40.12 dB\n```\n\n## Code Breakdown\n### Main Steps:\n1. **Read the Image**: Allows the user to select an image file from their device.\n2. **PNG Compression**: Uses MATLAB’s `imwrite` function to save the image as a PNG.\n3. **Huffman Encoding**: The script splits the image into Red, Green, and Blue channels and compresses each channel using Huffman coding.\n4. **Decoding**: The encoded image is decoded using the Huffman dictionaries and reshaped to its original size.\n5. **PSNR Calculation**: The quality of the decoded image is measured using the `psnr` function, comparing it to the original image.\n\n### Functions:\n- **huffman_encode**: Encodes a color channel using Huffman coding based on pixel intensity frequencies.\n- **huffman_decode**: Decodes the Huffman-encoded data for a color channel and reshapes it to the original dimensions.\n\n## Contributions\nFeel free to submit pull requests or issues if you find any bugs or want to enhance the functionality.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrinankmj%2Flossless_image_compression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrinankmj%2Flossless_image_compression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrinankmj%2Flossless_image_compression/lists"}