Anonymous user
Zhang-Suen thinning algorithm: Difference between revisions
m
→{{header|Elena}}
m (changed table to be not so compacted, added other whitespace.) |
|||
Line 982:
=={{header|Elena}}==
ELENA 3.
{{trans|Java}}
<lang elena>import system'collections.
Line 988:
import extensions.
import extensions'routines.
const image = (
" ",
Line 1,010 ⟶ 1,008:
" ######## ####### ###### ############# ###### ",
" ").
nbrs = ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1),
(-1, 1), (-1, 0), (-1, -1), (0, -1)).
nbrGroups = (((0, 2, 4), (2, 4, 6)), ((0, 2, 6),
(0, 4, 6))).
{
[
if (self[r][c] != $35)
[ ^ false ].
int nn := self numNeighbors(r,c).
if ((nn < 2) || (nn > 6))
[ ^ false ].
if(self numTransitions(r,c) != 1)
[ ^ false ].
ifnot (self atLeastOneIsWhite(r,c,firstStep iif(0,1)))
[ ^ false ].
toWhite append:{ x = c. y = r. }.
^ true.
]
numNeighbors
[
int count := 0.
0 till(nbrs length - 1) do(:i)
[
Line 1,049 ⟶ 1,047:
[ count := count + 1. ].
].
^ count.
]
numTransitions
[
int count := 0.
0 till(nbrs length - 1) do(:i)
[
Line 1,067 ⟶ 1,065:
].
].
^ count.
]
atLeastOneIsWhite
[
int count := 0.
Line 1,080 ⟶ 1,078:
[
var nbr := nbrs[group[i][j]].
if (self[r + nbr[1]][c + nbr[0]] == $32)
[ count := count + 1. ^ true ].
^ false.
].
].
^ count > 1.
]
thinImage
[
Line 1,096 ⟶ 1,094:
bool hasChanged := true.
var toWhite := List new.
while (hasChanged || firstStep)
[
hasChanged := false.
firstStep := firstStep
1 till(self rows - 1) do(:r)
[
1 till(self columns - 1) do(:c)
[
if(self~zhangsuenOp
[ hasChanged := true ].
].
].
toWhite forEach(:p)[ self[p y][p x] := $32. ].
toWhite clear.
].
]
print
[
var it := self enumerator.
it forEach(:ch) [ console print(ch," ") ].
while (it next)
[
console writeLine.
it forEach(:ch) [ console print(ch," ") ].
].
]
}
[
{
int rows = image length.
int columns = image[0] length.
getAt
= image[i][j].
setAt(int i, int j, object o)
▲ [
▲ ]
}.
grid thinImage.
grid print.
console readChar
]
{{out}}
<pre>
|