Delta E (CIE 1994)

The color difference, or $\Delta E$, between a sample color ($L_2$, $a_2$, $b_2$) and a reference color ($L_1$, $a_1$, $b_1$) is:

$$\Delta E = \sqrt{ {\left({{\Delta L} \over {K_L S_L}}\right)^2} + {\left({{\Delta C} \over {K_C S_C}}\right)^2} + {\left({{\Delta H} \over {K_H S_H}}\right)^2} }$$

where

$$\Delta L = L_1 - L_2$$ $$\Delta C = C_1 - C_2$$ $$\Delta H = \sqrt{{\Delta a}^2 + {\Delta b}^2 - {\Delta C}^2}$$ $$C_1 = \sqrt{{a_1}^2 + {b_1}^2}$$ $$C_2 = \sqrt{{a_2}^2 + {b_2}^2}$$ $$\Delta a = a_1 - a_2$$ $$\Delta b = b_1 - b_2$$ $$S_L = 1$$ $$S_C = 1 + K_1 C_1$$ $$S_H = 1 + K_2 C_1$$ $$K_L = \cases{ 1 & \text{default} \\ 2 & \text{textiles} }$$ $$K_C = 1 \text{ default}$$ $$K_H = 1 \text{ default}$$ $$K_1 = \cases{ 0.045 & \text{graphic arts} \\ 0.048 & \text{textiles} }$$ $$K_2 = \cases{ 0.015 & \text{graphic arts} \\ 0.014 & \text{textiles} }$$

Implementation Notes:

  1. In the calculation of $\Delta H$, the value inside the radical is, in theory, always greater than or equal to zero. However in an actual implementation, it may become a very slightly negative value, due to limited arithmetic precision. Should this occur, the square root will fail. Be sure to account for this possibility (see following note for a solution).
  2. The value for $\Delta H$ is not actually needed. Rather, ${\Delta H}^2$ is needed instead. So an optimization might be to avoid the square root altogether.