Пример #1
0
        public static float DoFullCompare(int R1, int G1, int B1, int R2, int G2, int B2)
        {
            ColorFormulas oColor1 = new ColorFormulas(R1, G1, B1);
            ColorFormulas oColor2 = new ColorFormulas(R2, G2, B2);

            return(oColor1.CompareTo(oColor2));
        }
Пример #2
0
        ///
        /// The smaller the number returned by this, the closer the colors are
        ///
        ///
        ///
        public float CompareTo(ColorFormulas oComparisionColor)
        {
            // Based upon the Delta-E (1976) formula at easyrgb.com (http://www.easyrgb.com/index.php?X=DELT&H=03#text3)
            double DeltaE = Math.Sqrt(Math.Pow((CieL - oComparisionColor.CieL), 2) + Math.Pow((CieA - oComparisionColor.CieA), 2) + Math.Pow((CieB - oComparisionColor.CieB), 2));

            return((float)DeltaE);
        }
Пример #3
0
        public static ComparisonReport CompareImages(Bitmap img1, Bitmap img2, float tolerance = 0)
        {
            Bitmap output       = new Bitmap(img1.Width, img1.Height);
            float  maxDeltaE    = float.MinValue;
            float  minDeltaE    = float.MaxValue;
            float  totalDeltaE  = 0;
            float  deltaEValues = 0;
            float  avgDeltaE    = 0;

            for (int x = 0; x < img1.Width; x++)
            {
                for (int y = 0; y < img1.Height; y++)
                {
                    Color         pixel1 = img1.GetPixel(x, y);
                    Color         pixel2 = img2.GetPixel(x, y);
                    ColorFormulas cf1    = new ColorFormulas(pixel1.R, pixel1.G, pixel1.B);
                    ColorFormulas cf2    = new ColorFormulas(pixel2.R, pixel2.G, pixel2.B);
                    float         deltaE = (cf1.CompareTo(cf2));

                    if (minDeltaE > deltaE)
                    {
                        minDeltaE = deltaE;
                    }
                    if (maxDeltaE < deltaE)
                    {
                        maxDeltaE = deltaE;
                    }
                    totalDeltaE += deltaE;
                    deltaEValues++;

                    if (deltaE <= tolerance)
                    {
                        Color  pixel = img1.GetPixel(x, y);
                        double h, s, v;
                        ColorToHSV(pixel, out h, out s, out v);
                        pixel = ColorFromHSV(h, s / 10, 1 - v / 10);
                        output.SetPixel(x, y, pixel);
                    }
                    else
                    {
                        output.SetPixel(x, y, Color.Red);
                    }
                }
            }

            avgDeltaE = totalDeltaE / deltaEValues;

            return(new ComparisonReport(output, maxDeltaE, minDeltaE, avgDeltaE));
        }