1

I'm trying to compare two screenshots from a webpage using Magick.NET, a C# library from ImageMagick. My code looks like this:

 //Adapt image a bit otherwise he'll throw an error over the whole image
            newScreenshot.ColorFuzz = new Percentage(15);
            //Get the difference, 1 = perfectly the same, less then 1 not.
            double diff = newScreenshot.Compare(benchmarkScreenshot, new ErrorMetric(), imgDiff);
            //Output the result image for comparaison
            imgDiff.Write(compareResultPath);


            if (diff < 0.998)
            {
                //Do something
            }

In this case I would get values lower then 1, where I imagined 1 would be "Identical" and everything less then 1 wouldn't be. I was wrong... So the only way I could think of to check if they are as identical as possible is to lower the tolerence by lowering the value in the if-statement.

So if I have a screenshot from a website, and I adapt it I get the following values for the "diff" variable:

  • Identical image: 0.99842343024053205

  • Removing a sentence: 0.99776453647987487

  • Removing one letter from any word on the page: 0.99698398328761506

I'm very afraid of the fact that removing an entire sentence has a higher value then just a single letter.

I also tried with ErrorMetric.Absolute rather then new ErrorMetric(), the values that I got for the "diff" variable were:

  • Identical image: 1949

  • Removing a sentence: 766

  • Removing one letter from any word on the page: 75

Is there a better, more accurate way then what I'm trying to do to check if there's an actual change or not?

Akorna
  • 217
  • 2
  • 16
  • In command line ImageMagick, the compare command has a -metric option. I do not know which is the default. But if you use rmse, the smaller the value, the more closely they match. A zero value is a perfect match and a 1 value is a total mismatch. You can also generate an output image that shows where the changes occur. I presume that .NET can do similarly. See http://www.imagemagick.org/Usage/compare/. Sorry I do not know .NET – fmw42 Jun 09 '17 at 16:20
  • 1
    The commandline also provides a "signature" checksum in the "identify -verbose" output. If the signatures of two files are identical, then it's virtually certain that the image data in the two files is identical. – Glenn Randers-Pehrson Jun 09 '17 at 18:04
  • Are you saving your screenshots as JPEGs? If so, you may be better off with PNG as they are lossless. – Mark Setchell Jun 09 '17 at 21:01
  • @fmw42 Indeed there is a way to get the difference image. But I want to avoid it being thrown to us if there is no "difference" :) – Akorna Jun 12 '17 at 06:24
  • @GlennRanders-Pehrson I'm going to look into that – Akorna Jun 12 '17 at 06:24
  • @MarkSetchell I've tried both types, same results sadly. – Akorna Jun 12 '17 at 06:25
  • Unfortunately neither @fmw42 nor I are familiar with Magick.NET. You could ask on the Magick.NET forum at the Imagemagick discourse server, https://www.imagemagick.org/discourse-server/ I imagine it will be something like "image.signature(...)". – Glenn Randers-Pehrson Jun 12 '17 at 11:35

0 Answers0