Skip to content

Implementation of two most popular image compression techniques JPEG compression and LZW compression.

Notifications You must be signed in to change notification settings

prashant531/Image-Compression

Repository files navigation

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.

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.

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

Brown Pastel Flowchart Diagram Graph Template (1)

Results

The algorithms were tested for a data set of color and grayscale images.

Sample output:

JPEG Compression

Figure_1

LZW Compression

a

About

Implementation of two most popular image compression techniques JPEG compression and LZW compression.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published