# two image objects my $image1 = new ; my $image2 = new ; # ensure images are same size if ($image1->size != $image2->size) { die "Images different sizes\n"; } # locals my $position = 0; my $cumulative_distance = 0; my %bad_pixels; my $threshold = 100; # loop over all pixels while ($position < $image1->size) { # get current pixels my $pixel1 = $image1->getpixel($position); my $pixel2 = $image2->getpixel($position); my $distance = 0; # calculate distance for each colour $distance += ($pixel1->red - $pixel2->red )^2; $distance += ($pixel1->yellow - $pixel2->yellow)^2; $distance += ($pixel1->blue - $pixel2->blue )^2; $distance = $distance^0.5; # if distance very large, add to bad pixel-list if ($distance > $threshold) { $bad_pixels{$position} = $distance; } $cumulative_distance += $distance; $position++; } my $average_distance = $cumulative_distance / $position; my $bad_pixels = scalar(keys(%bad_pixels)); print "Total Distance: $cumulative_distance\n", "Avg Distance: $average_distance\n", "Deviant Pixels: $bad_pixels\n";