Magick.NET How to use .ColorFuzz as pixel tolerance for image comparison

1.1k Views Asked by At

I am new to the image comparison area.

I am using C# and Magick.NET (Magick.NET-Q16-AnyCPU version: 7.14.5) to compare screenshots.

Using .ColorFuzz I want to implement some kind of pixel tolerance, to ignore screenshots differences.

Here is my code:

double fuzzLevel = 0;

MagickImage baseHeaderView = new MagickImage(@"C:\githubActual.png");
MagickImage actualHeaderView = new MagickImage(@"C:\githubBase.png");
MagickImage diffView = new MagickImage();

baseHeaderView.ColorFuzz = (Percentage)fuzzLevel;
baseHeaderView.Compare(actualHeaderView, ErrorMetric.Absolute, diffView);

baseHeaderView.Composite(diffView, CompositeOperator.Over);
Console.WriteLine(baseHeaderView.GetAttribute("distortion"));
baseHeaderView.Write(@"C:\diffView.png");

Here is my base and actual screenshots.

This is the diff image when fuzzLevel variable = 0. baseHeaderView.GetAttribute("distortion") will return 614 different pixels in this case.

When I am changing fuzzLevel to 75, baseHeaderView.GetAttribute("distortion") returns 0 different pixels, but diff image still contains highlighted differences

So, my question is why when distortion is equal to 0 there are still highlighted differences in the diff image. Am I doing something wrong, or this is expected behavior?

It is possible to change the code above, so when distortion is 0, then diff image will not contain any highlighted differences?

1

There are 1 best solutions below

1
On BEST ANSWER

It looks like you found a bug in the ImageMagick library. Your issues will be resolved with the next release of Magick.NET. Next time feel free to open an issue here instead: https://github.com/dlemstra/Magick.NET/issues