从 opencv 中的阈值文本图像中去除噪声

Win*_*ier 0 python opencv computer-vision

我有这些图像: 在此输入图像描述

我想在所有这些图像中去除背景中的噪声(即使第一个和第三个背景为白色,第二个为黑色),我尝试了这种方法:Removenoisefromthresholdimageopencvpython但它不起作用,怎么办我做吗?

PS 这是我试图增强的原始图像。 在此输入图像描述

fmw*_*w42 5

您可以在 Python/OpenCV 中对原始图像使用自适应阈值

输入:

在此输入图像描述

import cv2
import numpy as np

# read image
img = cv2.imread("writing.jpg")

# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# do adaptive threshold on gray image
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 10)

# write results to disk
cv2.imwrite("writing_thresh.jpg", thresh)

# display it
cv2.imshow("thresh", thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
结果:

在此输入图像描述