Zhang-Suen thinning algorithm: Difference between revisions

Content added Content deleted
Line 962: Line 962:
<lang Mathematica>nB[mat_] := Delete[mat // Flatten, 5] // Total;
<lang Mathematica>nB[mat_] := Delete[mat // Flatten, 5] // Total;


nA[mat_] := Module[{l, ct = 0, f},
nA[mat_] := Module[{l},
f[a_, b_] := If[a == 0 && b == 1, ct++; b, b];
l = Flatten[mat][[{2, 3, 6, 9, 8, 7, 4, 1, 2}]];
l = Flatten[mat][[{2, 3, 6, 9, 8, 7, 4, 1, 2}]];
Fold[f, l[[1]], l[[2 ;;]]];
Total[Map[If[#[[1]] == 0 && #[[2]] == 1, 1, 0] &,
Partition[l, 2, 1]]]
ct];
];


iW1[mat_] :=
iW1[mat_] :=