0

I'm coding in C# and I need help with the difference between two images. I'm using the emgu to help me with this part. The problem here is that as long as there is a diff in the pixel, it will be shown in the resulted pic.

However, what I need is if the pixel for the RefImg is higher than the CompImg, the color should be red and if it is lesser it should be green.

The code should take a minimal amount of time to execute too.

The code below is what I'm using now.

Image<Bgr, Byte> RefImg = new Image<Bgr, Byte>(new Bitmap(refImg));
Image<Bgr, Byte> CompImg = new Image<Bgr, Byte>(new Bitmap(compImg));
Image<Bgr, Byte> Difference; //Difference 
double Threshold = 5;

Difference = RefImg.AbsDiff(CompImg);
Difference = Difference.ThresholdBinary(new Bgr(Threshold, Threshold, Threshold), new Bgr(0, 255, 0)); 
JoshuaTheMiller
  • 2,582
  • 25
  • 27
Snooze
  • 1
  • 5

1 Answers1

1

Using Abs diff allow you to find différences but not the sign due to absolute value operator. To find greater and lower pixels value you must use cmp function.

Image<Bgr, Byte> RefImg = new Image<Bgr, Byte>(...);
Image<Bgr, Byte> CompImg = new Image<Bgr, Byte>(...);

//Convert to gray levels or split channels
Image<Gray, Byte> RefImgGray = RefImg.Convert<Gray, byte>();
Image<Gray, Byte> CompImgGray = CompImg.Convert<Gray, byte>();

//Compare image and build mask
Image<Gray, Byte> MaskDifferenceHigh = RefImgGray.Cmp(CompImgGray, CmpType.GreaterThan);
Image<Gray, Byte> MaskDifferenceLow = RefImgGray.Cmp(CompImgGray, CmpType.LessThan);

//Draw result
Image<Bgr, byte> result = RefImg.CopyBlank();
result.SetValue(new Bgr(Color.Red),MaskDifferenceHigh);
result.SetValue(new Bgr(Color.Green), MaskDifferenceLow);

Hope it helps.

  • Yes, it did help me! Thanks so much. I think there's a typo for the MaskDifferenceLow though, you compared the same image. – Snooze Sep 17 '17 at 08:53