sub median my mask shift for my heigth size-1 for my width size-1 my w

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
sub median {
my $mask = shift;
for my $heigth (0 .. $size-1) {
for my $width (0 .. $size-1) {
my $window;
for my $h_piece ($heigth-($mask-(int $mask/2)-1) .. $heigth+($mask-(int $mask/2)-1)) {
for my $w_piece ($width-($mask-(int $mask/2)-1) .. $width+($mask-(int $mask/2)-1)) {
my ($index, $color, $r, $g, $b);
if ($h_piece > -1 and $w_piece > -1) {
$index = $im->getPixel($w_piece, $h_piece);
($r,$g,$b) = $im->rgb($index);
$window += int ($r+$g+$b)/3
}
}
}
$im->setPixel($width, $heigth, $colors[$window/$mask**2])
}
}
return $im
}