Use of compare in Perlmagick (create diff image)

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
KerwinLumpkins

Use of compare in Perlmagick (create diff image)

Post by KerwinLumpkins »

I have a script running the compare utility in Perlmagick. I am able to get the error but how do I generate the "diff image". For instance in the command line interface I would write

compare -metric mae refImage.png checkThisImage.png diff.png

to do comparison between the refImage.png and checkThis.png images, with their difference pixels going into a file called "diff.png". How do I use Perlmagick to generate diff.png. Further, is there an interface spec somwhere that defines how to use compare and other utilities? For instance the Get function/method in the script below: Is there a doc that spells out usage of this and other functions/methods?

The script I'm using now is
-----------------------------------------------------------------------------
use Image::Magick;

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

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

$w = $i2->Read( filename=>'imgSmallDiff.PNG');
warn("$w") if $w;
exit if $w =~ /^Exception/;

$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'));
-------------------------------------------------------------------------------
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Use of compare in Perlmagick (create diff image)

Post by magick »

The complete compare functionality is not yet built into PerlMagick just yet. It should be available in point release in the near future.
KerwinLumpkins

Re: Use of compare in Perlmagick (create diff image)

Post by KerwinLumpkins »

Ah. Is there a list of what is supported in PerlMagick and some information about the functions that are supported. How about composite function? To cut to the chase, what i'm trying to do is use ImageMagick to find differences between ref images and a generated image and then update a log file that says "These are the same" or "No, they are not the same and there are x number of pixels different" or some other metric of difference. If PerlMagick isn't the best way to do it now, can you suggest another method?

Thanks, Kerwin
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Use of compare in Perlmagick (create diff image)

Post by magick »

See http://www.imagemagick.org/script/perl-magick.php. Documentation is sparse.

A patch to the PerlMagick Compare() method will be available in ImageMagick 6.5.4-3 Beta by sometime tomorrow to support the metric option.
wpns

Re: Use of compare in Perlmagick (create diff image)

Post by wpns »

I can confirm that:

$Difference = $Image->Compare(image=>$Previous, metric=>'PSNR');
$SNRdelta = $Difference->Get('error');
printf ("[ %f ]",$SNRdelta);

works just fine, where $Difference, $Image, and $Previous are images made with

my $Image=Image::Magick->new;

(etc) Note that if the images you are comparing are not the same size, IM will crash, but that arguably isn't a useful function anyway. in my case I had to:

if ($counter == 0)
{
$Previous = $Image->Clone();
$status = $Previous->Colorize(fill=>'white',opacity=>'100%');
warn "$status" if "$status";
}

on the first time through the loop to make sure $Previous was properly initialized, and it would always show a large difference (small PSNR number).
Post Reply