log compare score

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?".
Post Reply
lunchtimecinema
Posts: 2
Joined: 2013-01-24T05:12:16-07:00
Authentication code: 6789

log compare score

Post by lunchtimecinema »

Hello,
Im new to ImageMagick and would like to use the compare function in terminal as suggested:

Code: Select all

$ compare -metric PSNR rose.jpg reconstruct.jpg difference.png
but I'd like to save the output score (i.e. '28.31') to a text file (or other supported filetype)

If this can be done via the terminal command that would be preferable.

I've tried and failed at doing this with a python script to execute the command and catch the output:

Code: Select all

output = subprocess.Popen(["compare","-metric","PSNR",path + "before.jpg", path + "after.jpg", path + "difference.jpg"], stdout=subprocess.PIPE).communicate()[0]
with open(path+"scores.txt", "a") as myfile:
    myfile.write(str(output))
But the score does not come back within the 'output' return.
thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: log compare score

Post by snibgo »

The score goes to stderr, not stdout. (stdout is used for images.)
snibgo's IM pages: im.snibgo.com
lunchtimecinema
Posts: 2
Joined: 2013-01-24T05:12:16-07:00
Authentication code: 6789

Re: log compare score

Post by lunchtimecinema »

yes, that now works thanks!
Correct version:

Code: Select all

output = subprocess.Popen(["compare","-metric","PSNR",path + "before.jpg", path + "after.jpg", path + "difference.jpg"], stderr=subprocess.PIPE).stderr
score = output.read()
Post Reply