npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@blazediff/ssim

v1.7.1

Published

Fast single-threaded SSIM (Structural Similarity Index) metric for CI visual testing

Readme

@blazediff/ssim

npm bundle size NPM Downloads

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.

Features:

  • Three SSIM Variants - Standard SSIM, MS-SSIM, and Hitchhiker's SSIM
  • MATLAB-compatible - Matches reference implementation with <0.01% error
  • High Performance - Optimized implementations with ~4x faster Hitchhiker's SSIM
  • Perceptual Metrics - Structural similarity scoring (0-1 scale)
  • SSIM Map Output - Optional grayscale visualization
  • Zero Dependencies
  • TypeScript Support out of the box

For detailed algorithm explanation and mathematical formulas, see FORMULA.md.

Installation

npm install @blazediff/ssim

API

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

Compares two images using the standard SSIM algorithm with automatic downsampling and returns a similarity score.

Returns: number - SSIM score (0-1, where 1 is identical)

Options

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

Compares two images using the Multi-Scale SSIM (MS-SSIM) algorithm and returns a similarity score.

Same parameters as ssim(), but analyzes images at multiple scales (default: 5 levels) for better perceptual accuracy.

Returns: number - MS-SSIM score (0-1, where 1 is identical)

Options

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

Compares two images using Hitchhiker's SSIM (fast rectangular-window version with integral images).

Performance: ~4x faster than standard SSIM using integral images for O(1) window computation.

Returns: number - SSIM score (0-1, where 1 is identical)

Options

Usage

Basic SSIM Comparison

import ssim from '@blazediff/ssim/ssim';

const score = ssim(image1.data, image2.data, undefined, width, height);

console.log(`Similarity: ${score.toFixed(4)}`); // e.g., "Similarity: 0.9823"

// Use in tests
if (score < 0.95) {
  throw new Error(`Images differ too much: ${score}`);
}

Multi-Scale SSIM (MS-SSIM)

import msssim from '@blazediff/ssim/msssim';

// MS-SSIM provides better perceptual accuracy by analyzing at multiple scales
const score = msssim(image1.data, image2.data, undefined, width, height);

console.log(`MS-SSIM: ${score.toFixed(4)}`);

Hitchhiker's SSIM (Fast)

import hitchhikersSSIM from '@blazediff/ssim/hitchhikers-ssim';

// ~4x faster than standard SSIM
const score = hitchhikersSSIM(image1.data, image2.data, undefined, width, height);

console.log(`Hitchhiker's SSIM: ${score.toFixed(4)}`);

// With custom options
const scoreCustom = hitchhikersSSIM(image1.data, image2.data, undefined, width, height, {
  windowSize: 16,
  windowStride: 8,  // Overlapping windows
  covPooling: true, // CoV pooling (recommended)
});

Custom Options

import ssim from '@blazediff/ssim/ssim';

// Basic SSIM with custom window size
const score = ssim(image1, image2, undefined, width, height, {
  windowSize: 7,  // Smaller window for more local detail
  k1: 0.01,
  k2: 0.03,
  L: 255
});

// MS-SSIM with custom scales and method
import msssim from '@blazediff/ssim/msssim';

const msScore = msssim(image1, image2, undefined, width, height, {
  scales: 5,           // Number of scales (default: 5)
  method: 'product',   // 'product' or 'sum'
  windowSize: 11
});

SSIM Map Visualization

The SSIM map shows local similarity values as a grayscale image:

import ssim from '@blazediff/ssim/ssim';

// Create output buffer for SSIM map
const output = new Uint8ClampedArray(width * height * 4);

const score = ssim(image1, image2, output, width, height);

// output now contains grayscale SSIM map
// White (255) = high similarity, Black (0) = low similarity
// Can be saved as PNG or displayed for debugging

When to Use Each Variant

Use SSIM when:

  • You need MATLAB-compatible results for research or comparison
  • You want high accuracy with Gaussian weighting
  • You need automatic downsampling for large images
  • Performance is not critical

Use MS-SSIM when:

  • You need multi-scale analysis for better perceptual correlation
  • You're working with images at different resolutions
  • You want better correlation with human perception
  • You can afford the ~2-3x computation cost

Use Hitchhiker's SSIM when:

  • You need maximum performance (~4x faster than standard SSIM)
  • You're processing large images or many images
  • You want O(1) window computation regardless of window size
  • You need flexible window stride for overlapping/non-overlapping windows
  • CoV pooling provides better perceptual correlation than mean

Score Interpretation

| Score Range | Similarity Level | Description | | ----------- | ---------------- | ----------- | | 1.0 | Identical | Images are identical or perceptually identical | | 0.99+ | Excellent | Extremely high similarity (minor compression artifacts) | | 0.95-0.99 | Very Good | High similarity (small compression or noise) | | 0.90-0.95 | Good | Noticeable but acceptable differences | | 0.80-0.90 | Fair | Significant but tolerable differences | | <0.80 | Poor | Major structural differences |

References

SSIM & MS-SSIM

Hitchhiker's SSIM

License

See ../../licenses for algorithm attribution and licensing information.