繁体   English   中英

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

[英]How can I Remove dotted Noise from Image preserving the dots?

我有一张图片,背景中有很多点状噪声。 我尝试了很多过滤器(中值,高斯),但没有任何效果。 由于这些噪音,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)

这是图片的一部分在此处输入图片说明

你可以试试这个:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM