Color.Distance
(Color v0.4.0)
Copy Markdown
Color difference (ΔE) metrics between two colors.
Each function accepts two colors in any supported color space; inputs
that are not already in L*a*b* are converted via Color.convert/2,
chromatically adapting to D65 as necessary.
The supported metrics are:
delta_e_76/2— CIE76, the original simple Euclidean distance inL*a*b*. Fast but known to be perceptually non-uniform, especially in saturated blue-purple regions.delta_e_94/3— CIE94, a weighted distance that corrects the saturation/hue issues of CIE76. Parametric factors default to the graphic-arts application (kL = 1, K1 = 0.045, K2 = 0.015).delta_e_2000/3— CIEDE2000, the modern standard. Much more complex but handles perceptual non-uniformity well.delta_e_cmc/3— CMC l:c, developed by the Colour Measurement Committee of the Society of Dyers and Colourists. Common in the textile industry.
For most use cases prefer delta_e_2000/3.
Summary
Functions
CIE76 color difference — Euclidean distance in L*a*b*.
CIE94 color difference.
CIEDE2000 color difference.
CMC l:c color difference.
Functions
@spec delta_e_76(Color.input(), Color.input()) :: float()
CIE76 color difference — Euclidean distance in L*a*b*.
Arguments
ais any supported color.bis any supported color.
Returns
- A non-negative float.
Examples
iex> Color.Distance.delta_e_76(%Color.Lab{l: 50.0, a: 0.0, b: 0.0}, %Color.Lab{l: 50.0, a: 0.0, b: 0.0})
0.0
iex> Float.round(Color.Distance.delta_e_76(%Color.Lab{l: 50.0, a: 2.6772, b: -79.7751}, %Color.Lab{l: 50.0, a: 0.0, b: -82.7485}), 4)
4.0011
@spec delta_e_94(Color.input(), Color.input(), keyword()) :: float()
CIE94 color difference.
Arguments
ais any supported color.bis any supported color.optionsis a keyword list.
Options
:applicationis:graphic_arts(default) or:textilesand picks the CIE94kL,K1,K2constants.:kL,:kC,:kHare parametric weighting factors (defaults1.0, 1.0, 1.0).
Returns
- A non-negative float.
Examples
iex> Float.round(Color.Distance.delta_e_94(%Color.Lab{l: 50.0, a: 2.6772, b: -79.7751}, %Color.Lab{l: 50.0, a: 0.0, b: -82.7485}), 4)
1.3950
@spec delta_e_2000(Color.input(), Color.input(), keyword()) :: float()
CIEDE2000 color difference.
Reference: Sharma, Wu & Dalal, "The CIEDE2000 Color-Difference Formula: Implementation Notes, Supplementary Test Data, and Mathematical Observations" (2005).
Arguments
ais any supported color.bis any supported color.optionsis a keyword list.
Options
:kL,:kC,:kHare parametric weighting factors (defaults1.0, 1.0, 1.0).
Returns
- A non-negative float.
Examples
iex> Float.round(Color.Distance.delta_e_2000(%Color.Lab{l: 50.0, a: 2.6772, b: -79.7751}, %Color.Lab{l: 50.0, a: 0.0, b: -82.7485}), 4)
2.0425
iex> Float.round(Color.Distance.delta_e_2000(%Color.Lab{l: 50.0, a: 2.5, b: 0.0}, %Color.Lab{l: 73.0, a: 25.0, b: -18.0}), 4)
27.1492
@spec delta_e_cmc(Color.input(), Color.input(), keyword()) :: float()
CMC l:c color difference.
Arguments
ais any supported color.bis any supported color.optionsis a keyword list.
Options
:lis the lightness weighting factor. Defaults to2.0(acceptability). Use1.0for perceptibility.:cis the chroma weighting factor. Defaults to1.0.
Returns
- A non-negative float.
Examples
iex> Float.round(Color.Distance.delta_e_cmc(%Color.Lab{l: 50.0, a: 2.6772, b: -79.7751}, %Color.Lab{l: 50.0, a: 0.0, b: -82.7485}), 4)
1.7387