I need to check how similar two images are. I need to have this in a number; a percentage.
public static void Compare(Bitmap bmp1, Bitmap bmp2)
{
int width;
int height;
if (bmp1.width < bmp2.width)
{
width = bmp1.width;
}
else
{
width = bmp2.width;
}
if (bmp1.heigth < bmp2.width)
{
heigth = bmp1.heigth;
}
else
{
heigth = bmp2.heigth;
}
int contador = 0;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
if (bmp1.GetPixel(x, y) == bmp2.GetPixel(x, y))
{
contador++
}
}
}
Messagebox.Show("The percent of similar is:" + (contador / (height * width) * 100).ToString());
}
This works perfectly while the images are not of different size, because for example when putting a white line to one of the 2 images the percentage of comparison is 0% that if I put it at the beginning and if I put it at the end then it does not take it into consideration.
I surfed quite looking but I always find examples of images that have the same height and length.
Is there any way to see how much similarity has one image of the other? The resources are not problems since usually the images are quite small.