cosmic::cosmic_theme::palette

Module color_difference

source
Expand description

Algorithms for calculating the difference between colors.

§Selecting an algorithm

Different distance/difference algorithms and formulas are good for different situations. Some are faster but less accurate and some may only be suitable for certain color spaces. This table may help navigating the options a bit by summarizing the difference between the traits in this module.

Disclaimer: This is not an actual benchmark! It’s always best to test and evaluate the differences in an actual application, when possible.

Property explanations:

  • Complexity: Low complexity options are generally faster than high complexity options.
  • Accuracy: How the numerical difference compares to the perceived difference. May differ with the color space.
TraitComplexityAccuracyNotes
Ciede2000HighHigh for small differences, lower for large differencesThe de-facto standard, but requires complex calculations to compensate for increased errors in certain areas of the CIE L*a*b* (CIELAB) space.
ImprovedCiede2000HighHigh for small differences, lower for large differencesA general improvement of Ciede2000, using a formula by Huang et al.
DeltaEUsually lowMedium to highThe formula differs between color spaces and may not always be the best. Other formulas, such as Ciede2000, may be preferred for some spaces.
ImprovedDeltaEUsually low to mediumMedium to highA general improvement of DeltaE, using a formula by Huang et al.
EuclideanDistanceLowMedium to high for perceptually uniform spaces, otherwise lowCan be good enough for perceptually uniform spaces or as a “quick and dirty” check.
HyAbLowHigh accuracy for medium to large differences. Less accurate than CIEDE2000 for small differences, but still performs well and is much less computationally expensive.Similar to Euclidean distance, but separates lightness and chroma more. Limited to Cartesian spaces with a lightness axis and a chroma plane.
Wcag21RelativeContrastLowLow and only compares lightnessMeant for checking contrasts in computer graphics (such as between text and background colors), assuming sRGB. Mostly useful as a hint or for checking WCAG 2.1 compliance, considering the criticism it has received.

Traits§

  • Calculate the CIEDE2000 ΔE* (Delta E) color difference between two colors.
  • ColorDifferenceDeprecated
    A trait for calculating the color difference between two colors.
  • Calculate the ΔE color difference between two colors.
  • Calculate the distance between two colors as if they were coordinates in Euclidean space.
  • Calculate a combination of Euclidean and Manhattan/City-block distance between two colors.
  • Calculate the CIEDE2000 ΔE’ (improved IEDE2000 ΔE*) color difference.
  • Calculate the ΔE’ (improved ΔE) color difference between two colors.
  • Calculate and check the WCAG 2.1 relative contrast and relative luminance.