Skip to main content

Crate butteraugli

Crate butteraugli 

Source
Expand description

§Butteraugli

Butteraugli is a perceptual image quality metric developed by Google. This is a Rust port of the butteraugli algorithm from libjxl.

The metric is based on:

  • Opsin: dynamics of photosensitive chemicals in the retina
  • XYB: hybrid opponent/trichromatic color space
  • Visual masking: how features hide other features
  • Multi-scale analysis: UHF, HF, MF, LF frequency components

§Quality Thresholds

  • Score < 1.0: Images are perceived as identical
  • Score 1.0-2.0: Subtle differences may be noticeable
  • Score > 2.0: Visible difference between images

§Example

use butteraugli::{butteraugli, ButteraugliParams};
use imgref::Img;
use rgb::RGB8;

// Create two 8x8 RGB images (must be 8x8 minimum)
let width = 8;
let height = 8;
let pixels: Vec<RGB8> = (0..width * height)
    .map(|i| RGB8::new((i % 256) as u8, ((i * 2) % 256) as u8, ((i * 3) % 256) as u8))
    .collect();

let img1 = Img::new(pixels.clone(), width, height);
let img2 = Img::new(pixels, width, height); // Identical images

let params = ButteraugliParams::default();
let result = butteraugli(img1.as_ref(), img2.as_ref(), &params).unwrap();

// Identical images should have score ~0
assert!(result.score < 0.01);

§Features

  • cli: Command-line tool (adds clap, image, serde_json)
  • internals: Expose internal modules for testing/benchmarking (unstable API)

§References

Re-exports§

pub use precompute::ButteraugliReference;

Modules§

precompute
Precomputed reference data for fast repeated butteraugli comparisons.

Structs§

ButteraugliParams
Butteraugli comparison parameters.
ButteraugliResult
Butteraugli image comparison result.
ButteraugliStripConfig
Configuration for strip-wise butteraugli computation.
Img
Basic struct used for both owned (alias ImgVec) and borrowed (alias ImgRef) image fragments.
RGB
A Red + Green + Blue pixel.

Enums§

ButteraugliError
Error type for butteraugli operations.

Constants§

BUTTERAUGLI_BAD
Quality threshold for “bad” (visible difference).
BUTTERAUGLI_GOOD
Quality threshold for “good” (images look the same).
HALO_ROWS_DEFAULT
Default number of halo rows above and below each strip.
MIN_STRIP_HEIGHT
Minimum supported strip height (in rows).

Functions§

butteraugli
Computes butteraugli score between two sRGB images.
butteraugli_linear
Computes butteraugli score between two linear RGB images.
butteraugli_linear_strip
Strip-wise butteraugli with linear-RGB f32 inputs.
butteraugli_linear_strip_with_config
Strip-wise butteraugli with linear-RGB f32 inputs and explicit configuration.
butteraugli_strip
Strip-wise butteraugli with sRGB u8 inputs.
butteraugli_strip_with_config
Strip-wise butteraugli with sRGB u8 inputs and explicit configuration.
srgb_to_linear
Converts sRGB u8 value to linear RGB f32.

Type Aliases§

ImgRef
Reference to pixels inside another image. Pass this structure by value (i.e. ImgRef, not &ImgRef).
ImgVec
Image owning its pixels.
RGB8
8-bit RGB