二值化的cv2 threshold函数
发布时间:2020-12-14 05:18:43 所属栏目:大数据 来源:网络整理
导读:像素高于阈值时,给像素赋予新值,否则,赋予另外一种颜色。函数是cv2.threshold()? cv2.threshold(src,thresh,maxval,type[,dst])-retval,dst? 作用:用于获取二元值的灰度图像? thresh:阈值,maxval:在二元阈值THRESH_BINARY和逆二元阈值THRESH_BINARY_INV
像素高于阈值时,给像素赋予新值,否则,赋予另外一种颜色。函数是cv2.threshold()?
cv2.threshold(src,thresh,maxval,type[,dst])->retval,dst? 作用:用于获取二元值的灰度图像? thresh:阈值,maxval:在二元阈值THRESH_BINARY和逆二元阈值THRESH_BINARY_INV中使用的最大值? 返回值retval其实就是阈值? type:使用的阈值类型? 例子: ? #python 3.5.3 蔡军生
#http://edu.csdn.net/course/detail/2592
#
import cv2
import matplotlib.pyplot as plt
img = cv2.imread(‘test1.jpg‘,0) #直接读为灰度图像
#二值化
ret,thresh1 = cv2.threshold(img,1,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,cv2.THRESH_TOZERO_INV)
titles = [‘img‘,‘BINARY‘,‘BINARY_INV‘,‘TRUNC‘,‘TOZERO‘,‘TOZERO_INV‘]
images = [img,thresh1,thresh2,thresh3,thresh4,thresh5]
for i in range(6):
plt.subplot(2,3,i+1),plt.imshow(images[i],‘gray‘)
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
输出结果: 可见使用这个函数可以获取轮廓图案。 ? 1.?TensorFlow入门基本教程?
http://edu.csdn.net/course/detail/4369
2. C++标准模板库从入门到精通??
?
?
?
http://edu.csdn.net/course/detail/3324
3.跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
4. 跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
5. 在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
6. 在Windows下SVN的版本管理与实战??http://edu.csdn.net/course/detail/25797.Visual Studio 2015开发C++程序的基本使用?http://edu.csdn.net/course/detail/25708.在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
9.在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
?
?
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |