ColorDifference { public static double deltaE(float[] lab1, float[] lab2, int type) { if (type == CIE76) { return de_CIE76(lab1, lab2); } if (type == CIE94) { return de_CIE94(lab1, lab2); } if (type == CIE2000) { return de_CIE2000(lab1, lab2); } return Double.NaN; }  static double deltaE(float[] lab1, float[] lab2, int type); static double deltaL(float[] lab1, float[] lab2, int type); static double deltaC(float[] lab1, float[] lab2, int type); static double deltaH(float[] lab1, float[] lab2, int type); final static int CIE76; final static int CIE94; final static int CIE2000; }
@Test public void deltaETest() { logger.info("### Color difference tests"); double de76, de94, de2000; float[][] colors = new float[][] { black, blue, green, red, cyan, magenta, yellow, white }; double[][] expdE = new double[colors.length * colors.length][3]; expdE[0] = new double[] { 134.4973, 134.4973, 38.452 }; expdE[1] = new double[] { 143.3802, 143.3802, 87.8053 }; expdE[2] = new double[] { 119.84229, 119.84229, 51.3411 }; expdE[3] = new double[] { 104.933, 104.933, 89.9176 }; expdE[4] = new double[] { 126.6178, 126.6178, 56.39465 }; expdE[5] = new double[] { 136.0026, 136.0026, 101.7567 }; expdE[6] = new double[] { 100, 100, 100 }; expdE[7] = new double[] { 249.8625, 100.3250, 86.2377 }; expdE[8] = new double[] { 184.0129, 65.8068, 55.7975 }; expdE[9] = new double[] { 165.249711, 76.423064, 68.394632 }; expdE[10] = new double[] { 65.034953, 35.693348, 36.381306 }; expdE[11] = new double[] { 232.1433, 100.4879, 101.7251 }; expdE[12] = new double[] { 148.916111, 72.95108, 66.916642 }; expdE[13] = new double[] { 163.949043, 68.206066, 84.315595 }; expdE[14] = new double[] { 100.170582, 31.296575, 34.746495 }; expdE[15] = new double[] { 225.069427, 87.220456, 108.591186 }; expdE[16] = new double[] { 65.468789, 25.145621, 24.766593 }; expdE[17] = new double[] { 113.9924, 22.216953, 32.766165 }; expdE[18] = new double[] { 160.650309, 67.777436, 71.170128 }; expdE[19] = new double[] { 131.1362, 50.653977, 43.251949 }; expdE[20] = new double[] { 108.413607, 57.594223, 60.988315 }; expdE[21] = new double[] { 116.2060, 49.271276, 45.263973 }; expdE[22] = new double[] { 154.277858, 85.33285, 58.73103 }; expdE[23] = new double[] { 114.047794, 60.741430, 43.1763 }; expdE[24] = new double[] { 53.646781, 18.215779, 25.845217 }; expdE[25] = new double[] { 192.431605, 79.773082, 89.816011 }; expdE[26] = new double[] { 118.31371, 43.92827, 42.048382 }; expdE[27] = new double[] { 94.738016, 18.157318, 30.281539 }; int k = 0; for (int i = 0; i < colors.length - 1; i++) { for (int j = i + 1; j < colors.length; j++) { float[] a = colors[i]; float[] b = colors[j]; de76 = ColorDifference.deltaE(a, b, ColorDifference.CIE76); de94 = ColorDifference.deltaE(a, b, ColorDifference.CIE94); de2000 = ColorDifference.deltaE(a, b, ColorDifference.CIE2000); logger.info("(calculated - expected) = (dE76=" + (de76 - expdE[k][0]) + ", dE94=" + (de94 - expdE[k][1]) + ", dE2000=" + (de2000 - expdE[k][2]) + ")"); Assert.assertEquals(expdE[k][0], de76, eqDelta); Assert.assertEquals(expdE[k][1], de94, eqDelta); Assert.assertEquals(expdE[k][2], de2000, eqDelta); k++; } } }