Zhang-Suen thinning algorithm: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: add entry) |
(→{{header|Perl 6}}: use gather/take rather than push, saves initializing to ()) |
||
Line 350: | Line 350: | ||
repeat while my @goners1 or my @goners2 { |
repeat while my @goners1 or my @goners2 { |
||
@goners1 = @goners2 = (); |
|||
sub cycles (@neighbors) { [+] @neighbors Z< @neighbors[].rotate } |
sub cycles (@neighbors) { [+] @neighbors Z< @neighbors[].rotate } |
||
sub blacks (@neighbors) { [+] @neighbors } |
sub blacks (@neighbors) { [+] @neighbors } |
||
for @has8 -> \p { |
@goners1 = gather for @has8 -> \p { |
||
next unless @black[p]; |
next unless @black[p]; |
||
my \n = @black[p8 X+ p]; |
my \n = @black[p8 X+ p]; |
||
Line 361: | Line 359: | ||
next unless 2 <= blacks(n) <= 6; |
next unless 2 <= blacks(n) <= 6; |
||
next if all n[0,2,4] or all n[2,4,6]; |
next if all n[0,2,4] or all n[2,4,6]; |
||
take p; |
|||
} |
} |
||
@black[@goners1] = 0 xx *; |
@black[@goners1] = 0 xx *; |
||
say "Ping: {[+] @black} remaining after removing ", @goners1 if $DEBUG; |
say "Ping: {[+] @black} remaining after removing ", @goners1 if $DEBUG; |
||
for @has8 -> \p { |
@goners2 = gather for @has8 -> \p { |
||
next unless @black[p]; |
next unless @black[p]; |
||
my \n = @black[p8 X+ p]; |
my \n = @black[p8 X+ p]; |
||
Line 372: | Line 370: | ||
next unless 2 <= blacks(n) <= 6; |
next unless 2 <= blacks(n) <= 6; |
||
next if all n[0,2,6] or all n[0,4,6]; |
next if all n[0,2,6] or all n[0,4,6]; |
||
take p; |
|||
} |
} |
||
@black[@goners2] = 0 xx *; |
@black[@goners2] = 0 xx *; |
||
Line 396: | Line 394: | ||
.........#.........####......... |
.........#.........####......... |
||
................................</pre> |
................................</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Several input images are converted. |
Several input images are converted. |