eawariyah / GreyscaleRunLengthCompressionDecompression

A collection of scripts and tools for image processing and compression using Python. Whether you're interested in exploring image quantization, Run-Length Encoding (RLE), or visualizing grayscale images, this repository has something for you. Feel free to explore the various scripts and contribute to the project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grayscale Run-Length Encoding (RLE) Project

This project provides a set of Python scripts to perform grayscale image Run-Length Encoding (RLE) compression and decoding. It includes scripts for converting images to and from CSV format, quantizing images, performing RLE encoding, and decoding RLE-encoded images. Additionally, scripts for visualizing images and comparing file sizes before and after compression are provided.

Sample Images

Below are side-by-side comparisons of various images:

Original Image Quantized Image (16 batch) Quantized Image (32 batch)
Original Image Quantized Image (16 batch) Quantized Image (32 batch)

File Sizes Comparison

Size Lossless Lossy Lossy
Original 16 batch 32 batch
Encoded (Compressed) 8.43 mb 6.41 mb 4.87 mb
Decoded (Decompressed) 6.25 mb 6.27 mb 6.27 mb

Overview

The project contains the following scripts:

  • ConvertCSVToImage.py: Converts a CSV file containing pixel values back into an image.
  • ConvertCSVToMatrix.py: Converts a CSV file to a NumPy array.
  • ConvertImageToCSV.py: Converts an image to a CSV file.
  • ConvertMatrixToCSV.py: Converts a NumPy array to a CSV file.
  • PlotArray.py: Visualizes a grayscale image.
  • QuantizationBinning16.py: Quantizes the pixel values of an image, grouping values every 16 units.
  • QuantizationBinning32.py: Quantizes the pixel values of an image, grouping values every 32 units.
  • RunLengthDecoding.py: Decodes an RLE-encoded grayscale image.
  • RunLengthEncoding.py: Encodes a grayscale image using Run-Length Encoding.

Usage

Encoding and Decoding

To encode an image using RLE, run RunLengthEncoding.py. This script takes a grayscale image as input and outputs the RLE-encoded version of the image.

python RunLengthEncoding.py

To decode an RLE-encoded image, run RunLengthDecoding.py. This script takes the RLE-encoded CSV file as input and outputs the decoded image.

python RunLengthDecoding.py

Quantization

To quantize an image, run either QuantizationBinning16.py or QuantizationBinning32.py. These scripts group pixel values into bins of specified size.

python QuantizationBinning16.py

or

python QuantizationBinning32.py

Visualization

To visualize a grayscale image, run PlotArray.py. This script displays the image using matplotlib.

python PlotArray.py

Converting to and from CSV

  • ConvertImageToCSV.py and ConvertMatrixToCSV.py are used to convert images or NumPy arrays to CSV format.
  • ConvertCSVToImage.py and ConvertCSVToMatrix.py are used to convert CSV files back to images or NumPy arrays.

Requirements

  • Python 3.x
  • OpenCV
  • NumPy
  • Matplotlib

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A collection of scripts and tools for image processing and compression using Python. Whether you're interested in exploring image quantization, Run-Length Encoding (RLE), or visualizing grayscale images, this repository has something for you. Feel free to explore the various scripts and contribute to the project.

License:MIT License


Languages

Language:C 84.5%Language:Python 14.2%Language:Shell 1.3%