滤波
1:中值滤波:median=cv2.medianBlur(img,5)//5代表的是5×5为一个处理单位,中值滤波能够把所有噪音点一下子消除掉
2:均值滤波blur=cv2.blur(img,(3,3))
3:方框滤波,基本和中值滤波一样,可以选择归一化
box=cv2.boxfilter(img,-1,(3,3),nomarlize=True)
4:高斯滤波aussian=cv2.GaussianBlur(img,(5,5),1)
图像阈值
1:简单阈值,如果像素点小于阈值,则设置为0,否则将其设置为最大值,第一个参数为源图像,第二个图像为阈值,第三个参数是分配给超过阈值的像素值的最大值,简单阈值类型有cv.THRESH_BINARY
cv.THRESH_BINARY_INV
cv.THRESH_TRUNC
cv.THRESH_TOZERO
cv.THRESH_TOZERO_INV
exp:
ret,thresh1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
ret,thresh2 = cv.threshold(img,127,255,cv.THRESH_BINARY_INV)
ret,thresh3 = cv.threshold(img,127,255,cv.THRESH_TRUNC)
ret,thresh4 = cv.threshold(img,127,255,cv.THRESH_TOZERO)
ret,thresh5 = cv.threshold(img,127,255,cv.THRESH_TOZERO_INV)
2:自适应阈值,但这可能并非在所有情况下都很好,例