ARKBreedingStats.ArkOCR.PercentageMatch C# (CSharp) Method

PercentageMatch() public method

public PercentageMatch ( Bitmap img1, Bitmap img2 ) : float
img1 System.Drawing.Bitmap
img2 System.Drawing.Bitmap
return float
        public float PercentageMatch(Bitmap img1, Bitmap img2)
        {
            //int whiteInFirstAlsoInSecond = 0;
            //int whiteInFirstNotInSecond = 0;
            //int blackInFirstAlsoInSecond = 0;
            //int blackInFirstNotInSecond = 0;
            double matches = 0;

            int minWidth = Math.Min(img1.Width, img2.Width);
            int minHeight = Math.Min(img1.Height, img2.Height);

            for (int i = 0; i < minWidth; i++)
            {
                for (int j = 0; j < minHeight; j++)
                {
                    if (img1.GetPixel(i, j).R == 0)
                    {
                        if (img2.GetPixel(i, j).R == 0)
                            matches++;
                        else if (img2.GetPixel(i, j).R < 255)
                            matches += 0.2;
                    }
                    else if (img1.GetPixel(i, j).R < 255)
                    {
                        if (img2.GetPixel(i, j).R == 255)
                            matches += 0.6;
                        else if (img2.GetPixel(i, j).R != 0)
                            matches += 0.8;
                        else matches += 0.2;
                    }
                    else
                    {
                        if (img2.GetPixel(i, j).R == 255)
                            matches++;
                        else if (img2.GetPixel(i, j).R != 0)
                            matches += 0.6;
                    }

                    //if (img1.GetPixel(i, j).R != 0)
                    //{
                    //    if (img2.GetPixel(i, j).R != 0)
                    //        whiteInFirstAlsoInSecond++;
                    //    else
                    //        whiteInFirstNotInSecond++;
                    //}
                    //else
                    //{
                    //    if (img2.GetPixel(i, j).R == 0)
                    //        blackInFirstAlsoInSecond++;
                    //    else
                    //        blackInFirstNotInSecond++;
                    //}
                }
            }

            // assume whites count as much as blacks.

            //int totalMatches = whiteInFirstAlsoInSecond + blackInFirstAlsoInSecond;
            //int totalFails = whiteInFirstNotInSecond + blackInFirstNotInSecond;

            //totalFails += (Math.Max(img1.Width, img2.Width) * Math.Max(img1.Height, img2.Height) - minWidth * minHeight);
            //float oldpercentage = (float)totalMatches / (totalMatches + totalFails);

            float percentage = (float)(matches / (Math.Max(img1.Width, img2.Width) * Math.Max(img1.Height, img2.Height)));

            return percentage;
        }