saturon/deltaE
Compute perceptual color differences using CIE76, CIE94, CIEDE2000, and OKLab algorithms.
The saturon/deltaE subpath provides standalone functions for calculating the perceptual distance (Delta E / ) between two colors. Higher values indicate greater visual dissimilarity, where a value around 1.0 roughly corresponds to a Just Noticeable Difference (JND) for human vision under reference viewing conditions.
Functions
deltaEOK()
Calculates color difference in the OKLab color space (Euclidean distance scaled by 100). Fast and highly reliable for general-purpose perceptual differences and modern displays.
import { deltaEOK } from "saturon/deltaE";
const diff = deltaEOK(color1, color2);deltaE76()
Calculates perceptual distance using the classic CIE76 formula (), computed as simple Euclidean distance in the CIE color space.
import { deltaE76 } from "saturon/deltaE";
const diff = deltaE76(color1, color2);deltaE94()
Calculates color difference using the CIE94 standard (), incorporating weighting factors for lightness (), chroma (), and hue () in CIE space.
import { deltaE94 } from "saturon/deltaE";
const diff = deltaE94(color1, color2);deltaE2000()
Calculates perceptual distance using the industry-standard CIEDE2000 algorithm (). It accounts for non-uniformities in CIE space, neutral color corrections, and rotation terms in the blue region.
import { deltaE2000 } from "saturon/deltaE";
const diff = deltaE2000(color1, color2);Common Signature
All Delta E functions share the exact same parameter signature:
function deltaE(color1: ColorData, color2: ColorData): number;Parameters
| Parameter | Type | Description |
|---|---|---|
color1 | ColorData | The baseline color object ({ model, coords }). |
color2 | ColorData | The target color object ({ model, coords }). |
Returns
A non-negative number representing the perceptual distance scalar () between color1 and color2.
Behavior
- Both input colors are automatically converted to the required color model for calculation (
"oklab"fordeltaEOK,"lab"fordeltaE76,deltaE94, anddeltaE2000). - Coordinates are extracted using
toArray()with unclipped bounds (fit: "none") to maintain numerical precision. - Perceptual Metrics:
deltaEOK: Computes Euclidean distance in OKLab space.deltaE76: Computes Euclidean distance in CIE space.deltaE94: Evaluates lightness (), chroma (), and hue () weighting functions ().deltaE2000: Applies non-linear transformed chroma (), hue rotation factors (), and lightness/chroma/hue weighting scales.
Usage Example
import { deltaEOK, deltaE2000, deltaE76 } from "saturon/deltaE";
const colorA = { model: "rgb", coords: [255, 0, 0] };
const colorB = { model: "rgb", coords: [240, 20, 10] };
// OKLab perceptual distance
const distanceOK = deltaEOK(colorA, colorB);
console.log(distanceOK); // ~8.42
// Industry standard CIEDE2000
const distance2000 = deltaE2000(colorA, colorB);
console.log(distance2000); // ~4.12
// Classic CIE76
const distance76 = deltaE76(colorA, colorB);
console.log(distance76); // ~11.85