예제 #1
0
        public void FourDifferentColorsTest()
        {
            var matrix = new ImageLabColorMatrix(2, 2);

            matrix.AddColor(0, 0, 10, 20, 30);
            matrix.AddColor(1, 0, 120, 230, 130);
            matrix.AddColor(0, 1, 60, 50, 40);
            matrix.AddColor(1, 1, 132, 221, 39);

            //first point
            Assert.AreEqual(5.8508421241227389d, matrix[0, 0].L);
            Assert.AreEqual(-1.4962768959702193d, matrix[0, 0].a);
            Assert.AreEqual(-8.2548250495584838d, matrix[0, 0].b);

            //second point
            Assert.AreEqual(21.655220595591864d, matrix[0, 1].L);
            Assert.AreEqual(3.280509548974714d, matrix[0, 1].a);
            Assert.AreEqual(8.1445067737438315d, matrix[0, 1].b);

            //third point
            Assert.AreEqual(83.050799346571111d, matrix[1, 0].L);
            Assert.AreEqual(-48.362370827319864d, matrix[1, 0].a);
            Assert.AreEqual(38.474842882762729d, matrix[1, 0].b);

            //fourth point
            Assert.AreEqual(80.230934014636588d, matrix[1, 1].L);
            Assert.AreEqual(-47.580683430828493d, matrix[1, 1].a);
            Assert.AreEqual(71.103078949925276d, matrix[1, 1].b);
        }
예제 #2
0
        public double Process(ImageLabColorMatrix colorMatrix1, ImageLabColorMatrix colorMatrix2)
        {
            if (colorMatrix1.Width != colorMatrix2.Width || colorMatrix1.Height != colorMatrix2.Height)
            {
                return(100.0);
            }

            double counter = 0d;
            double sum     = 0.0d;

            for (int x = 0; x < colorMatrix1.Width; x++)
            {
                for (int y = 0; y < colorMatrix1.Height; y++)
                {
                    var color1 = colorMatrix1[x, y];
                    var color2 = colorMatrix2[x, y];

                    var result = ColorDifferenceAnalyzer.ComputeColorDifference(color1, color2);

                    if (result > 0.0d)
                    {
                        counter++;
                    }

                    sum += result;
                }
            }

            if (Math.Abs(counter) < 0.00001)
            {
                return(0.0d);
            }
            return((sum / counter) * (counter / (colorMatrix1.Width * colorMatrix1.Height)));
        }