Fast Image & Video Fidelity Metrics in C, Zig

Lobsters Hottest Tools

Summary

fmetrics is an open-source library in C and Zig for computing fast perceptual image and video fidelity metrics such as IW-SSIM, MS-SSIM, SSIMULACRA2, Butteraugli, and CVVDP, with validated correlation to human ratings.

<p>Associated blog post: <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">Comments</a></p>
Original Article
View Cached Full Text

Cached at: 07/10/26, 06:07 AM

halidecx/fmetrics

Source: https://github.com/halidecx/fmetrics

fmetrics

Fast image & video fidelity metrics in C & Zig.

Usage

Compilation requires Zig ≥0.16.0 & a macOS, Linux, or Unix-like operating system. To compile, run:

zig build --release=fast

You may add -Dflto=true for FLTO, and -Dstrip=true to strip the binary.

Compilation emits:

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

fmetrics binary usage:

fmetrics by Halide Compression, LLC | [version]

usage: fmetrics <metric> [options] <reference> <distorted>

compare two images/videos using various perceptual quality metrics

metrics:  iwssim, msssim, ssimu2, butter, cvvdp

run `fmetrics <metric> --help` for metric-specific help

options:
  -h, --help
      show this help message

sRGB PNG, PNM/PAM, QOI, or Y4M input expected

Usage is different per-metric; some metrics support outputting visual error maps via --err-map, and some support additional configuration options. I/O is the same for all metrics, and is provided by simpleimgio.

Library Usage

libfmetrics.a exposes a C API declared in fmetrics.h. To use it as a Zig dependency, add it to your build.zig.zon by running:

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

This should show something like this in build.zig.zon:

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

Then you can link it from your 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 projects can also import the native 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);

See src/fmetrics.zig for the full Zig API. C projects may use fmetrics.h.

Reference Comparison

Reference metric implementations tested include:

MOS Correlation

MOS correlation is how closely a metric correlates with subjective human ratings.

Tested using mos.py via mos-correlation, on CID22. For our purposes, these tests don’t determine which metrics we think are better than others, but rather how effective our implementations are relative to their references. Here, we just report the Spearman Rank Correlation Coefficient (SRCC), where higher is better.

metricsrcc (reference)srcc (fmetrics)difference (%)
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%

*Note: Because Butteraugli is a smaller-is-better metric, the signs are flipped for the SRCCs reported above.

**Note: fmetrics uses the fcvvdp library (as a Zig module) with different I/O, so the underlying metric implementation is the same.

Speed & Memory Usage

Testing was done on a stock Core i7-13700k with 3840x2160 source & distorted PAM images (Drive link, lossless JPEG-XL sources; run djxl <*.pam.jxl> <*.pam> to decompress).

Speed (ms)

metricms (reference)ms (fmetrics)difference (%)
butteraugli (p3 i203)4110313031.31% faster
fcvvdp*139013900.00%
iw_ssim30202281224.6% faster
ms_ssim**1110106947.2% faster
ssimulacra2722232211.2% faster

RAM Usage (MB)

metricMB (reference)MB (fmetrics)difference (%)
butteraugli (p3 i203)24401670-31.56%
fcvvdp*160016000.00%
iw_ssim2660551-79.29%
ms_ssim**841376-55.29%
ssimulacra21370741-45.91%

*Note: fmetrics uses the fcvvdp library (as a Zig module) with different I/O, so the underlying metric implementation is the same.

**Note: MS-SSIM comparison isn’t fair, as libvmaf has to compute other metrics in the filterchain alongside MS-SSIM.

Credits

fmetrics is under the Apache 2.0 License. fmetrics is developed by Halide Compression.

Special thanks to Vship, which has inspired parts of fmetrics. Vship is under the MIT NON-AI license.

Similar Articles

Fc, a lossless compressor for floating-point streams

Hacker News Top

fc is an open-source lossless compressor for IEEE-754 64-bit double streams, offering superior compression ratios for structured data compared to zstd and fpzip, though with slower encoding speeds.

Video compressor

Simon Willison's Blog

Simon Willison created a web-based video compression tool using Claude Fable 5.1 and FFMPEG WebAssembly to quickly generate optimized video files with customizable presets for blog publishing.

AFP-GIC: Controllable Generative Image Compression [R]

Reddit r/MachineLearning

AFP-GIC, a controllable generative image compression framework published in IEEE Access (2026), uses an asymmetric Adaptive Fused Prior Transfer pipeline to reduce hallucinations and local distortion at ultra-low bitrates, achieving 18.1% lower decoder latency and 20.5% fewer parameters than DC-VIC, with released code, benchmark data, and an interactive Hugging Face demo.

@samsja19: great benchmark

X AI KOLs Following

Introducing VGI-Bench, a multimodal benchmark that probes 12 distinct visual and audio-visual skills with 550 human-curated questions to expose failures in today's video benchmarks.