You can use ImageMagick's compare. See PerlMagick page and search for Compare to do it in Perl. In shell, it would go something like
compare -metric mae image.png reference.png difference.png
in Perl, I havn't figured out the right syntax. If you do, please post it.

Update: I found this on Google. The shell compare returns an image with red pixels where the diff's are. Apparently, Compare in PerlMagick just returns some statistics like the following returns:

Errors is 3156.326700 Mean Error is 0.026116

#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $i1 = Image::Magick->new; my $i2 = Image::Magick->new; my $w = $i1->Read('image.png'); # read in images warn("$w") if $w; exit if $w =~ /^Exception/; $w = $i2->Read( 'reference.png'); 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');

UPDATE2: Found a way with the Difference option of Composite, to produce a visual diff.

#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $i1 = Image::Magick->new; my $i2 = Image::Magick->new; #make some test files $i1->Set(size=>'250x100'); $i1->ReadImage('xc:white'); $i1->Draw(primitive=> 'rectangle', fill=>'red', points=>'60,30 110,70'); $i1->Write("i1.png"); #for comparison $i2->Set(size=>'250x100'); $i2->ReadImage('xc:white'); $i2->Draw(primitive=> 'line', fill=>'green', points=>'10,10 200,100'); $i2->Write("i2.png"); #for comparison $i1->Composite( gravity => "Center", compose=>'Difference', image => $i2, ); $i1->Write("$0-diff-compose.png");

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: compare images with perl 5.6 or 5.8 by zentara
in thread compare images with perl 5.6 or 5.8 by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.