2

I'm using Magick.NET (Q16-x64 v7.0.0.0011) to compare images. When I use the command line version of ImageMagick and do a compare without any special options, it gives an image with the identical portions shown as a lightened background and the differences in red. I'm trying to duplicate this behavior in Magick.NET. I tried the following code:

var image1Path = @"D:\Compare Test\image1.jpg";
var image2Path = @"D:\Compare Test\image2.jpg";

var diffImagePath = @"D:\Compare Test\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);
}

What I end up with though is a file that shows only the differences. This seems like what you would get if you ran the command line version with "-compose src". The differences are whatever SetHighlightColor is set to and the rest of the image is a solid color according to SetLowlightColor. I tried several different files and file formats with the same result.

Reference the "Illustrated Examples" in the answer to the following SO question: Diff an Image What I'm getting is the first example. What I want is the last example.

Any help would be greatly appreciated.

Community
  • 1
  • 1
Craig
  • 48
  • 2
  • 6
  • Are you aware that ImageMagick 7.0.0 is not yet officially released? What's available now are only pre-liminary betas for testing. So know that some things may not work as expected! – Kurt Pfeifle Mar 31 '15 at 11:51
  • 2
    Thanks for this information. A developer of Magick.NET replied to my question on the Magick.NET forums. I was missing setting a property, but there is also a bug in the current version of ImageMagick on Compare. The developer is going to post an answer here once the bug is resolved. – Craig Mar 31 '15 at 14:26

1 Answers1

2

The CLI compare method used for the last example was:

compare img1.png img2.png delta.png

This did not explicitly set a -compose method. That means, compare used its default composition method, which is SrcOver. So the command was shorter, but equivalent with

compare img1.png img2.png -compose SrcOver delta.png

If you are interested to test out ALL the available composition methods for comparison, you can run

compare -list compose

It should return a list similar to this:

Atop Blend Blur Bumpmap ChangeMask Clear ColorBurn ColorDodge Colorize CopyBlack CopyBlue CopyCyan CopyGreen Copy CopyMagenta CopyOpacity CopyRed CopyYellow Darken DarkenIntensity DivideDst DivideSrc Dst Difference Displace Dissolve Distort DstAtop DstIn DstOut DstOver Exclusion HardLight HardMix Hue In Lighten LightenIntensity LinearBurn LinearDodge LinearLight Luminize Mathematics MinusDst MinusSrc Modulate ModulusAdd ModulusSubtract Multiply None Out Overlay Over PegtopLight PinLight Plus Replace Saturate Screen SoftLight Src SrcAtop SrcIn SrcOut SrcOver VividLight Xor

To actually see the effect of these methods, try this (on Mac OS X or Linux -- DOS cmd/*.bat you have to come up with yourself):

for i in $(compare -list compose); do
  compare img1.png img2.png -compose ${i} composed-with-${i}-delta.png
done

You'll find that there are quite some interesting effects to discover :)

Community
  • 1
  • 1
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345