Skip to main content

Fast, multi-threaded SSIM and PSNR algorithms for Python.

Project description

Fast-SSIM

Fast, multi-threaded SSIM and PSNR calculations!


ℹ About

This fork wraps the Fast-SSIM project in an easy-to-use package that can be readily installed via PyPI.
To further accelerate processing, this version enables multithreading and leverages AVX2/FMA hardware instructions. For older CPUs it falls back to a SSE implementation.
This version achieves up to a 360x speedup for SSIM and 150x for PSNR on modern multi-core processors (tested on an AMD Ryzen 5 5600X 6-Core Processor) compared to standard implementations.

Requirements

  • Python 3.9 or higher

How to Install

pip install Fast-SSIM

Usage

The functionalities are explained in the following code snippet that is also provided in this repo:

from skimage.io import imread

import fast_ssim

img1_path = r"test_images/0.jpg"
img2_path = r"test_images/1.jpg"

# Load the images into NumPy arrays
img1 = imread(img1_path)
img2 = imread(img2_path)

ssim_score = fast_ssim.ssim(
    img1, img2,
    data_range=255
)
psnr_score = fast_ssim.psnr(
    img1, img2,
    data_range=255
)

print(f"SSIM Score: {ssim_score}")
print(f"PSNR Score: {psnr_score}")

Output:

SSIM Score: 0.9886590838432312
PSNR Score: 31.11587142944336

Diagnostics & Testing

You can query the C++ backend about what hardware acceleration is being used:

import fast_ssim

status = fast_ssim.get_cpu_status()
if status == 0:
    print("Using AVX2 + FMA")
else:
    print(f"Running in compatibility mode (SSE Fallback). Status Code: {status}")

If you have a modern AVX2-capable CPU but want to test the slower SSE fallback path (for benchmarking or debugging), you can force the library to bypass AVX2 entirely.
Just set the SSIM_FORCE_SSE environment variable before importing the library:

import os
os.environ["SSIM_FORCE_SSE"] = "1"

import fast_ssim
print(fast_ssim.get_cpu_status()) # Will now output: 2 (Missing AVX2 / Forced SSE)

Performance Comparison

Due to multithreading, your exact speedup will scale dynamically with your CPU's core count. The benchmarks below were recorded on an AMD Ryzen 5 5600X 6-Core Processor:

Hardware Tested: AMD Ryzen 5 5600X 6-Core Processor

Resolution Metric scikit-image (Avg) Fast-SSIM (Avg) Speedup
1080p SSIM 0.5804s 0.0023s 251.0x
1080p PSNR 0.0426s 0.0002s 180.4x
4K SSIM 2.6128s 0.0071s 367.5x
4K PSNR 0.1782s 0.0012s 154.4x

Notes

  • The SSIM calculation uses sample covariance (and sample variance) for its statistics. This aligns with the default behavior of scikit-image's structural_similarity function, where use_sample_covariance is True by default.

  • This implementation does not offer an option for applying a Gaussian filter to the images or local windows prior to the SSIM/PSNR calculation.

Original author

Chen Yu / @Chen Yu

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

fast_ssim-1.3.1.tar.gz (178.0 kB view details)

Uploaded Source

Built Distribution

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

fast_ssim-1.3.1-py3-none-any.whl (177.7 kB view details)

Uploaded Python 3

File details

Details for the file fast_ssim-1.3.1.tar.gz.

File metadata

  • Download URL: fast_ssim-1.3.1.tar.gz
  • Upload date:
  • Size: 178.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for fast_ssim-1.3.1.tar.gz
Algorithm Hash digest
SHA256 f7fbf078e3daf48b83f58ee025517255b14c903cb4c7fb4895ffba2512389dc1
MD5 2a6d8f327b2f46a883318c96207d608c
BLAKE2b-256 c38398b335ae8afcd51f28034928f73c4a4cfc7f5cee2f6809f653433e3342e2

See more details on using hashes here.

File details

Details for the file fast_ssim-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: fast_ssim-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 177.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for fast_ssim-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d09f67512fa86e08d8fc701db1bf4ba920858c013c10d3aa3eb5919bcb04f39
MD5 fbb27df9c4890acaac39a932466b5bf4
BLAKE2b-256 2120c211e1c4cc44d3d7e843f50792aeaa5885eccbabb744e2a5ec06b27a8ced

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