Skip to main content

Crate blazediff_ssim

Crate blazediff_ssim 

Source
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§

HitchhikersOptions
Knobs specific to Hitchhiker’s SSIM; the shared window and stability constants live in SsimOptions.
MsSsimOptions
Knobs specific to MS-SSIM; the shared window and stability constants live in SsimOptions.
PerceptualOptions
Plane
A single-channel luma plane, the form every metric works in.
Rgba8
A borrowed RGBA8 image, 4 bytes per pixel, row-major.
SsimOptions
Knobs shared by every SSIM variant.
SsimOutcome
A metric score and the local map it was pooled from.

Enums§

ColorSpace
Which space the pyramid scales in and the statistics are computed in.
MsSsimMethod
How the per-scale scores are pooled into one number.
Pooling
How a scale’s local map collapses to one number.
SsimError
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 separate level.

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 map over an RGBA8 output buffer as an opaque grayscale image, dark where the local score is low.
ssim
Mean SSIM over image1 and image2, plus the local map it was pooled from.