public Bitmap SubtractImages(Bitmap Left, Bitmap Right)
{
if (Left.Width != Right.Width)
{
throw new Exception("Images dimension must be equal.");
}
if (Left.Height != Right.Height)
{
throw new Exception("Images dimension must be equal.");
}
Bitmap OutputImage = new System.Drawing.Bitmap(Left.Width, Left.Height);
//int x, y;
for (int x = 0; x < Left.Width; x++)
{
for (int y = 0; y < Left.Height; y++)
{
Color pixelLeft = Left.GetPixel(x, y);
Color pixelRight = Right.GetPixel(x, y);
int gs1 = (int)((pixelLeft.R * 0.3) + (pixelLeft.G * 0.59) + (pixelLeft.B * 0.11));
int gs2 = (int)((pixelRight.R * 0.3) + (pixelRight.G * 0.59) + (pixelRight.B * 0.11));
int gs = gs1 - gs2;
if (gs > 255) gs = 255;
if (gs < 0) gs = 0;
Color newColor = Color.FromArgb(255, gs, gs, gs);
OutputImage.SetPixel(x, y, newColor);
}
}
return OutputImage;
}