import cv2
import matplotlib.pyplot as plt
import numpy as np
'''
ret,dst=cv2.threshold(src,thresh,maxval,type)
src:输入图,只能输入单通道的图像,通常来讲
dst:输出图
thresh:阈值
maxval:当像素值超过了阈值(或者小于阈值,根据type来决定),所赋予的值
type:二值化操作的类型包括以下5种:
cv2.THRESH_BINARY 超过阈值部分取最大值,否则取0
cv2.THRESH_BINARY_INV cv2.THRESH_BINARY的反转 超过阈值部分取最大值,否则取255
cv2.THRESH_TRUNC 大于阈值部分 设置成阈值 ,否则不变
cv2.THRESH_TOZERO 大于与之部分不改变,否则设为0
cv2.THRESH_TOZERO_INV cv2.THRESH_TOZERO 的反转
'''
imge=cv2.imread('Cat.jpg')
imge2=cv2.imread('Cat.jpg',cv2.IMREAD_GRAYSCALE)
thresh1=cv2.threshold(imge2,127,255,cv2.THRESH_BINARY)
thresh2=cv2.threshold(imge2,127,255,cv2.THRESH_BINARY_INV)
thresh3=cv2.threshold(imge2,127,255,cv2.THRESH_TRUNC)
thresh4=cv2.threshold(imge2,127,255,cv2.THRESH_TOZERO )
thresh5=cv2.threshold(imge2,127,255,cv2.THRESH_TOZERO_INV)