@blazediff/gmsd

中文文档
2.0.0发布于 2026/11/05MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.6万

Fast single-threaded GMSD (Gradient Magnitude Similarity Deviation) metric for CI visual testing

原始使用文档
文档目录6 节
  1. Installation
  2. API
  3. gmsd(a, b, options?)
  4. Usage
  5. Migrating from 1.x
  6. References

@blazediff/gmsd

npm bundle size NPM Downloads

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/gmsd

API

gmsd(a, b, options?)

Compares two RGBA images of the same size and returns a GMSD score.

interface Image {
  data: Uint8Array | Uint8ClampedArray; // RGBA, width * height * 4 bytes. Buffer works too.
  width: number;
  height: number;
}

type GmsdResult =
  | { kind: "compared"; score: number } // 0 when identical, higher is more different (typically 0-0.35)
  | { kind: "dimension-mismatch"; a: Size; b: Size };

Images of different sizes return kind: "dimension-mismatch". A buffer that does not hold width * height * 4 bytes, or an output of the wrong size, throws.

Option Type Default Description Hint
downsample 0 | 1 0 Downsampling factor 0 = full resolution, 1 = 2x downsample (faster, slight accuracy loss)
c number 170 Stability constant Prevents division by zero. 170 is from original MATLAB implementation for 8-bit images
output Image none Draws the gradient similarity map White is identical gradient structure, black is different, gray is partial similarity

Usage

import { gmsd } from '@blazediff/gmsd';

const result = gmsd(image1, image2, { downsample: 0, c: 170 });

// Lower score = better quality (0 = perfect match)
if (result.kind === 'compared') console.log(`GMSD score: ${result.score.toFixed(4)}`);

// With the GMS map drawn into an RGBA buffer
const output = { data: new Uint8ClampedArray(width * height * 4), width, height };
gmsd(image1, image2, { output });

Migrating from 1.x

1.xNow
gmsd(a.data, b.data, out, width, height, options)gmsd(a, b, { ...options, output: { data: out, width, height } })
returns numberreturns { kind: "compared", score }
grayscale input (1 byte per pixel)RGBA input only

References

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.

版本与发布记录

@blazediff/gmsd 共发布 5 个版本,首次发布于 2025/10/17;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/11/053 天前
1.7.12026/01/129 个月前
1.7.02025/11/2211 个月前
1.6.02025/10/211 年前
1.5.02025/10/171.1 年前

关于 @blazediff/gmsd 的常见问题

@blazediff/gmsd 是什么?

Fast single-threaded GMSD (Gradient Magnitude Similarity Deviation) metric for CI visual testing

如何安装 @blazediff/gmsd?

在项目目录运行 npm install @blazediff/gmsd,或使用 pnpm add / yarn add / bun add。

@blazediff/gmsd 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@blazediff/gmsd 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@blazediff/gmsd 可以商用吗?

@blazediff/gmsd 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@blazediff/gmsd 的下载量有多少?

根据 npm 官方下载统计,@blazediff/gmsd 在 2026/10/09 – 2026/11/07 这 30 天内被下载 15,766 次,日均约 526 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@blazediff/gmsd 还在维护吗?

最新版本 2.0.0 发布于 2026/11/05(3 天前);至今共发布 5 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/10/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。