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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 = $im->getPixel($w_piece, $h_piece);
my ($r,$g,$b) = $im->rgb($index);
my $color = int ($r+$g+$b)/3;
push @window, $color
}
}
my $newcolor = (sort @window)[($mask**2+1)/2];
print $newcolor,"\n";
#$im->setPixel($width, $heigth, $colors[$newcolor])
}
}
return $im
}
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 = $im->getPixel($w_piece, $h_piece);
my ($r,$g,$b) = $im->rgb($index);
my $color = int ($r+$g+$b)/3;
push @window, $color
}
}
my $newcolor = (sort @window)[($mask**2+1)/2];
print $newcolor,"\n";
$im->setPixel($width, $heigth, $colors[$newcolor])
}
}
return $im
}