Zhang-Suen thinning algorithm: Difference between revisions
m
→{{header|Sidef}}: updated code
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: works again after adding a 'flat', set of parens) |
m (→{{header|Sidef}}: updated code) |
||
Line 2,605:
const CIRCULARS = (NEIGHBOURS + [NEIGHBOURS.first]) # P2, ... P9, P2
has r = 0
has image = [[]]
method init {
var s1 = str.lines.map{|line| line.chars.map{|c| c==black ? 1 : 0 }}
var s2 = s1.len.of { s1[0].len.of(0) }
var xr =
var yr =
do {
r = 0
xr.each{|x| yr.each{|y| s2[x][y] = (s1[x][y] - self.zs(s1,x,y,1)) }} # Step 1
xr.each{|x| yr.each{|y| s1[x][y] = (s2[x][y] - self.zs(s2,x,y,0)) }} # Step 2
} while !r.is_zero
image = s1
}
Line 2,625:
|| (ng[x-1][y] + ng[x][y+1] + ng[x+g][y+g - 1] == 3) ->
|| (ng[x+g - 1][y+g] + ng[x+1][y] + ng[x][y-1] == 3) ->
&& return 0
var bp1 = NEIGHBOURS.map {|p| ng[x+p[0]][y+p[1]] }.sum
return 0 if ((bp1 < 2) || (6 < bp1))
var ap1 = 0
CIRCULARS.map {|p| ng[x+p[0]][y+p[1]] }.each_cons(2, {|
++ap1 if (
})
return 0 if (ap1 != 1)
r = 1
}
|