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

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
redhood
Posts: 1
Joined: 2019-10-16T23:22:38-07:00
Authentication code: 1152

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post by dlemstra »

Setting image1.Compose to CompositeOperator.Difference should give you the result that you want.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply