Itatsumaki has asked for the wisdom of the Perl Monks concerning the following question:
Howdy all,
There is an open-source program that creates an image sa the output files (this comes from my earlier question about drawing chromosomes. I suggested to the primary developer that perhaps it would be useful to add testing to see if "back-end" changes ended up impacting the final product. He said "go for it". So I'm now, err, trying to do that!
So two basic questions:
So far, this is what I came up with:
In case #2 isn't clear, I would use something like this:
# two image objects my $image1 = new <some image object>; my $image2 = new <some image object>; # 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";
Of course that all requires some image library that lets me walk through pixel-by-pixel and extract the colour values.
Any other (easier?) approaches I could go for? Also, any comments/criticisms of what I've come up with are always appreciated.
-Tats
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching Binary Files
by Zero_Flop (Pilgrim) on Jan 10, 2004 at 22:29 UTC | |
|
Re: Matching Binary Files
by BrowserUk (Patriarch) on Jan 10, 2004 at 20:24 UTC | |
|
Re: Matching Binary Files
by neuroball (Pilgrim) on Jan 10, 2004 at 21:12 UTC | |
|
Re: Matching Binary Files
by zentara (Cardinal) on Jan 11, 2004 at 15:44 UTC |