使用C和Zig实现的快速图像与视频保真度指标

Lobsters Hottest 工具

摘要

fmetrics是一个使用C和Zig开发的开源库,用于计算快速的感知图像和视频保真度指标,如IW-SSIM、MS-SSIM、SSIMULACRA2、Butteraugli和CVVDP,并且经过验证与人类评分具有相关性。

<p>相关博客文章:<a href="https://halide.cx/blog/fmetrics/" rel="ugc">https://halide.cx/blog/fmetrics/</a></p> <p><a href="https://lobste.rs/s/gd15cf/fast_image_video_fidelity_metrics_c_zig">评论</a></p>
查看原文
查看缓存全文

缓存时间: 2026/07/10 06:07

halidecx/fmetrics

来源:https://github.com/halidecx/fmetrics

fmetrics

使用 C 和 Zig 实现的快速图像与视频保真度指标。

使用方法

编译需要 Zig (https://ziglang.org/) ≥0.16.0 以及 macOS、Linux 或类 Unix 操作系统。

运行以下命令进行编译:

zig build --release=fast

可添加 -Dflto=true 启用链接时优化(FLTO),添加 -Dstrip=true 去除二进制文件中的调试信息。

编译后生成的文件结构如下:

tree zig-out
├── bin
│   ├── fmetrics
├── include
│   └── fmetrics.h
└── lib
    └── libfmetrics.a

fmetrics 二进制文件的使用方法:

fmetrics by Halide Compression, LLC | [version]
usage: fmetrics [options] compare two images/videos using various perceptual quality metrics
metrics: iwssim, msssim, ssimu2, butter, cvvdp
run `fmetrics --help` for metric-specific help
options:
  -h, --help            show this help message
sRGB PNG, PNM/PAM, QOI, or Y4M input expected

不同指标的使用方式各异;部分指标支持通过 --err-map 输出视觉误差图,部分指标支持额外的配置选项。所有指标的输入输出方式相同,由 simpleimgio (https://github.com/gianni-rosato/simpleimgio) 提供支持。

库的使用

libfmetrics.a 提供了声明在 fmetrics.h 中的 C 语言 API。若要将其作为 Zig 的依赖使用,请在 build.zig.zon 中添加以下内容,并运行:

zig fetch --save git+https://github.com/halidecx/fmetrics.git

之后 build.zig.zon 中会显示类似如下的内容:

.dependencies = .{
    .fmetrics = .{
        .url = "git+https://github.com/halidecx/fmetrics.git#",
        .hash = "fmetrics--",
    },
},

接着你可以在 build.zig 中链接该依赖:

const fmetrics_dep = b.dependency("fmetrics", .{
    .target = target,
    .optimize = optimize,
});
const fmetrics = fmetrics_dep.artifact("fmetrics");
exe.root_module.linkLibrary(fmetrics);
exe.root_module.addIncludePath(fmetrics.getEmittedIncludeTree());

Zig 项目也可以直接导入原生的 Zig API:

const fmetrics_dep = b.dependency("fmetrics", .{
    .target = target,
    .optimize = optimize,
});
const fmetrics = fmetrics_dep.module("fmetrics");
exe.root_module.addImport("fmetrics", fmetrics);
exe.root_module.linkLibrary(fmetrics_dep.artifact("libfmetrics"));
const fmetrics = @import("fmetrics");
const reference = try fmetrics.Image.init(reference_rgb, width, height);
const distorted = try fmetrics.Image.init(distorted_rgb, width, height);
const score = try fmetrics.msssim(reference, distorted);

完整的 Zig API 请参见 src/fmetrics.zig。C 项目可使用 fmetrics.h

参考对比

参考实现测试来源包括:

  • Butteraugli:libjxl (https://github.com/libjxl/libjxl) 中的 butteraugli_main
  • CVVDP:我们的 fcvvdp (https://github.com/halidecx/fcvvdp)
  • IW-SSIM:Python IW-SSIM (https://github.com/Jack-guo-xy/Python-IW-SSIM) 的一个分支 (https://github.com/gianni-rosato/Python-IW-SSIM)
  • MS-SSIM:通过 ffmpeg 调用 libvmaf (https://github.com/netflix/vmaf) 的 MS-SSIM 滤波器
  • SSIMULACRA2:Cloudinary 的 ssimulacra2 (https://github.com/cloudinary/ssimulacra2)

MOS 相关性

MOS 相关性衡量的是指标与主观人眼评分的吻合程度。使用 mos-correlation (https://github.com/gianni-rosato/mos-correlation) 中的 mos.py 在 CID22 数据集上进行测试。对我们而言,这些测试并不旨在评判不同指标的优劣,而是评估我们的实现相对于各自参考的准确性。此处仅报告 Spearman 秩相关系数(SRCC),数值越高越好。

指标参考实现 SRCCfmetrics SRCC差异 (%)
butteraugli (p3 i203)*0.79290.7863-0.83%
fcvvdp**0.82740.8286+0.15%
iw_ssimn/a0.7925+0.00%
ms_ssim0.78450.8048+2.59%
ssimulacra20.89160.8910-0.07%

*注意:由于 Butteraugli 是数值越小越好的指标,上述 SRCC 的符号已经翻转。 **注意:fmetrics 使用 fcvvdp 库(作为 Zig 模块),仅输入输出不同,因此底层指标实现相同。

速度与内存使用

测试环境:标准 Core i7-13700k,使用 3840x2160 的源图像和失真图像(PAM 格式)(Google Drive 链接 (https://drive.google.com/drive/folders/1Kxzmw-jMWtbh8elPuQidY5MM1pTXkF0L?usp=sharing),无损 JPEG-XL 源文件;运行 djxl <*.pam.jxl> <*.pam> 解压缩)。

速度(毫秒)

指标参考实现 (ms)fmetrics (ms)差异 (%)
butteraugli (p3 i203)41103130快 31.31%
fcvvdp*139013900.00%
iw_ssim3020228快 1224.6%
ms_ssim**1110106快 947.2%
ssimulacra2722232快 211.2%

内存使用(MB)

指标参考实现 (MB)fmetrics (MB)差异 (%)
butteraugli (p3 i203)24401670-31.56%
fcvvdp*160016000.00%
iw_ssim2660551-79.29%
ms_ssim**841376-55.29%
ssimulacra21370741-45.91%

*注意:fmetrics 使用 fcvvdp 库(作为 Zig 模块),仅输入输出不同,因此底层指标实现相同。 **注意:MS-SSIM 的比较并不完全公平,因为 libvmaf 在滤波器链中同时计算了其他指标。

致谢

fmetrics 遵循 Apache 2.0 许可证

fmetrics 由 Halide Compression (https://halide.cx) 开发。

特别感谢 Vship (https://codeberg.org/Line-fr/Vship),它的部分设计启发了 fmetrics。Vship 遵循 MIT NON-AI 许可证 (https://codeberg.org/Line-fr/Vship/src/branch/main/LICENSE)。

相似文章

Perceptual Image Codec: 实际学习型图像压缩中的关键因素

Hacker News Top

PICO (Perceptual Image Codec) 是苹果公司推出的一种新型学习型编解码器,针对人类视觉系统进行了优化,相比AV1和VVC等传统编解码器可节省2.3–3倍的比特率,同时在iPhone 17 Pro Max上实现230毫秒编码/150毫秒解码。

LiteFrame 扩展视频大语言模型效率(6分钟阅读)

TLDR AI

LiteFrame 为视频大语言模型引入了一种高效的视频编码器,采用压缩令牌蒸馏技术,在保持准确率的同时,能够处理多达8倍的帧数并降低35%的延迟,为长视频理解开创了新的帕累托前沿。

LiteFrame: 高效视觉编码器解锁视频大语言模型的帧缩放

Hugging Face Daily Papers

LiteFrame提出了一种轻量级视频编码器,采用压缩令牌蒸馏(Compressed Token Distillation)训练,可降低延迟,并使视频大语言模型能够处理8倍以上的帧数以实现长视频理解,在降低计算量的同时提高准确性。