@ blazediff/ gmsd (英语)
高性能的GMSD(Gradient Magnitude 相似度偏移)能感图像质量度量. 结构感知相似分分 使用普鲁维特梯度 在卢马通道.
安装
npm install @blazediff/gmsd
API 密码
gmsd( a, b, 选项)
比较两个大小相同的RGBA图像并返回一个GMSD分数.
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 };
大小不同的图像返回 kind: "dimension-mismatch"。不持有的缓冲器 width * height * 4 字节,或 output 大小不对,丢出.
| 选项 | 类型 | 默认 | 说明 | 提示 |
|---|---|---|---|---|
downsample |
0| 1 | 0 个 | 采样系数 | 0 = 全分辨度, 1 = 2x 下采样(较快,略微精度损失) |
c |
编号 | 170国 | 稳定不变 | 防止零除法. 170 从最初 MATLAB 执行 8- 位图像 |
output |
图像 | 无 | 绘制梯度相似度图 | 白色是相同的梯度结构,黑色是不同的,灰色是部分相似的 |
使用量
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 });
从 1.x 移动
| 1.x 运算 | 现在 |
|---|---|
gmsd(a.data, b.data, out, width, height, options) | gmsd(a, b, { ...options, output: { data: out, width, height } }) |
返回时 number | 返回时 { kind: "compared", score } |
| 灰度输入 (每像素 1 字节) | 只有 RGBA 输入 |
参考资料
根据该文件:
薛, W., 张, L., Mou, X., & Bovik, A. C. (2013). "Gradient Magnitude相似度偏差:一个高效的感知图像质量指数". IEEE交易 关于图像处理,22(2),684-695.