Zhang-Suen thinning algorithm: Difference between revisions
Content added Content deleted
m (→{{header|Kotlin}}: Added attribution) |
|||
Line 418: | Line 418: | ||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 3.2 : |
|||
{{trans|Java}} |
{{trans|Java}} |
||
<lang elena> |
<lang elena>import system'collections. |
||
import system'routines. |
|||
import extensions. |
|||
import extensions'routines. |
|||
type charmatrix = matrix<CharValue>. |
|||
const image = ( |
const image = ( |
||
Line 452: | Line 453: | ||
(0, 4, 6))). |
(0, 4, 6))). |
||
charmatrix extension zhangsuenOp |
|||
{ |
{ |
||
$proceed : r : c : toWhite : firstStep |
$proceed : r : c : toWhite : firstStep |
||
[ |
[ |
||
if (self |
if (self[r][c] != $35) |
||
[ ^ false ]. |
[ ^ false ]. |
||
int nn := self numNeighbors |
int nn := self numNeighbors(r,c). |
||
if ((nn < 2) || (nn > 6)) |
if ((nn < 2) || (nn > 6)) |
||
[ ^ false ]. |
[ ^ false ]. |
||
if(self numTransitions |
if(self numTransitions(r,c) != 1) |
||
[ ^ false ]. |
[ ^ false ]. |
||
ifnot (self atLeastOneIsWhite |
ifnot (self atLeastOneIsWhite(r,c,firstStep iif(0,1))) |
||
[ ^ false ]. |
[ ^ false ]. |
||
toWhite |
toWhite append:{ x = c. y = r. }. |
||
^ true. |
^ true. |
||
Line 479: | Line 480: | ||
int count := 0. |
int count := 0. |
||
0 till |
0 till(nbrs length - 1) do(:i) |
||
[ |
[ |
||
if (self |
if (self[r + nbrs[i][1]][c + nbrs[i][0]] == $35) |
||
[ count := count + 1. ]. |
[ count := count + 1. ]. |
||
]. |
]. |
||
Line 492: | Line 493: | ||
int count := 0. |
int count := 0. |
||
0 till |
0 till(nbrs length - 1) do(:i) |
||
[ |
[ |
||
if (self |
if (self[r + nbrs[i][1]][c + nbrs[i][0]] == $32) |
||
[ |
[ |
||
if (self |
if (self[r + nbrs[i + 1][1]][c + nbrs[i + 1][0]] == $35) |
||
[ |
[ |
||
count := count + 1. |
count := count + 1. |
||
Line 509: | Line 510: | ||
[ |
[ |
||
int count := 0. |
int count := 0. |
||
var group := nbrGroups |
var group := nbrGroups[step]. |
||
0 till:2 |
0 till:2 do(:i) |
||
[ |
[ |
||
0 till |
0 till(group[i] length) seek(:j) |
||
[ |
[ |
||
var nbr := nbrs |
var nbr := nbrs[group[i][j]]. |
||
if (self |
if (self[r + nbr[1]][c + nbr[0]] == $32) |
||
[ count := count + 1. ^ true |
[ count := count + 1. ^ true ]. |
||
^ false. |
^ false. |
||
Line 537: | Line 538: | ||
firstStep := firstStep not. |
firstStep := firstStep not. |
||
1 till |
1 till(self rows - 1) do(:r) |
||
[ |
[ |
||
1 till |
1 till(self columns - 1) do(:c) |
||
[ |
[ |
||
if |
if(self~zhangsuenOp $proceed(r,c,toWhite,firstStep)) |
||
[ hasChanged := true ]. |
[ hasChanged := true ]. |
||
]. |
]. |
||
]. |
]. |
||
toWhite |
toWhite forEach(:p)[ self[p y][p x] := $32. ]. |
||
toWhite clear. |
toWhite clear. |
||
]. |
]. |
||
Line 555: | Line 556: | ||
var it := self enumerator. |
var it := self enumerator. |
||
it |
it forEach(:ch) [ console print(ch," ") ]. |
||
while (it next) |
while (it next) |
||
[ |
[ |
||
console writeLine. |
console writeLine. |
||
it |
it forEach(:ch) [ console print(ch," ") ]. |
||
]. |
]. |
||
] |
] |
||
Line 567: | Line 568: | ||
program = |
program = |
||
[ |
[ |
||
charmatrix grid := MatrixSpace |
charmatrix grid := MatrixSpace:: |
||
{ |
{ |
||
rows = image length. |
rows = image length. |
||
columns = image |
columns = image[0] length. |
||
getAt |
getAt int:i int:j |
||
= image |
= image[i][j]. |
||
}. |
}. |
||