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'sstructural_similarityfunction, whereuse_sample_covarianceis 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
Metadata
Release files for Fast-SSIM 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fast_ssim-1.4.0.tar.gz | 178.9 kB | Without provenance | Details for fast_ssim-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fast_ssim-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for fast_ssim-1.4.0-py3-none-any.whl |
Total release size: 357.6 kB
Release files / fast_ssim-1.4.0.tar.gz
| Download URL | fast_ssim-1.4.0.tar.gz |
|---|---|
| Size | 178.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
938b478d0ae5ec97ca854afc0c5a274cf7d75aedc6f54b25f713797982754fea
|
|
BLAKE2b-256 checksum How to use checksums |
01b32eff4e0c646e6c58741af02ea8c892811c539284a5f67d9c2e6fd94d7f7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / fast_ssim-1.4.0-py3-none-any.whl
| Download URL | fast_ssim-1.4.0-py3-none-any.whl |
|---|---|
| Size | 178.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b734812ced5af2c6c0c75029c84e92fa45694f0f8e1110420c522c2d6ad745c1
|
|
BLAKE2b-256 checksum How to use checksums |
41d9f0831e7d391849e4b0d545a52ddf90c6c2a3d3cfc0acedc0cd0f8d41a1b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Security for Fast-SSIM 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.