一共有5个方法
• cv2.THRESH_BINARY(超过阈值部分取最大值, 如超过了阈值127变为255)
• cv2.THRESH_BINARY_INV(反转上面的,可以理解为上面的颜色反转)
• cv2.THRESH_TRUNC (截断,大于阈值部分设置阈值,比如大于127的就设置为127)
• cv2.THRESH_TOZERO (大于阈值部分保持不变,小于等于阈值的全为0)
• cv2.THRESH_TOZERO_INV(反转上面的,小于阈值不变,大于等于阈值为0)
ret,thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(gray,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO_INV)
from matplotlib import pyplot as plt
#thresh1在上面
titles = ['BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [thresh1, thresh2, thresh3, thresh4, thresh5]
for i in range(5):
plt.subplot(2, 3, i+1)
plt.imshow(images[i])
plt.title(titles[i])
plt.show()
滤波:
#均值滤波 对一个3*3的像素颜色进行平均化
img=cv2.blur(img,(3,3))
#方框滤波 和均值滤波基本一样,-1是固定写法(颜色通道),normalize是处理像素颜色加起来不会越界 #不做处理的话 越界大于255就会用255来处理
img2=cv2.boxFilter(img,-1,(3,3),normalize=True)
#高斯滤波的卷积核里的数值是满足高斯分布,相当于更重视中间的
img3=cv2.GaussianBlur(img,(3,3),1)
# cv_show(img3)
#中值滤波 取3*3范围内的中间数
img4=cv2.medianBlur(img,3)
好没意思啊。难顶哦
好没意思啊。难顶哦