/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="DiffMethod">The specific way to calculate the difference</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE94(ColorLab Color1, ColorLab Color2, CIE94DifferenceMethod DiffMethod) { var1 = (DiffMethod == CIE94DifferenceMethod.Textiles) ? 2 : 1; //SL var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.045 : 0.048; //K1 var5 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.015 : 0.014; //K2 var6 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2); //Delta H return(Math.Sqrt(Math.Pow((Color1.L - Color2.L) / var1, 2) + Math.Pow((var2 - var3) / (1 + var4 * var2), 2) + var6 / Math.Pow((1 + var5 * var2), 2))); }
/// <summary> /// Calculate the difference between two colors /// </summary> /// <param name="DiffMethod">The specific way to calculate the difference</param> /// <returns>The difference between Color1 and Color2</returns> public double DeltaE(CIE94DifferenceMethod DiffMethod) { switch (DiffMethod) { case CIE94DifferenceMethod.GraphicArts: return(DeltaE(1, 0.045, 0.015)); case CIE94DifferenceMethod.Textiles: return(DeltaE(2, 0.048, 0.014)); default: throw new ArgumentException("Not a valid enum value"); } }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="DiffMethod">The specific way to calculate the difference</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE94(ColorLab Color1, ColorLab Color2, CIE94DifferenceMethod DiffMethod) { var1 = (DiffMethod == CIE94DifferenceMethod.Textiles) ? 2 : 1; //SL var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.045 : 0.048; //K1 var5 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.015 : 0.014; //K2 var6 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2);//Delta H return Math.Sqrt(Math.Pow((Color1.L - Color2.L) / var1, 2) + Math.Pow((var2 - var3) / (1 + var4 * var2), 2) + var6 / Math.Pow((1 + var5 * var2), 2)); }