如何从保留点的图像中去除点状噪点?

时间:2019-12-13 13:03:42

标签: python tesseract

我有一幅在背景中有很多点状噪点的图像。我尝试了很多过滤器(中值,高斯),但没有解决。由于这些噪音,Tesseract缺少很多文本 然后,我尝试查找所有连接组件,然后通过小于50的区域。但是它也删除了有效的十进制数字。

_, blackAndWhite = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV)
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(blackAndWhite, None, None, None, 8, cv2.CV_32S)
sizes = stats[1:, -1] #get CC_STAT_AREA component
img2 = np.zeros((labels.shape), np.uint8)

for i in range(0, nlabels - 1):
    if sizes[i] >= 50:   #filter small dotted regions
        img2[labels == i + 1] = 255
res = cv2.bitwise_not(img2)

这是图片enter image description here

的一部分

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:-1)

您可以尝试以下方法:

import cv2
import numpy as np

img = cv2.imread('path_image', 0)
blackAndWhite = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)

nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(blackAndWhite, None, None, None, 8, cv2.CV_32S)
sizes = stats[1:, -1] 
img2 = np.zeros((labels.shape), np.uint8)

for i in range(0, nlabels - 1):
    if sizes[i] >= 50:   #filter small dotted regions
        img2[labels == i + 1] = 255

res = cv2.bitwise_not(img2)

cv2.imwrite('res.png', res)