cv2.threshold()函数的作用是将一幅灰度图二值化,基本用法如下:
#ret:暂时就认为是设定的thresh阈值,mask:二值化的图像
ret,mask = cv2.threshold(img2gray,175,255,cv2.THRESH_BINARY)
plt.imshow(mask,cmap='gray')
上面代码的作用是,将灰度图img2gray中灰度值小于175的点置0,灰度值大于175的点置255
具体用法如下:
threshold(src, thresh, maxval, type[, dst])->ret,dst
src::灰度图
thresh:阈值
maxval:最大值
type:阈值类型
对于最后一个参数,常见的阈值类型有:
THRESH_BINARY=0,
THRESH_BINARY_INV,
THRESH_TRUNC,
THRESH_TOZERO,
THRESH_TOZERO_INV,
THRESH_OTSU,
THRESH_TRIANGLE,
THRESH_MASK