Image Compare doesn't work like expected with transparent images
See original GitHub issueMagick.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:
- Created a year ago
- Comments:11 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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#.
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: