/// <summary> /// A color difference algorithm to get the difference in visible color, and not just the integer difference in RGB values. /// NOTE: The JND (Just Noticible Difference) between two colors is about 2.3. /// </summary> public static double GetEDeltaColorDifference(this Color c, Color color) { LAB a = c.GetLAB(); LAB b = color.GetLAB(); return(Math.Sqrt(Math.Pow(a.L - b.L, 2) + Math.Pow(a.a - b.a, 2) + Math.Pow(a.b - b.b, 2))); }
public static LAB GetLAB(this XYZ c) { // Adapted from http://www.easyrgb.com/index.php?X=MATH&H=07#text7 double var_X = c.X / 95.047; double var_Y = c.Y / 100.000; double var_Z = c.Z / 108.883; if (var_X > 0.008856) { var_X = Math.Pow(var_X, (1.0 / 3)); } else { var_X = (7.787 * var_X) + (16.0 / 116); } if (var_Y > 0.008856) { var_Y = Math.Pow(var_Y, (1.0 / 3)); } else { var_Y = (7.787 * var_Y) + (16.0 / 116); } if (var_Z > 0.008856) { var_Z = Math.Pow(var_Z, (1.0 / 3)); } else { var_Z = (7.787 * var_Z) + (16.0 / 116); } LAB lab = new LAB(); lab.L = (116 * var_Y) - 16; lab.a = 500 * (var_X - var_Y); lab.b = 200 * (var_Y - var_Z); return(lab); }
public static LAB GetLAB(this XYZ c) { // Adapted from http://www.easyrgb.com/index.php?X=MATH&H=07#text7 double var_X = c.X / 95.047; double var_Y = c.Y / 100.000; double var_Z = c.Z / 108.883; if (var_X > 0.008856) var_X = Math.Pow(var_X, (1.0 / 3)); else var_X = (7.787 * var_X) + (16.0 / 116); if (var_Y > 0.008856) var_Y = Math.Pow(var_Y, (1.0 / 3)); else var_Y = (7.787 * var_Y) + (16.0 / 116); if (var_Z > 0.008856) var_Z = Math.Pow(var_Z, (1.0 / 3)); else var_Z = (7.787 * var_Z) + (16.0 / 116); LAB lab = new LAB(); lab.L = (116 * var_Y) - 16; lab.a = 500 * (var_X - var_Y); lab.b = 200 * (var_Y - var_Z); return lab; }