imagemagickimage-comparison

ImageMagick `compare` precision


Probably a fairly simple question, but I can't seem to find an answer to it anywhere: When using ImageMagick's compare to figure out how different two images are, what degree of precision does the normalized cross correlation metric have? In other words, how many decimal points and/or significant figures can I expect from the command compare -metric NCC "$image1" "$image2" null: 2>&1? My few trials have seemed to get me 6 decimal places, but I'd like some confirmation that this simply isn't a coincidence.


Solution

  • In Imagemagick, compare returns only 6 digits. But that is just a formatting. The precision is computed at least to full floating point precision if not double precision.

    There is a -precision option, but it does not work with compare, thought it could be made so.

    However, there is a newer convert ... -compare option that will allow you to get more precision. This has been available since 6.8.6-9. See https://www.imagemagick.org/script/command-line-options.php#compare

    convert -precision 10 lena.png lena.jpg -metric NCC -compare -format "%[distortion]\n" info:
    0.9968860232