Expand description
Structural-similarity metrics: SSIM, MS-SSIM and Hitchhiker’s SSIM.
Where a pixel diff answers “which pixels changed”, these answer “how alike
do these look”: a single score in 0..=1 that tolerates imperceptible noise
and punishes structural damage. They are ports of @blazediff/ssim, which
is validated against the reference MATLAB scripts in packages/ssim/matlab;
tests/matlab_parity.rs holds the Rust side of that proof to the same
tolerances.
The hot loops are vectorised through simd, which picks a lane backend at
compile time. Tap-by-tap accumulation order is kept identical to the JS
reference so the ports inherit its measured MATLAB agreement rather than
drifting by an unmeasured amount.
use blazediff_ssim::{ms_ssim, MsSsimOptions, Plane, Rgba8, SsimOptions};
let plane1 = Plane::from_rgba8(Rgba8::new(&rgba1, width, height))?;
let plane2 = Plane::from_rgba8(Rgba8::new(&rgba2, width, height))?;
let outcome = ms_ssim(
&plane1,
&plane2,
&SsimOptions::default(),
&MsSsimOptions::default(),
)?;
println!("{:.6}", outcome.score);Structs§
- Hitchhikers
Options - Knobs specific to Hitchhiker’s SSIM; the shared window and stability
constants live in
SsimOptions. - MsSsim
Options - Knobs specific to MS-SSIM; the shared window and stability constants live
in
SsimOptions. - Perceptual
Options - Plane
- A single-channel luma plane, the form every metric works in.
- Rgba8
- A borrowed RGBA8 image, 4 bytes per pixel, row-major.
- Ssim
Options - Knobs shared by every SSIM variant.
- Ssim
Outcome - A metric score and the local map it was pooled from.
Enums§
- Color
Space - Which space the pyramid scales in and the statistics are computed in.
- MsSsim
Method - How the per-scale scores are pooled into one number.
- Pooling
- How a scale’s local map collapses to one number.
- Ssim
Error - Why a metric could not produce a score.
Constants§
- DEFAULT_
WEIGHTS - Per-scale weights from the MS-SSIM paper. The number of entries is the
number of scales, so
weights.len()replaces MATLAB’s separatelevel.
Functions§
- hitchhikers_
ssim - Pooled Hitchhiker’s SSIM, plus the local map it was pooled from.
- ms_ssim
- Pooled multi-scale SSIM, plus the local map from the coarsest scale.
- perceptual_
ssim - Pooled perceptual SSIM over an RGBA pair.
- render_
map - Paint
mapover an RGBA8outputbuffer as an opaque grayscale image, dark where the local score is low. - ssim
- Mean SSIM over
image1andimage2, plus the local map it was pooled from.