question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image Compare doesn't work like expected with transparent images

See original GitHub issue

Magick.NET version

Magick.NET-Q16-AnyCPU-11.3.0

Environment (Operating system, version and so on)

Windows 10 - Version 21H1, 19043.1826

Description

I’m not sure if this is an issue of ImageMagick or the .NET version, but the image compare doesn’t work as expected with transparent PNG’s.

public bool ImagesEqual(string img1, string img2)
{
    MagickImage first = new MagickImage(img1);
    MagickImage second = new MagickImage(img2);

    double diff = first.Compare(second, new ErrorMetric());
    Console.WriteLine("Images are equal to: " + diff);

    // If the images are equal = NaN, they should at least be 95% equal
    if (double.IsNaN(diff) || diff >= 0.95)
    {
         return true;
    }
    else
    {
         return false;
    }
}

Steps to Reproduce

Put in the method 2 transparent images

Expected result: A value between 0 and 1 Actual result: A value above 1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dlemstracommented, Aug 21, 2022

I am not sure what you are asking and trying to accomplish. Maybe you could ask for more detailed help in the discussions of the @ImageMagick repository and then start a new discussion here if you need help to translate something to C#.

1reaction
dlemstracommented, Aug 8, 2022

I will try to add a unit test before the next release to check if this issue was resolved. Already gave it a try on the command line and got this output:

compare -metric ncc img1.png img2.png null:
0.840183
Read more comments on GitHub >

github_iconTop Results From Across the Web

Comparing images in which some parts are variable, but ...
Open the baseline image in an image editor (for instance, in MSPaint). Select the color that you will use as the “transparent” color....
Read more >
Quickly Check If a Google Image Is Really Transparent or Not
The Method · Visit https://images.google.com · Search for something you're interested in such as: lamps png · Click into a specific image so...
Read more >
Transparent Background Images | CSS-Tricks
This is the css codes to make the image background transparent! ... Works exactly as expected and makes modifying backgrounds a breeze.
Read more >
Google: Finding transparent images properly (No background)
A lot of people don't use Google properly for finding images with no backgrounds. This is the proper way to look for images...
Read more >
Transparent background does not stay transparent
Hi. JPEG does not support transparency. PNG does, if transparency is checked. Please show the dialog box with your option for the .png...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found