问题描述
如何清除图像上的线条并确保图像不失真? 1st picture
解决方法
这个目的和去噪没有单一的解决方案,但是你可以使用下面两个参数,虽然由于线条和图像的颜色很难完全去除。
# apply morphology close and open to make mask
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(10,10))
morph = cv2.morphologyEx(thresh,cv2.MORPH_CLOSE,kernel,iterations=1)
mask = cv2.morphologyEx(morph,cv2.MORPH_OPEN,iterations=1)
然后:
# do OTSU threshold
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
otsu = cv2.threshold(gray,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]