Jump to content

Zhang-Suen thinning algorithm: Difference between revisions

→‎{{header|Perl 6}}: use gather/take rather than push, saves initializing to ()
(→‎{{header|Perl 6}}: use gather/take rather than push, saves initializing to ())
Line 350:
 
repeat while my @goners1 or my @goners2 {
@goners1 = @goners2 = ();
 
sub cycles (@neighbors) { [+] @neighbors Z< @neighbors[].rotate }
sub blacks (@neighbors) { [+] @neighbors }
 
@goners1 = gather for @has8 -> \p {
next unless @black[p];
my \n = @black[p8 X+ p];
Line 361 ⟶ 359:
next unless 2 <= blacks(n) <= 6;
next if all n[0,2,4] or all n[2,4,6];
@goners1.push:take p;
}
@black[@goners1] = 0 xx *;
say "Ping: {[+] @black} remaining after removing ", @goners1 if $DEBUG;
 
@goners2 = gather for @has8 -> \p {
next unless @black[p];
my \n = @black[p8 X+ p];
Line 372 ⟶ 370:
next unless 2 <= blacks(n) <= 6;
next if all n[0,2,6] or all n[0,4,6];
@goners2.push:take p;
}
@black[@goners2] = 0 xx *;
Line 396 ⟶ 394:
.........#.........####.........
................................</pre>
 
=={{header|Python}}==
Several input images are converted.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.