Anonymous user
Zhang-Suen thinning algorithm: Difference between revisions
m
→{{header|Elena}}
Line 982:
=={{header|Elena}}==
ELENA
{{trans|Java}}
<lang elena>import system'collections
import system'routines
import extensions
import extensions'routines
const string[] image =
" ",
" ################# ############# ",
Line 1,007:
" ######## ####### ###### ################ ###### ",
" ######## ####### ###### ############# ###### ",
" "
int[][] nbrs = new int[][]
{
(-1, 1), (-1, 0), (-1, -1), (0, -1)).▼
new int[]{0, -1}, new int[]{1, -1}, new int[]{1, 0}, new int[]{1, 1}, new int[]{0, 1},
};
int[][][] nbrGroups = new int[][][]
extension<Matrix<CharValue>> zhangsuenOp▼
{
new int[][]{new int[]{0, 2, 4}, new int[]{2, 4, 6}},
new int[][]{new int[]{0, 2, 6}, new int[]{0, 4, 6}}
};
{
proceed(r, c, toWhite, firstStep)
if (self[r][c] != $35)
int nn := self
if ((nn < 2) || (nn > 6))
if(self
ifnot (self
toWhite.append(new
^ true
numNeighbors(r,c)
int count := 0
if (self[r + nbrs[i][1]][c + nbrs[i][0]] == $35)
^ count
numTransitions(r,c)
int count := 0
if (self[r + nbrs[i][1]][c + nbrs[i][0]] == $32)
if (self[r + nbrs[i + 1][1]][c + nbrs[i + 1][0]] == $35)
count := count + 1
^ count
atLeastOneIsWhite(r, c, step)
int count := 0
var group := nbrGroups[step]
for(int j := 0, j <
var nbr := nbrs[group[i][j]]
if (self[r + nbr[1]][c + nbr[0]] == $32)
^ false
^ count > 1
thinImage()
bool firstStep := false
bool hasChanged := true
var toWhite :=
while (hasChanged || firstStep)
hasChanged := false
firstStep := firstStep
if(self
toWhite
toWhite
print()
var it := self
it forEach(:ch) [ console print(ch," ") ].▼
[▼
console writeLine.▼
}
public program()
{
Matrix<CharValue> grid :=
{
int
int
= image[i][j]
▲ [
▲ }.
▲ grid thinImage.
grid
console
{{out}}
<pre>
|