Skip to main content

dssim

Function dssim 

Source
pub fn dssim<F: PixelFormat>(
    reference: &Image<F>,
    distorted: &Image<F>,
    opts: DssimOptions,
) -> Result<f64>
Expand description

Computes the structural dissimilarity (DSSIM) between reference and distorted as (1 - SSIM) / 2.

Both images share the pixel format F, so a difference in color space, channel layout, or bit depth is rejected by the compiler rather than at run time. An alpha channel, if present, is ignored. The score ranges over [0, 1); lower is better, and pixel-identical images score exactly 0.0. Each image must be at least 11x11 (the size of SSIM’s Gaussian window).

This is the classic (1 - SSIM) / 2 dissimilarity, not the multi-scale L*a*b* metric of kornelski/dssim (see this module’s documentation).

§Errors

§Examples

use iqa::{Image, DssimOptions, dssim};

let reference = Image::srgb8(11, 11, vec![128; 11 * 11 * 3])?;
let distorted = Image::srgb8(11, 11, vec![130; 11 * 11 * 3])?;
let score = dssim(&reference, &distorted, DssimOptions::default())?;
assert!(score >= 0.0);

Identical images score exactly zero:

use iqa::{Image, DssimOptions, dssim};

let img = Image::srgb8(11, 11, vec![64; 11 * 11 * 3])?;
assert_eq!(dssim(&img, &img, DssimOptions::default())?, 0.0);

Comparing two different pixel formats does not type-check:

use iqa::{Image, DssimOptions, dssim};

let rgb = Image::srgb8(11, 11, vec![0; 11 * 11 * 3])?;
let gray = Image::gray8(11, 11, vec![0; 11 * 11])?;
let _ = dssim(&rgb, &gray, DssimOptions::default()); // channel mismatch
use iqa::{Image, DssimOptions, dssim};

let eight = Image::srgb8(11, 11, vec![0; 11 * 11 * 3])?;
let sixteen = Image::srgb16(11, 11, vec![0; 11 * 11 * 3])?;
let _ = dssim(&eight, &sixteen, DssimOptions::default()); // bit-depth mismatch