当前位置:网站首页>OPENCN学习DAY3
OPENCN学习DAY3
2022-07-22 03:09:00 【SKYWALKERS_2397】
阈值操作
ret,dst = cv2.threshold(src,thresh,maxval,type)
src:输入图,只能输入单通道图像,一般使用灰度图
dst:输出图
thresh:阈值
maxval:当像素值超过了阈值(或者小于阈值,根据type来决定),所赋予的值
type:二值化操作的类型,包含以下5中类型:
cv2.THRESH_BINARY:超过阈值部分取maxval(最大值),否则取0
cv2.THRESH_BINARY_INV:cv2.THRESH_BINARY的反转
cv2.THRESH_TRUNC:大于阈值的部分设为阈值,否则不变
cv2.THRESH_TOZERO:大于阈值的部分不变,否则设为0
cv2.THRESH_TOZERO_INV:cv2.THRESH_TOZERO的反转
import cv2
image = cv2.imread('sample.jpg')
img_Gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret1,thresh1 = cv2.threshold(img_Gray, 127, 255, cv2.THRESH_BINARY)
ret2,thresh2 = cv2.threshold(img_Gray, 127, 255, cv2.THRESH_BINARY_INV)
ret3,thresh3 = cv2.threshold(img_Gray, 127, 255, cv2.THRESH_TRUNC)
ret4,thresh4 = cv2.threshold(img_Gray, 127, 255, cv2.THRESH_TOZERO)
ret5,thresh5 = cv2.threshold(img_Gray, 127, 255, cv2.THRESH_TOZERO_INV)
title = ['Original Image', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'THRESH_TOZERO_INV']
images = [image, thresh1,thresh2, thresh3, thresh4, thresh5]
for i in range(6):
cv2.imshow(title[i],images[i])
cv2.waitKey(0)
cv2.destroyAllWindows()
边栏推荐
- C语言题库 part.1
- Nifi 1.16.3 updates and bugs used in production.
- mysql安装失败,不知道什么原因
- Pyside2 as a simple browser
- Creation and call of QT dynamic DLL
- 微服务真的不挑数据库吗?如何选择?
- Cookies and sessions
- Exponential moving average method_ Baidu Encyclopedia
- [medical image segmentation] using deep learning: a survey
- NiFi 1.16.3 生产使用的更新及BUG。
猜你喜欢
信息系统项目管理师必背核心考点(四十八)合同类型的选择
Barcode (bar code)
10个自动化测试框架,测试工程师用起来
Nifi 1.16.3 updates and bugs used in production.
LeetCode高频题:二叉树的锯齿形(Z字形,之字形)层序遍历
查日志只有ES好使?那是你没这样用Clickhouse……
Check for degenerate boxes
【FiddlerTX插件】使用Fiddler抓包腾讯课堂视频下载
C语言动态分配内存
The interview transcript of sister Juan is updated daily, Day1
随机推荐
Code shoe set - mt2201 · sum of all
面试刁钻问题应对思路
Barcode(条形码)
Golang language cli Library
Rotation matrix_ Baidu Encyclopedia
[fiddlertx plug-in] use Fiddler to capture Tencent classroom video download
[06] instruction jump: it turns out that if... Else is goto
小乌龟上传远程仓库
9 good habits improve your happiness
[medical image segmentation] using deep learning: a survey
Leetcode 0128. longest continuous sequence
JS高级 之 ES6 实现继承
EACCES: permission denied, unlink ‘/usr/local/bin/code‘
微信小程序实现PDF预览功能——pdf.js(含源码解析)
Creation and call of QT dynamic DLL
Leetcode high frequency question: zigzag (zigzag, zigzag) sequence traversal of binary tree
JS array object sorting (ES6)
Ubuntu common operation and maintenance commands
LeetCode 0814. 二叉树剪枝
img.shape[-2:]/len(img.shape[-2:]):GeneralizedRCNN:original_image_sizes中的 torch._assert