python-opencv(6):阈值分割

语法格式:

retval,dst=cv2.threshold(src,thresh,maxval,type)

retval,thresh:阈值
maxval:最大值
type:类型
cv2.THRESH_BINARY:二进制阈值化
cv2.THRESH_BINARY_INV:反二进制阈值化
cv2.THRESH_TRUNC:截断阈值化
cv2.THRESH_TOZERO:阈值化为0
cv2.THRESH_TOZERO_INV:反阈值化为0

程序示例:

import cv2
img=cv2.imread("lena.bmp",cv2.IMREAD_UNCHANGED)
retval,result=cv2.threshold(img,128,255,cv2.THRESH_BINARY)
cv2.imshow("lena",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()

结果:

python-opencv(6):阈值分割_第1张图片

你可能感兴趣的:(python-opencv)