Search code examples
imagemagick

Error showing when using ImageMagick compare


I have created what I hope to be a lossless .jp2 file from a .tif using ImageMagick.

for %%a in (*.tif) do magick "%%a" -quality 0 "%%~na.jp2"

I'd like to check that the conversion is lossless and so have used the command:

for %%a in (*.jp2) do magick compare -verbose "%%a" "%%~na.tif" -metric RMSE

After listing the details of the two files, this returns an error:

magick compare -verbose "DSC09906.jp2" "DSC09906.tif" -metric RMSE DSC09906.jp2 JP2 5463x3851 5463x3851+0+0 16-bit sRGB 84.1136MiB 7.566u 0:07.566 DSC09906.tif TIFF 5463x3851 5463x3851+0+0 16-bit TrueColor sRGB 120.385MiB 0.126u 0:00.126 compare: `RMSE' @ error/compare.c/CompareImagesCommand/1159

Is this error the difference between the two files (I was hoping for a 0) or have a I made a mistake in the way I have asked the comparison to be made?

Many thanks :-)


Solution

  • Your Imagemagick syntax is likely in error. You have the ordering wrong --- put the metric before the images-- and I do not see any output image for the comparison result. So for a given image, perhaps you should use the following syntax

    magick compare -verbose -metric RMSE "DSC09906.jp2" "DSC09906.tif"  compare_result.jp2
    

    The default for JP2 quality (in DB) is lossless. See https://imagemagick.org/script/defines.php

    I am not sure why you might want the output compare image to be JP2. Nevertheless, the above syntax should work. If you do not want the output compare image, the use NULL: in its place.