"missing image filename" error from compare program

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?".
timg11
Posts: 2
Joined: 2013-08-03T19:55:50-07:00
Authentication code: 6789

"missing image filename" error from compare program

Post 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?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: "missing image filename" error from compare program

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "missing image filename" error from compare program

Post by fmw42 »

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

Re: "missing image filename" error from compare program

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: "missing image filename" error from compare program

Post 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.
timg11
Posts: 2
Joined: 2013-08-03T19:55:50-07:00
Authentication code: 6789

Re: "missing image filename" error from compare program

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "missing image filename" error from compare program

Post 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.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: "missing image filename" error from compare program

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "missing image filename" error from compare program

Post 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%
snibgo's IM pages: im.snibgo.com
mrinmay
Posts: 6
Joined: 2018-04-25T14:33:02-07:00
Authentication code: 1152

Re: "missing image filename" error from compare program

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "missing image filename" error from compare program

Post by fmw42 »

Please do not post to multiple forums.

For IM 7, compare is replaced by magick compare.
mrinmay
Posts: 6
Joined: 2018-04-25T14:33:02-07:00
Authentication code: 1152

Re: "missing image filename" error from compare program

Post 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
mrinmay
Posts: 6
Joined: 2018-04-25T14:33:02-07:00
Authentication code: 1152

Re: "missing image filename" error from compare program

Post by mrinmay »

Any suggestions @fmw2 kindly?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "missing image filename" error from compare program

Post 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.
mrinmay
Posts: 6
Joined: 2018-04-25T14:33:02-07:00
Authentication code: 1152

Re: "missing image filename" error from compare program

Post 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.
Last edited by mrinmay on 2018-04-26T16:58:09-07:00, edited 2 times in total.
Post Reply