← FFmpeg Subtitle Tools

Colour Distance Metrics for Sparse Palette Mapping

Which distance metric picks the best nearest-neighbour in a 16-colour DVD palette? 12 metrics tested across 20 diagnostic colours and 262,144 exhaustive inputs.

The palette

DVD default 16-colour global palette. Each subtitle must select 4 colours from this fixed set.

Comparison

For each test colour, 12 distance metrics pick the nearest palette entry. "Claude's opinion" is what Claude Opus 4.6 judged as the perceptually best match.

Scorecard

How often does each metric agree with Claude's opinion?

Exhaustive statistics (262,144 colors)

Methodology

MetricFormula (OkLab unless noted)Notes
sRGBΔR² + ΔG² + ΔB²What dvdsubenc.c uses
OkLabΔL² + Δa² + Δb²Current FFmpeg quantizer
HyAB w=N|ΔL| + N·√(Δa²+Δb²)Abasi et al. 2020
OkLab C×NΔL² + N·(Δa²+Δb²)Chroma-weighted Euclidean
OkLab L×NN·ΔL² + Δa² + Δb²Lightness-reduced (= C×1/N)
CIEDE2000CIE standard with SL/SC/SH/RTIn CIELAB, not OkLab

No perceptual metric beats sRGB for this sparse palette. All OkLab variants map chromatic colours to achromatic entries (light-grey) too readily. sRGB's equal-weight RGB channels act as implicit hue preservation. Even CIEDE2000 (the CIE gold standard) maps skin tone to grey.

Links