For read 2 images and get differences between them I use this code in C# :
Bitmap Img1 = new Bitmap("D:\\Imgs\\Img1.png");
Bitmap Img2 = new Bitmap("D:\\Imgs\\Img2.png");
public static int[,] MatrisFromBMP(Bitmap bmp)
{
int width = bmp.Width, height = bmp.Height;
int[,] matris = new int[width, height];
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
Color c = bmp.GetPixel(i, j);
matris[i, j] = (c.R == 0 && c.G == 0 && c.B == 0) ? 0 : 1;
}
}
return matris;
}
public static Bitmap BMPFromMatris(int[,] matris, int width, int height)
{
Bitmap bmp = new Bitmap(width, height);
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
bmp.SetPixel(i, j, matris[i, j] == 1 ? Color.White : Color.Black);
return bmp;
}
these are my functions and this is my process :
int[,] Matris1;
int[,] Matris2;
int[,] Matris3;
Matris1 = MatrisFromBMP(Img1);
Matris2 = MatrisFromBMP(Img2);
Matris3 = MatrisFromBMP(Img2);
int dist = 0;
for (int i = 0; i < Img1.Width; i++)
{
for (int j = 0; j < Img1.Height; j++)
{
dist = Math.Abs(Matris1[i, j] - Matris2[i, j]);
Matris3[i, j] = dist;
}
}
Img3_p.Image = BMPFromMatris(Matris3, Img1.Width, Img2.Height);
This works fine but for each picture with Size(1360*768) take 5s !
This is a very long time for me and i just have less than 0.5 s !
What are the better ways to do this ?
thanks , Arman