"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 » 2013-08-03T20:02:39-07:00

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 » 2013-08-03T20:18:49-07:00

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: 23241
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 » 2013-08-03T23:35:38-07:00


snibgo
Posts: 10278
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 » 2013-08-04T02:06:58-07:00

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 » 2013-08-04T02:23:45-07:00

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 » 2013-08-04T11:02:53-07:00

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: 23241
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 » 2013-08-04T11:19:22-07:00

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 » 2013-08-04T11:53:42-07:00

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: 10278
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 » 2013-08-04T14:03:28-07:00

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 » 2018-04-25T14:37:52-07:00

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: 23241
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 » 2018-04-25T14:55:40-07:00

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 » 2018-04-25T15:16:24-07:00

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 » 2018-04-25T16:03:38-07:00

Any suggestions @fmw2 kindly?

User avatar
fmw42
Posts: 23241
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 » 2018-04-25T16:58:08-07:00

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 » 2018-04-26T16:21:15-07:00

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