Skip to content

Commit

Permalink
Added README.md ☕️
Browse files Browse the repository at this point in the history
  • Loading branch information
Karanraj06 committed Jun 4, 2023
1 parent 628ac65 commit d468be4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 152 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ venv/
ENV/
env.bak/
venv.bak/
**/myenv/
myenv/

# Spyder project settings
.spyderproject
Expand All @@ -133,4 +133,4 @@ dmypy.json
**/.DS_Store

# Visual Studio Code settings and workspace files
**/.vscode/
.vscode/
128 changes: 0 additions & 128 deletions CODE_OF_CONDUCT.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
# Image-Compression
# Image-Compression

This project implements two different algorithms for image compression: JPEG and LZW. JPEG is a lossy compression in which some of the data from the original image is lost, while LZW is lossless, meaning that the compressed image can be reconstructed exactly to the original without any loss of information.

## JPEG Compression

JPEG (Joint Photographic Experts Group) is a popular image compression standard that achieves high compression ratios by applying a series of mathematical transformations on the image data. The JPEG encoder in this project takes a color/grayscale image as input and applies the following steps:

1. Divide the image into blocks.

2. Apply a discrete cosine transform (DCT) on each block to convert it into a frequency domain representation.

3. Quantize the DCT coefficients by dividing by the quantization matrix.

4. Perform zigzag scanning for each block.

5. Truncate each encode block to the specified number of coefficient parameters and return the encoded image

The JPEG decoder reverses the above steps to reconstruct the original image from the compressed data.

![Brown Pastel Flowchart Diagram Graph Template](https://user-images.githubusercontent.com/102947018/233417587-5d362e93-45d5-438d-add2-e1ed3a407128.png)

## LZW Compression

LZW is a compression algorithm that exploit the spatial and statistical redundancies in the data by replacing frequently occurring patterns with shorter codes. The LZW encoder in this project takes a grayscale image, block size and the maximum allowed dictionary size as input and applies the following steps:

1. Divide the image into blocks of the specified size (or treat the whole image as a single block if the block size is set to -1).

2. Flatten each block into a 1D array of pixel values.

3. Apply the LZW compression algorithm on each block to obtain the corresponding encoded output.

4. Store the encoded outputs

The LZW decoder in this project reverses the above steps to reconstruct the original image from the encoded data. It applies the LZW decoding algorithm to obtain the decoded output for each block and concatenates them to obtain the reconstructed image. The RMSE between the original and the reconstructed image is zero for lossless compression.

![Brown Pastel Flowchart Diagram Graph Template (1)](https://user-images.githubusercontent.com/102947018/233417223-a08ad368-f0a6-4a90-8426-1b1cd28adf23.png)

## Usage

- Requires Python 3.10+

- Install the required modules

```
pip3 install -r requirements.txt
```
- Run the programs
JPEG Compression
```
python3 jpeg_compression.py
```
LZW Compression
```
python3 lzw_compression.py
```
## Results
The algorithms were tested for a data set of color and grayscale images.
Sample output:
**JPEG Compression**
![Figure_1](https://user-images.githubusercontent.com/102947018/233422987-fea9d017-6ce3-433e-840b-70ae185848fc.png)
**LZW Compression**
![a](https://user-images.githubusercontent.com/102947018/233423176-8f5f8a78-e579-4f56-89e6-ffba0cb985fb.png)

0 comments on commit d468be4

Please sign in to comment.