fast-ssim2
Rust implementation of the SSIMULACRA2 perceptual image quality metric.
Attribution
This crate is a fork of rust-av/ssimulacra2. Thank you to the rust-av team for creating the original Rust implementation - their clean, well-structured code made it straightforward to build upon.
What's different
The upstream crate provides a correct, readable scalar implementation. This fork experiments with SIMD acceleration and adds some API conveniences:
- SIMD-accelerated blur and XYB conversion (via
widecrate and x86 intrinsics) - Precomputed reference API for batch comparisons (
Ssimulacra2Reference) imgreftype support viaToLinearRgbtrait
These changes come with trade-offs: higher MSRV (1.89.0 vs 1.65.0), more complex code, and platform-specific behavior. If you prefer simplicity and stability, the upstream crate may be a better fit.
Contributing back
We'd be happy to upstream any of these changes if the rust-av team is interested. The SIMD work is substantial and may not align with their goals, but we're open to collaboration.
Benchmarks
Full SSIMULACRA2 computation (AMD Ryzen, x86_64):
| Resolution | Scalar | SIMD | Unsafe SIMD |
|---|---|---|---|
| 1920×1080 | 1083ms | 434ms (2.5×) | 370ms (2.9×) |
| 3840×2160 | 4256ms | 1612ms (2.6×) | 1422ms (3.0×) |
Run your own:
Installation
[]
= "0.6"
Features
simd(default): Safe SIMD via thewidecrateunsafe-simd(default): x86_64 intrinsics (faster on supported hardware)imgref: Support forimgrefimage typesrayon: Parallel computation
Usage
With imgref
use compute_ssimulacra2;
use ImgVec;
let source: = /* your image */;
let distorted: = /* distorted version */;
let score = compute_ssimulacra2?;
// 100 = identical, lower = more different
With yuvxyb types
use ;
let source = new?;
let distorted = new?;
let score = compute_frame_ssimulacra2?;
Precomputed reference (for batch comparisons)
use Ssimulacra2Reference;
let reference = new?;
for distorted in variants
Score interpretation
| Score | Meaning |
|---|---|
| 100 | Identical |
| 90+ | Imperceptible difference |
| 70-90 | Minor difference |
| 50-70 | Noticeable |
| < 50 | Significant degradation |
License
BSD-2-Clause (same as upstream)
Notes
Developed with assistance from Claude (Anthropic). Tested against the C++ reference implementation.