Page 1 of 1

MagickCore::CompareImages() question

Posted: 2016-04-15T11:12:51-07:00
by trevor123
Hello

I've observed a difference in using MagickCore::CompareImages when the image hasn't originated from a decoded png. The code, essentially, looks like:

Code: Select all

Image a(pixel buffer);
Image b("b.png");
a.write("saved_a.png");
MagickCore::CompareImages(b.image(), a.image(), MagickCore::FuzzErrorMetric, &distortion, exception);
The resultant distortion is 0.00422927

If, however, I reload the "saved_a.png" file back into an Image type, and compare, I get a lower difference value, say 0.00345319:

Code: Select all

Image a(pixel buffer);
Image b("b.png");
a.write("saved_a.png");
Image c("saved_a.png"); // decode the image we've just saved
// note compare b and c
MagickCore::CompareImages(b.image(), c.image(), MagickCore::FuzzErrorMetric, &distortion, exception);
And indeed, this is true using the command line:

Code: Select all

$ compare -metric FUZZ a.png b.png null
0.00345319
How can I ensure I get the same values back without decoding the file that I've just written out (ie I don't want to do that as it's expensive). Is there something that I can invoke on Image?

Thanks a lot

Re: MagickCore::CompareImages() question

Posted: 2016-04-15T16:30:37-07:00
by snibgo
Please, always tell us what version of IM you are running on. The platform probably isn't important here, but the Q-number and HDRI is.

Is your pixel buffer identical to the saved file a.png? Perhaps the buffer is 32-bit or something.

Re: MagickCore::CompareImages() question

Posted: 2016-04-17T14:46:39-07:00
by trevor123
Sorry, it's Magick++ v6.0.0-7. Presumably, you're referring to MAGICKCORE_QUANTUM_DEPTH (which is 16 - I've also tried 8 ) and MAGICKCORE_HDRI_ENABLE (which is 0). The pixel buffer is a Magick::CharPixel, and is a GL framebuffer.

Re: MagickCore::CompareImages() question

Posted: 2016-04-17T17:02:21-07:00
by snibgo
v6.0.0-7 is a museum piece. I suggest you upgrade.

I don't know exactly what your first code example does, so I don't know if the difference between the compares is expected behaviour.