Skip to Content
New: @blazediff/core-native now includes interpret — structured diff analysis to understand what changed. Read more →
Documentation@blazediff/ssim

@blazediff/ssim

Fast SSIM (Structural Similarity Index) implementations for perceptual image quality assessment. Includes standard SSIM, MS-SSIM (Multi-Scale SSIM), and Hitchhiker’s SSIM for various use cases and performance requirements.

Installation

npm install @blazediff/ssim

Features

  • Three variants - Standard SSIM, MS-SSIM, and Hitchhiker’s SSIM (~4x faster)
  • MATLAB-compatible - Standard SSIM matches reference implementation with <0.01% error
  • SSIM map output - Optional grayscale visualization of similarity

API Reference

ssim(image1, image2, output, width, height, options?)

Compares two images using standard SSIM metric and returns a similarity score.

Parameters

ParameterTypeDescription
image1Buffer, Uint8Array, or Uint8ClampedArrayImage data of the first image
image2Buffer, Uint8Array, or Uint8ClampedArrayImage data of the second image
outputBuffer, Uint8Array, Uint8ClampedArray, or undefinedOptional output buffer for SSIM map visualization
widthnumberWidth of the images in pixels
heightnumberHeight of the images in pixels
optionsSsimOptionsComparison options (optional)
Options
OptionTypeDefaultDescription
windowSizenumber11Size of the Gaussian window
k1number0.01Algorithm parameter for luminance
k2number0.03Algorithm parameter for contrast
Lnumber255Dynamic range of pixel values
Returns

number - SSIM score between 0 and 1

Score Interpretation

Score RangeSimilarity LevelDescription
1.0IdenticalImages are identical or perceptually identical
0.99+ExcellentExtremely high similarity (minor compression artifacts)
0.95-0.99Very GoodHigh similarity (small compression or noise)
0.90-0.95GoodNoticeable but acceptable differences
0.80-0.90FairSignificant but tolerable differences
<0.80PoorMajor structural differences

Threshold Guidelines: - Use threshold >0.99 for strict visual regression testing - Use threshold >0.95 for standard visual regression testing - Scores below 0.90 indicate substantial visual differences

Usage Examples

import ssim from "@blazediff/ssim/ssim"; // Basic usage const score = ssim(img1.data, img2.data, undefined, width, height); // With SSIM map output const output = new Uint8ClampedArray(width * height * 4); const score = ssim(img1.data, img2.data, output, width, height); // With custom options const score = ssim(img1.data, img2.data, undefined, width, height, { windowSize: 8, k1: 0.01, k2: 0.03, });

CLI Usage

All three variants are available via the @blazediff/cli CLI:

# Standard SSIM blazediff-cli ssim image1.png image2.png # MS-SSIM blazediff-cli msssim image1.png image2.png # Hitchhiker's SSIM blazediff-cli hitchhikers-ssim image1.png image2.png # With options blazediff-cli hitchhikers-ssim image1.png image2.png --window-size 16 --no-cov-pooling
Last updated on