Zhang-Suen thinning algorithm: Difference between revisions

m (→‎{{header|Kotlin}}: Added attribution)
Line 418:
 
=={{header|Elena}}==
ELENA 3.2 :
{{trans|Java}}
<lang elena>#import system'collections.
#import system'routines.
#import extensions.
#import extensions'routines.
 
#subjecttype charmatrix = matrixof(char)matrix<CharValue>.
 
const image = (
Line 452 ⟶ 453:
(0, 4, 6))).
 
extension(charmatrix) extension zhangsuenOp
{
$proceed : r : c : toWhite : firstStep
[
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.
Line 479 ⟶ 480:
int count := 0.
0 till:(nbrs length - 1) &doEach:do(:i)
[
if (self@([r + nbrs@[i@][1)@(]][c + nbrs@[i@][0)]] == #$35)
[ count := count + 1. ].
].
Line 492 ⟶ 493:
int count := 0.
0 till:(nbrs length - 1) &doEach:do(:i)
[
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.
Line 509 ⟶ 510:
[
int count := 0.
var group := nbrGroups@[step].
0 till:2 &doEach:do(:i)
[
0 till:(group@[i] length) &seekEach:seek(:j)
[
var nbr := nbrs@([group@[i@][j)]].
if (self@([r + nbr@[1)@(]][c + nbr@[0)]] == #$32)
[ count := count + 1. ^ true. ].
^ false.
Line 537 ⟶ 538:
firstStep := firstStep not.
 
1 till:(self rows - 1) &doEach:do(:r)
[
1 till:(self columns - 1) &doEach:do(:c)
[
if (self~zhangsuenOp $proceed:(r:,c:,toWhite:,firstStep))
[ hasChanged := true ].
].
].
toWhite run &each:forEach(:p)[ self@([p y)@(][p x)] := #$32. ].
toWhite clear.
].
Line 555 ⟶ 556:
var it := self enumerator.
it run &each:forEach(:ch) [ console writeLiteral:print(ch:," ".) ].
while (it next)
[
console writeLine.
it run &each:forEach(:ch) [ console writeLiteral:print(ch:," ".) ].
].
]
Line 567 ⟶ 568:
program =
[
charmatrix grid := MatrixSpace::
{
rows = image length.
columns = image@[0] length.
getAt &int:i &int:j
= image@[i@][j].
}.
 
Anonymous user