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 + R_T \left({\Delta C'} \over {K_C S_C}\right) \left({\Delta H'} \over {K_H S_H}\right) }$$where
$$\bar L' = (L_1 + L_2)/2$$ $$C_1 = \sqrt{a_1^2 + b_1^2}$$ $$C_2 = \sqrt{a_2^2 + b_2^2}$$ $$\bar C = (C_1 + C_2)/2$$ $$G = {1 \over 2}\left({1 - \sqrt{{{\bar C}^7} \over {{\bar C}^7 + 25^7}}}\right)$$ $$a_1' = a_1(1+G)$$ $$a_2' = a_2(1+G)$$ $$C_1' = \sqrt{{a_1'}^2 + b_1^2}$$ $$C_2' = \sqrt{{a_2'}^2 + b_2^2}$$ $$\bar C' = (C_1' + C_2')/2$$ $$h_1' = \cases{ \arctan(b_1 / a_1') & \text{if }\arctan(b_1 / a_1') \geq 0 \\ \arctan(b_1 / a_1')+360° & \text{otherwise} }$$ $$h_2' = \cases{ \arctan(b_2 / a_2') & \text{if }\arctan(b_2 / a_2') \geq 0 \\ \arctan(b_2 / a_2')+360° & \text{otherwise} }$$ $$\bar H' = \cases{ (h_1' + h_2' + 360°)/2 & \text{if }|h_1' - h_2'| \gt 180° \\ (h_1' +h_2')/2 & \text{otherwise} }$$ $$T = 1 - 0.17 \cos (\bar H' - 30°) + 0.24 \cos(2 \bar H') + 0.32\cos(3 \bar H' + 6°) - 0.20 \cos(4 \bar H' - 63°)$$ $$\Delta h' = \cases{ h_2' - h_1' & \text{if }|h_2' - h_1'| \leq 180° \\ h_2' - h_1' + 360° & \text{else if }|h_2' - h_1'| \gt 180° \text{and }h_2' \leq h_1' \\ h_2' - h_1' - 360° & otherwise }$$ $$\Delta L' = L_2 - L_1$$ $$\Delta C' = C_2' - C_1'$$ $$\Delta H' = 2 \sqrt{C_1' C_2'} \sin(\Delta h' / 2)$$ $$S_L = 1 + {{0.015 (\bar L' - 50)^2} \over {\sqrt{20 + (\bar L' - 50)^2}}}$$ $$S_C = 1 + 0.045 \bar C'$$ $$S_H = 1 + 0.015 \bar C' T$$ $$\Delta \theta = 30 \exp \left \lbrace -\left({{\bar H' - 275°} \over 25} \right)^2\right \rbrace$$ $$R_C = 2 \sqrt{{\bar C'^7} \over {\bar C'^7 + 25^7}}$$ $$R_T = -R_C \sin(2 \Delta \theta)$$ $$K_L = 1 \text{ default}$$ $$K_C = 1 \text{ default}$$ $$K_H = 1 \text{ default}$$Implementation Notes: