Skip to main content

Image compression using REIS-SVD with evaluation metrics like MSE, PSNR, and SSIM.

Project description

reissvd_imgcompress

A Python package for image compression using the REIS-SVD algorithm. This package helps in reducing the size of images while preserving quality, and also provides various metrics for evaluating compression quality, including MSE, PSNR, and SSIM.

Update

  • Remove the limitation on k: The code allows k to exceed the total number of singular values and sets k to the maximum available value if necessary to avoid errors.
  • Improve the precision of the Sylvester equation: Increase max_iter to 50 iterations and reduce tol to 1e-6, which allows for a more accurate solution of the equation.

Features

  • Compress grayscale images using REIS-SVD.
  • Compute compression metrics:
    • Compression Ratio (CR)
    • Mean Squared Error (MSE)
    • Peak Signal-to-Noise Ratio (PSNR)
    • Structural Similarity Index (SSIM)
  • Visualize compressed images with different singular values.

Installation

To install the package, first clone the repository or download the code, then navigate to the package directory and run:

pip install .

Usage

from reissvd_imgcompress import (
    rgb2gray, reis_svd, compute_metrics, plot_compressed_images
)
import numpy as np
from PIL import Image

# Load an image and convert it to grayscale
image = np.array(Image.open('sample_image.png'))
gray_image = rgb2gray(image) # If grayscale conversion is not needed, you can skip this step.


# Define singular value counts for testing
k_values = [1, 2, 5, 10, 20, 50, 100, 200, 500]

# Iterate over k_values, compress images, and compute metrics
for k in k_values:
    compressed = reis_svd(gray_image, k)
    CR, mse, psnr, ssim_index = compute_metrics(gray_image, compressed, k)
    print(f"k={k}: CR={CR:.2f}, MSE={mse:.2f}, PSNR={psnr:.2f} dB, SSIM={ssim_index:.4f}")

# Plot compressed images for visual comparison
plot_compressed_images(gray_image, k_values)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reissvd_imgcompress-0.2.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reissvd_imgcompress-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file reissvd_imgcompress-0.2.0.tar.gz.

File metadata

  • Download URL: reissvd_imgcompress-0.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for reissvd_imgcompress-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1b9ffdf47b099a3866a960c16a4697e5a6738232aa778142b35604ce954022ce
MD5 4d08d70b7820e49bf38653ec5eee47ee
BLAKE2b-256 ebd12de8b5443d1cd54c5e7699831f2de52f845af5f06814ba6aeaf8c66fbf31

See more details on using hashes here.

File details

Details for the file reissvd_imgcompress-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for reissvd_imgcompress-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1941990c085e7e47071dfae7ebe49ca5c2a9b852f41c79cd31cfd0794c084ae2
MD5 8619ec4fe804c9077f39b5e62df51e9d
BLAKE2b-256 9fb5d6479541ced12ea0182a00a211cfbafaf0d5865e745dcf80b183d8143691

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page