Page 1 of 1

Storing compare output as a variable

Posted: 2012-08-07T11:51:29-07:00
by timAMD
Hi all, I am forced to use perl to do some work on calculating the pixel percentage difference on two images and I cannot seem to get the result from compare to store in a variable. It just seems to always spit out to the shell (I am on windows) and therefore I can't do anything with the return (it is blank).

I am using "$wrong = `compare -metric AE -compose src -alpha off \"testGold\\\Atari_Car\\\Atari_car.1.tif\" \"test3.3.0_render\\\Atari_Car\\\Atari_car.1.tif\" null:`;"\

Can someone please help me with this? I would greatly appreciate it.

Re: Storing compare output as a variable

Posted: 2012-08-07T12:41:30-07:00
by fmw42
add 2>&1 to the end of your command. The data goes to standard error and you need to make it go to standard out.

Re: Storing compare output as a variable

Posted: 2012-08-07T14:09:54-07:00
by timAMD
That did the trick. Thanks

Re: Storing compare output as a variable

Posted: 2012-08-07T21:05:44-07:00
by anthony
For image comapring in perl, for lots of images I found holding image thumbnails in memory with PerlMagick, and comparing them works better.

Here is a simple two thumb compare. I have scaled this up to compare directories of images.

Code: Select all

#!/usr/bin/perl
=head1 NAME

image_cmp_thumbs_two --  two image thumbnails - simply

=head1 SYNOPSIS

  image_compare  image  image

=head1 DESCRIPTION

Just compare two images and only two images.

=head1 AUTHOR

  Anthony Thyssen  21 January 2003  anthony_AT_griffith.edu.au

=cut
# -----------------------------------------------------------------------
use Image::Magick;

$i1 = Image::Magick->new;
$i2 = Image::Magick->new;

$w = $i1->Read( filename=> shift );       # read in images
warn("$w")  if $w;
exit  if $w =~ /^Exception/;

$w = $i2->Read( filename=> shift );
warn("$w")  if $w;
exit  if $w =~ /^Exception/;

$i1->Scale(width=>100, height=>100); # scale without preserving aspect ratio
$i2->Scale(width=>100, height=>100);

$w = $i1->Compare(image=>$i2);       # compare
die "$w" if $w;

printf "Errors is %f\n",     $i1->Get('error');
printf "Mean Error is %f\n", $i1->Get('mean-error');