Image Comparing and return Percentage

前端 未结 2 1897
南笙
南笙 2021-01-01 07:53
int DiferentPixels = 0;
Bitmap first = new Bitmap(\"First.jpg\");
Bitmap second = new Bitmap(\"Second.jpg\");
Bitmap container = new Bitmap(first.Width, first.Height         


        
相关标签:
2条回答
  • 2021-01-01 08:20

    For speed, resize the images to something very small (16x12, for example) and do the pixel comparison. If it is a near match, then try it at higher resolution.

    0 讨论(0)
  • 2021-01-01 08:21

    One obvious change would be call GetPixel only once per Bitmap, and then work with the returned Color structs directly:

    for (int i = 0; i < first.Width; ++i)
    {
        for (int j = 0; j < first.Height; ++j)
        {
            Color secondColor = second.GetPixel(i, j);
            Color firstColor = first.GetPixel(i, j);
    
            if (firstColor != secondColor)
            {
                DiferentPixels++;
                container.SetPixel(i, j, Color.Red);
            }
            else
            {
                container.SetPixel(i, j, firstColor);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题