学习笔记(15):Python+OpenCV计算机视觉-threshold函数
程序员文章站
2024-03-25 08:22:52
...
立即学习:https://edu.csdn.net/course/play/10552/234930?utm_source=blogtoedu
图像阈值(threshold实现)
函数threshold
retval,dst = cv2.threshold(src,thresh,maxval,type)
retval 阈值 dst 处理结果
src 原图像 threshhold 阈值
maxval 最大值 type 类型
import cv2
import numpy as np
a = cv2.imread('111.jpg',cv2.IMREAD_GRAYSCALE)
r,b = cv2.threshold(a,128,255,cv2.THRESH_BINARY)
r,c = cv2.threshold(a,128,255,cv2.THRESH_BINARY_INV)
r,d = cv2.threshold(a,128,255,cv2.THRESH_TOZERO)
r,e = cv2.threshold(a,128,255,cv2.THRESH_TOZERO_INV)
r,f = cv2.threshold(a,128,255,cv2.THRESH_TRUNC)
print(a)
cv2.imshow('a',a)
cv2.imshow('b',b)
cv2.imshow('c',c)
cv2.imshow('d',d)
cv2.imshow('e',e)
cv2.imshow('f',f)
cv2.waitKey(0)
cv2.destroyAllWindows()