Page 1 of 2

"missing image filename" error from compare program

Posted: 2013-08-03T20:02:39-07:00
by timg11
I just discovered ImageMagick, and I'm figuring out how it works.

I want to compare two images and get a metric on their similarity returned to be used by a subsequent program in the script.

I found a usage example hereand I'm trying to model my command after this example:

Code: Select all

compare -metric MAE image1 image2 null: 2>1
When I run my command like this:

Code: Select all

compare -identify -metric MAE Crop1.jpg Interactive_Template.jpg null:
I get this output:

Code: Select all

Crop1.jpg[0] JPEG 345x855 345x855+0+0 8-bit sRGB 7.45KB 0.016u 0:00.017
Interactive_Template.jpg[0] JPEG 345x855 345x855+0+0 8-bit sRGB 14.5KB 0.016u 0:00.013
25.0933 (0.0984051)
But I need to post-process that output. So I redirect the output to a file like this:

Code: Select all

compare -identify -metric MAE Crop1.jpg Interactive_Template.jpg null: > result.txt
I don't understand why the file "result.txt" contains only the first two lines of output:

Code: Select all

Crop1.jpg[0] JPEG 345x855 345x855+0+0 8-bit sRGB 7.45KB 0.016u 0:00.017
Interactive_Template.jpg[0] JPEG 345x855 345x855+0+0 8-bit sRGB 14.5KB 0.016u 0:00.013
The line I need is missing.

I don't understand what the "null: " parameter is doing, so I tried removing it.

Then I get this error:

Code: Select all

C:\Data\DEV\>compare -identify -metric MAE Crop1.jpg Interactive_Template.jpg
compare.exe: missing an image filename `Crop1.jpg' @ error/compare.c/CompareImageCommand/951.
Can anyone point me to an explanation of the required parameters for COMPARE, and the meaning and proper use of the "NULL:" parameter?

Re: "missing image filename" error from compare program

Posted: 2013-08-03T20:18:49-07:00
by GreenKoopa
Welcome. A good place to begin reading about compare:
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/

The first two images are input, the two to compare. The third image is output, a difference of the two inputs. When this output image is not wanted, null: may be used. This is common when only the -metric is of interest.

To help you with redirecting the output, it would be helpful to know your platform. For Windows
To capture both outputs to the same file:
compare -identify -metric MAE out_1.png out_2.png null: 1> result.txt 2>&1
To capture both outputs to separate files:
compare -identify -metric MAE out_1.png out_2.png null: 1> identify.txt 2> metric.txt
Leave off either or both redirections to send them to the console.
Replace either filename with nul to disregard that output.

Re: "missing image filename" error from compare program

Posted: 2013-08-03T23:35:38-07:00
by fmw42

Re: "missing image filename" error from compare program

Posted: 2013-08-04T02:06:58-07:00
by snibgo
As GreenKoopa has implied but not explicitly stated: the compare metric data goes to stderr, not stdout, so needs the "2>" trick to put the data in a file.

Re: "missing image filename" error from compare program

Posted: 2013-08-04T02:23:45-07:00
by GreenKoopa
snibgo wrote: As GreenKoopa has implied but not explicitly stated
As always, snibgo is much more articulate. Still, that anything coherent comes out of a turtle is remarkable.
snibgo wrote: the compare metric data goes to stderr, not stdout
This design choice is both genius and confusing.

Re: "missing image filename" error from compare program

Posted: 2013-08-04T11:02:53-07:00
by timg11
Thanks to all. The form:

Code: Select all

compare -identify -metric MAE out_1.png out_2.png null: 1> identify.txt 2> metric.txt
works perfectly. I didn't need the identify information file anyway, so I can just ignore that file.

Re: "missing image filename" error from compare program

Posted: 2013-08-04T11:19:22-07:00
by fmw42
If on Unix/Mac, you can store the results into a variable and process from there. You do not have to store to file unless you want to.

var=`compare -metric MAE out_1.png out_2.png null: 2>&1`

You can even filter the variable to separate out the match score from the coordinates if you want either inline using pipe to something like sed or tr and cut or you can filter in another step.

My personal preference in most cases is to use rmse metric, though in a few under special circumstances I have used other metrics.

I am sure the Windows users can show you an equivalent way to put the results into a variable, if you are on Windows.

Re: "missing image filename" error from compare program

Posted: 2013-08-04T11:53:42-07:00
by GreenKoopa
timg11 wrote:Thanks to all. The form:

Code: Select all

compare -identify -metric MAE out_1.png out_2.png null: 1> identify.txt 2> metric.txt
works perfectly. I didn't need the identify information file anyway, so I can just ignore that file.
If you don't need it you could replace identify.txt with nul, or leave -identify out of your command in the first place.

Re: "missing image filename" error from compare program

Posted: 2013-08-04T14:03:28-07:00
by snibgo
In Windows 7, this will save the results in COMP_INT and COMP_FLT. The echoes are just for demonstration.

Code: Select all

FOR /F "tokens=1,2 usebackq delims=() " %%R ^
IN (`%IM%compare -metric RMSE rose: rose: NULL: 2^>^&1`) ^
DO (
  echo answer: %%R %%S
  set COMP_INT=%%R
  set COMP_FLT=%%S
)

echo Saved result: %COMP_INT% %COMP_FLT%

Re: "missing image filename" error from compare program

Posted: 2018-04-25T14:37:52-07:00
by mrinmay
I am getting a similar error

./compare ./bag_frame1.gif ./bag_frame2.gif x:

dyld: Library not loaded: /ImageMagick-7.0.7/lib/libMagickCore-7.Q16HDRI.5.dylib
Referenced from: /Users/mrinmaykalita/Downloads/ImageMagick-7.0.7/bin/./compare
Reason: image not found
Abort trap: 6

also shows for ./compare ./bag_frame1.gif ./bag_frame2.gif ./compare.gif
./compare -identify -metric MAE bag_frame1.gif bag_frame2.gif null:
./compare

Re: "missing image filename" error from compare program

Posted: 2018-04-25T14:55:40-07:00
by fmw42
Please do not post to multiple forums.

For IM 7, compare is replaced by magick compare.

Re: "missing image filename" error from compare program

Posted: 2018-04-25T15:16:24-07:00
by mrinmay
I get the same error when running from inside bin folder (permissions are a+x)

./magick ./compare ./bag_frame1.gif ./bag_frame2.gif x:
dyld: Library not loaded: /ImageMagick-7.0.7/lib/libMagickCore-7.Q16HDRI.5.dylib
Referenced from: /Users/mrinmaykalita/Downloads/ImageMagick-7.0.7/bin/./magick
Reason: image not found
Abort trap: 6

Re: "missing image filename" error from compare program

Posted: 2018-04-25T16:03:38-07:00
by mrinmay
Any suggestions @fmw2 kindly?

Re: "missing image filename" error from compare program

Posted: 2018-04-25T16:58:08-07:00
by fmw42
If your files are in the same location as you execute your command, then just do

Code: Select all

magick compare bag_frame1.gif bag_frame2.gif diff.gif
If that works, then try

Code: Select all

magick compare bag_frame1.gif bag_frame2.gif x:
or

Code: Select all

./magick compare ./bag_frame1.gif ./bag_frame2.gif x:
Do not put ./ before compare.

Re: "missing image filename" error from compare program

Posted: 2018-04-26T16:21:15-07:00
by mrinmay
Hello @fmw2

I am trying to send output of the command from shell to a file

how do I do that? Can you help?

magick compare -metric MSE $f1 $f2 NULL: >> /file
does not work.