@blazediff/gmsd
v1.7.0
Published
Fast single-threaded GMSD (Gradient Magnitude Similarity Deviation) metric for CI visual testing
Maintainers
Readme
@blazediff/gmsd
High-performance GMSD (Gradient Magnitude Similarity Deviation) perceptual image quality metric. Structure-aware similarity scoring using Prewitt gradients on luma channel.
Installation
npm install @blazediff/gmsdAPI
gmsd(image1, image2, output, width, height, options)
Compare two images using GMSD perceptual similarity metric and return a similarity score.
Returns: GMSD score where 0 = identical, higher values = more differences (typically 0-0.35 range)
Usage
import { gmsd } from '@blazediff/gmsd';
// Basic comparison
const score = gmsd(
image1.data,
image2.data,
undefined,
width,
height,
{
downsample: 0,
c: 170,
}
);
// Lower score = better quality (0 = perfect match)
console.log(`GMSD score: ${score.toFixed(4)}`);
// With GMS map output for visualization
const output = new Uint8ClampedArray(width * height * 4);
const score = gmsd(
image1.data,
image2.data,
output, // Will be filled with grayscale similarity map
width,
height,
{}
);
// output now contains:
// - White pixels (255): identical gradient structure
// - Black pixels (0): different gradient structure
// - Gray shades: partial similarityReferences
Based on the paper:
Xue, W., Zhang, L., Mou, X., & Bovik, A. C. (2013). "Gradient Magnitude Similarity Deviation: A Highly Efficient Perceptual Image Quality Index." IEEE Transactions on Image Processing, 22(2), 684-695.
