Compare no output

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
jmspaggi
Posts: 29
Joined: 2020-02-09T15:15:17-07:00
Authentication code: 1152

Compare no output

Post by jmspaggi »

Hi,

I'm trying to compare 2 images. From the documentation I should do something like this:

Code: Select all

convert -compare -metric AE 1586348746.png 1586348789.png output.png
The output.png seems to be fine. However, the command doesn't return anything. I can count the red pixels on the output.png file, but from what I understand the metric should be printed in the standard output, no?

Thanks,

JMS

PS: This command fails while it should work: convert -version -compare -metric AE 1586348746.png 1586348789.png /dev/null removing "-version" makes it work.

jmspaggi
Posts: 29
Joined: 2020-02-09T15:15:17-07:00
Authentication code: 1152

Re: Compare no output

Post by jmspaggi »

Here is the full output of the command:

Code: Select all

(base) @t460s:~/$ convert -verbose -compare -metric AE 1586348746.png 1586348789.png /dev/null
1586348746.png PNG 1440x2960 1440x2960+0+0 8-bit sRGB 582426B 0.080u 0:00.070
1586348789.png PNG 1440x2960 1440x2960+0+0 8-bit sRGB 599430B 0.060u 0:00.059
1586348746.png=>/dev/null PNG 1440x2960 1440x2960+0+0 8-bit sRGB 0.840u 0:00.469

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare no output

Post by snibgo »

What version of IM? If v7, I suggest you use "magick", not "convert".

You seem to be confusing two possibilities.

1. Use "magick compare". Note there is no "-" in compare. For example:

Code: Select all

magick compare -metric AE 1586348746.png 1586348789.png output.png
The text goes to stderr.

2. Use just "magick", with the "-compare" operation. The operation should come after the inputs are read. If you want an image output and the "score" text output (to stdout), these are two outputs, so you need a "write" operation. The score text output needs a "-format".

Code: Select all

magick 1586348746.png 1586348789.png -metric AE -compare -format %[distortion] +write info: output.png
If using Windows BAT, double the %.
snibgo's IM pages: im.snibgo.com

jmspaggi
Posts: 29
Joined: 2020-02-09T15:15:17-07:00
Authentication code: 1152

Re: Compare no output

Post by jmspaggi »

Thanks for your help snibgo.

I'm using version 6 it seems. That's the one shipped with Debian:

Code: Select all

Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
I tried to "magick" command but it doesn't seem to exist. I also look for the file without any success.

In version 6, if I remove the "-" before compare, it complains that the "compare" files doesn't exist:

Code: Select all

convert-im6.q16: unable to open image `compare'
Taking your command exactly the way it is but replacing "magick" by "convert" seems to give an output:

Code: Select all

$ convert 1586348746.png 1586348789.png -metric AE -compare -format %[distortion] +write info: output.png
599955
Sometimes the output is in scientific format:

Code: Select all

convert 1586348746.png ../1586348139080_0_0_0.png -metric AE -compare -format %[distortion] +write info: output.png
4.01285e+06
Is there a way to avoid that?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare no output

Post by snibgo »

For IM v6, either use the "compare" command, or "convert" with the "-compare" option.

Code: Select all

compare -metric AE 1586348746.png 1586348789.png output.png

Code: Select all

convert 1586348746.png 1586348789.png -metric AE -compare -format %[distortion] +write info: output.png
I don't think there is any method to always guarantee avoiding scientific format. However, "-metric AE" will give an integer result (the number of non-matching pixels), so "-precision 15" before the "-format" will do that.
snibgo's IM pages: im.snibgo.com

jmspaggi
Posts: 29
Joined: 2020-02-09T15:15:17-07:00
Authentication code: 1152

Re: Compare no output

Post by jmspaggi »

Awesome! Thanks a lot again for your help! It all works perfectly.

JMS

Locked