如何从opencv中的图像中去除噪声?
How to remove noise from an image in opencv?
如何在opencv中去除图像中的噪声(见输入图片)?我想在输出中实现这一点,我将只获得白色背景和黑色文本。
假设灰度图像,你可以像这样部分消除噪声:
# thresholding
thresh, thresh_img = cv.threshold(img, 128, 255, 0, cv.THRESH_BINARY)
# erode the image to *enlarge* black blobs
erode = cv.erode(thresh_img, cv.getStructuringElement(cv.MORPH_ELLIPSE, (3,3)))
# fill in the black blobs that are not surrounded by white:
_, filled, _, _ = cv.floodFill(erode, None, (0,0), 255)
# binary and with the threshold image to get rid of the thickness from erode
out = (filled==0) & (thresh_img==0)
# also
# out = cv.bitwise_and(filled, thresh_img)
输出不干净(文本行之间有一些黑色斑点,可以通过对连通分量的大小设置阈值来进一步去除),但这应该是一个好的开始:
如何在opencv中去除图像中的噪声(见输入图片)?我想在输出中实现这一点,我将只获得白色背景和黑色文本。
假设灰度图像,你可以像这样部分消除噪声:
# thresholding
thresh, thresh_img = cv.threshold(img, 128, 255, 0, cv.THRESH_BINARY)
# erode the image to *enlarge* black blobs
erode = cv.erode(thresh_img, cv.getStructuringElement(cv.MORPH_ELLIPSE, (3,3)))
# fill in the black blobs that are not surrounded by white:
_, filled, _, _ = cv.floodFill(erode, None, (0,0), 255)
# binary and with the threshold image to get rid of the thickness from erode
out = (filled==0) & (thresh_img==0)
# also
# out = cv.bitwise_and(filled, thresh_img)
输出不干净(文本行之间有一些黑色斑点,可以通过对连通分量的大小设置阈值来进一步去除),但这应该是一个好的开始: