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.
Storing compare output as a variable
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Storing compare output as a variable
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
That did the trick. Thanks
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Storing compare output as a variable
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.
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');
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/