我试图找到一种方法来打破已经自适应阈值化的扫描文档中的文本行.现在,我存储文档为无符号的整数0到255的像素值,并且这是我在像素的平均值中的每一行,以及我基于像素值的平均值是否是线分割成的范围大于250,然后我取每个范围的线的中位数.但是,这种方法有时会失败,因为图像上可能会出现黑色斑点.
是否有更加抗噪的方式来完成这项任务?
编辑:这是一些代码."扭曲"是原始图像的名称,"剪切"是我想要分割图像的地方.
warped = threshold_adaptive(warped, 250, offset = 10)
warped = warped.astype("uint8") * 255
# get areas where we can split image on whitespace to make OCR more accurate
color_level = np.array([np.sum(line) / len(line) for line in warped])
cuts = []
i = 0
while(i < len(color_level)):
if color_level[i] > 250:
begin = i
while(color_level[i] > 250):
i += 1
cuts.append((i + begin)/2) # middle of the whitespace region
else:
i += 1
Run Code Online (Sandbox Code Playgroud)