/// <summary> /// Converts CIEXYZ to CIELab. /// </summary> public CIELab XYZtoLab(CIEXYZ xyz) { CIELab lab = CIELab.Empty; lab.L = 116.0 * Fxyz(xyz.Y / CIEXYZ.D65.Y) - 16; lab.A = 500.0 * (Fxyz(xyz.X / CIEXYZ.D65.X) - Fxyz(xyz.Y / CIEXYZ.D65.Y)); lab.B = 200.0 * (Fxyz(xyz.Y / CIEXYZ.D65.Y) - Fxyz(xyz.Z / CIEXYZ.D65.Z)); return(lab); }
private void UnlockButton_Click(object sender, RoutedEventArgs e) { // Debug.WriteLine("PRESSED"); // check the colors //From: http://stackoverflow.com/questions/5392061/algorithm-to-check-similarity-of-colors-based-on-rgb-values-or-maybe-hsv //I would recommend using cie94 (deltae-1994), it's said to be a decent representation of the human color perception. i've used it quite a bit in my computer-vision related applications, and i am rather happy with the result. //it's however rather computational expensive to perform such a comparison: //rgb to xyz for both colors //xyz to lab for both colors //diff = deltae94(labcolor1, labcolor2) Color color = this.colorPick1.Color; Color color2 = this.colorPick2.Color; this.Container.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, (byte)((color.R + color2.R) / 2), (byte)((color.G + color2.G) / 2), (byte)((color.B + color2.B) / 2))); //Debug.WriteLine("secretCIEL1:" + secretCIEL1 + " secretCIELa1:" + secretCIEa1 + " secretCIEb1:" + secretCIEb1); //Debug.WriteLine("r:" + color.R + " g:" + color.G + " b:" + color.B); CIEXYZ c1 = RGBtoXYZ(color.R, color.G, color.B); //Debug.WriteLine("x:" + c1.X + " y:" + c1.Y + " z:" + c1.Z); CIELab lab1 = XYZtoLab(c1); //Debug.WriteLine("lab1L:" + lab1.L + " lab1a:" + lab1.A + " lab1b:" + lab1.B); double delta = delta1994(lab1.L, lab1.A, lab1.B, secretCIEL1, secretCIEa1, secretCIEb1); //Debug.WriteLine("delta:" + delta); if (delta <= allowedColorDelta) { // pretty close match, now check the next one CIELab lab2 = XYZtoLab(RGBtoXYZ(color2.R, color2.G, color2.B)); delta = delta1994(lab2.L, lab2.A, lab2.B, secretCIEL2, secretCIEa2, secretCIEb2); if (delta <= allowedColorDelta) { // reset the colors this.colorPick1.Color = Windows.UI.Color.FromArgb(255, 0, 0, 255); this.colorPick2.Color = Windows.UI.Color.FromArgb(255, 255, 0, 255); //Debug.WriteLine("UNLOCKED WOOWOWOWOWOW"); Storyboard sb = (Storyboard)this.Resources["ShowUnlock"]; sb.Begin(); } } }