def GetLineSegments(itrim):
"""
Segment an image in lines and interline spaces
Returns lists of both (position width)
"""
# sum along pixel lines
asum = np.sum(itrim, axis=1)
abin = asum > 0
sp = []
tx = []
lastval=-1
lastpos=-1
for i in range(0, abin.size):
if abin[i] != lastval:
lastval = abin[i]
if lastval:
tx.append(np.array((i,0)))
if i>0:
sp[-1][1] = i-sp[-1][0]
else:
sp.append(np.array((i,0)))
if i>0:
tx[-1][1] = i-tx[-1][0]
# set the last segment lenght
if tx[-1][1] == 0: tx[-1][1] = itrim.shape[0] - tx[-1][0]
if sp==[]:# empy if there is just one line in the image
sp.append(np.array((0,0)))
else:
if sp[-1][1] == 0: sp[-1][1] = itrim.shape[0] - sp[-1][0]
return tx, sp
docompare.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录