Module cosmic::cosmic_theme::palette::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.
Trait | Complexity | Accuracy | Notes |
---|---|---|---|
Ciede2000 | High | High for small differences, lower for large differences | The de-facto standard, but requires complex calculations to compensate for increased errors in certain areas of the CIE L*a*b* (CIELAB) space. |
ImprovedCiede2000 | High | High for small differences, lower for large differences | A general improvement of Ciede2000 , using a formula by Huang et al. |
DeltaE | Usually low | Medium to high | The formula differs between color spaces and may not always be the best. Other formulas, such as Ciede2000 , may be preferred for some spaces. |
ImprovedDeltaE | Usually low to medium | Medium to high | A general improvement of DeltaE , using a formula by Huang et al. |
EuclideanDistance | Low | Medium to high for perceptually uniform spaces, otherwise low | Can be good enough for perceptually uniform spaces or as a “quick and dirty” check. |
HyAb | Low | High 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. |
Wcag21RelativeContrast | Low | Low and only compares lightness | Meant 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.
- Color
Difference Deprecated 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.