Page 1 of 1

log compare score

Posted: 2013-01-24T05:35:29-07:00
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

Re: log compare score

Posted: 2013-01-24T05:46:03-07:00
by snibgo
The score goes to stderr, not stdout. (stdout is used for images.)

Re: log compare score

Posted: 2013-01-24T05:51:17-07:00
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()