Page 1 of 1

Is it possible to compare 2 images and see the diff?

Posted: 2019-10-16T23:29:42-07:00
by redhood
This code on ImageMagick, I would like to do the same on Magick.NET

Code: Select all

convert anot.jpg one_real.jpg -compose difference -composite -morphology dilate disk:10 +level-colors "black,red" -fuzz 20% -transparent black result.png
Image
As you can see, I have a image1, image2, and the third image is the diff. I was able to do this on command line with the code I previously showed

this is my code on c#:

Code: Select all

 var image1Path = @"D:\Spot\tiger_real.jpg";
        var image2Path = @"D:\Spot\tiger_edit.jpg";

        var diffImagePath = @"D:\Spot\imageDiff.jpg";

        using (MagickImage image1 = new MagickImage(image1Path))
        using (MagickImage image2 = new MagickImage(image2Path))
        using (MagickImage diffImage = new MagickImage())
        {
             image1.Compare(image2, ErrorMetric.Absolute, diffImage);
            diffImage.Write(diffImagePath);
        }
But this is the result I m getting, I only drawed a line on the left side of the tiger image. The while image is highlighed with red color. I want the result just like the image I have shown.
Image

Re: Is it possible to compare 2 images and see the diff?

Posted: 2019-10-17T09:03:03-07:00
by fmw42
I do not use Magick.NET. But in looking at your code, you are using -compose difference -composite in command line, but using compare in Magick.NET. They are not equivalent. The output from compare is color coded over one of the two images. The output from composite, you color code the difference. You should use the equivalent of -compose difference -composite in Magick.Net, not compare.

See
https://imagemagick.org/Usage/compose/#difference
https://imagemagick.org/Usage/compare/#compare

Re: Is it possible to compare 2 images and see the diff?

Posted: 2019-10-17T11:13:59-07:00
by dlemstra
Setting image1.Compose to CompositeOperator.Difference should give you the result that you want.