#! perl -slw use strict; use Data::Dumper; use List::Util qw[ reduce sum max min ]; use GD; sub check { my $img = GD::Image->new( shift() ); my( $iMin, $iMax, %freq ) = ( 0, 0 ); my( $xMax, $yMax ) = $img->getBounds; for my $y ( 0 .. $yMax - 1 ) { for my $x ( 0 .. $xMax - 1 ) { my $i = reduce{ ($a<<8) + $b;} $img->rgb( $img->getPixel( $x, $y ) ); $freq{ $i }++; $iMin = $iMin < $i ? $iMin : $i; $iMax = $iMax > $i ? $iMax : $i; } } my $count = $xMax * $yMax; my $ex = 16777216 / ( $iMax - $iMin ); my %norm; while( my( $i, $f ) = each %freq ) { $norm{ ( ( $i - $iMin ) * $ex ) / 16777216 } = $f / $count; } return 100 * sum map{ $_ * $norm{ $_ } } keys %norm; } my %sums = map{ check( $_ ), $_ } map glob, @ARGV; printf "%32s : %7.5f\n", $sums{ $_ }, $_ for sort { $a <=> $b } keys %sums; __END__