关于ret,mask = cv2.threshold(src, dst, thresh, maxval, type) 输入输出参数注释(图像二值化处理)
cv2.threshold()函数的作用是将一幅灰度图二值化,基本用法如下:
ret,mask = cv2.threshold(src, dst, thresh, maxval, type)
plt.imshow(mask,cmap='gray')
输出参数:
(ret,mask)ret: 输入的thresh值。
mask: 处理后的图像。
#The first is the threshold that was used and the second output is the thresholded image.
其中关于输入参数有:
(src, dst, thresh, maxval, type)src: 输入源图像(灰度图)。# The first argument is the source image, which should be a grayscale image.
thresh:阈值,用于对像素值进行分类。# The second argument is the threshold value which is used to classify the pixel values.
maxval:最大值(分配给超过阈值的像素值的最大值)。# The third argument is the maximum value which is assigned to pixel values exceeding the threshold.
type:阈值类型,OpenCV提供了由函数的第四个参数给出的不同类型的阈值。# OpenCV provides different types of thresholding which is given by the fourth parameter of the function.
其中五种type类型如下:
cv.THRESH_BINARY # 小于阈值的像素点置0,大于阈值的像素点置maxval; cv.THRESH_BINARY_INV # 此时小于阈值的像素点置maxval,大于阈值的像素点置0;cv.THRESH_TRUNC # 此时小于阈值的像素点保持原数值,大于阈值的像素点置阈值; cv.THRESH_TOZERO # 此时小于阈值的像素点置0,大于阈值的像素点保持原数值; cv.THRESH_TOZERO_INV # 此时小于阈值的像素点保持原数值,大于阈值的像素点置0。
关于不同的type阈值类型的测试代码:
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('gradient.png',0)
ret,thresh1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
ret,thresh2 = cv.threshold(img,127,255,cv.THRESH_BINARY_INV)
ret,thresh3 = cv.threshold(img,127,255,cv.THRESH_TRUNC)
ret,thresh4 = cv.threshold(img,127,255,cv.THRESH_TOZERO)
ret,thresh5 = cv.threshold(img,127,255,cv.THRESH_TOZERO_INV)
titles = ['Original Image','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',vmin=0,vmax=255)plt.title(titles[i])plt.xticks([]),plt.yticks([])
plt.show()
输出结果是;
参考网址:https://docs.opencv.org/3.4/d7/d4d/tutorial_py_thresholding.html
关于ret,mask = cv2.threshold(src, dst, thresh, maxval, type) 输入输出参数注释(图像二值化处理)相关推荐
- opencv 二值化 matlab,opencv-python图像二值化函数cv2.threshold函数详解及参数cv2.THRESH...
cv2.threshold()函数的作用是将一幅灰度图二值化,基本用法如下: #ret:暂时就认为是设定的thresh阈值,mask:二值化的图像 ret,mask = cv2.threshold(i ...
- opencv 二值化 python_opencv-python图像二值化函数cv2.threshold函数详解及参数cv2.THRESH_OTSU使用...
cv2.threshold()函数的作用是将一幅灰度图二值化,基本用法如下: #ret:暂时就认为是设定的thresh阈值,mask:二值化的图像 ret,mask = cv2.threshold(i ...
- 图像二值化 cv2.threshold
图像二值化 cv2.threshold http://docs.opencv.org/master/d7/d4d/tutorial_py_thresholding.html (一)简单阈值 impor ...
- OpenCV-Python学习(10)—— OpenCV 图像二值化处理(cv.threshold)
1. 学习目标 理解图像的分类,不同类型的图像的区别: 对图像进行二值化处理,对[ cv.threshold ]函数的理解. 2. 图像分类 2.1 不同类型图像说明 按照颜色对图像进行分类,可以分为 ...
- [转载] python3 opencv 图像二值化笔记(cv2.adaptiveThreshold)
参考链接: python opencv 基础6: cv2.threshold()二值图像 前一篇研究了opencv二值化方法threshold的使用,但是这个方法也存在一定的局限性,假如有一张图存在明 ...
- python3 opencv 图像二值化笔记(cv2.adaptiveThreshold)
前一篇研究了opencv二值化方法threshold的使用,但是这个方法也存在一定的局限性,假如有一张图存在明显的明暗不同的区域,如下图 可以看到左边部分因为整体偏暗,导致二值化后变成全黑,丢失了所有 ...
- Opencv java 二值化函数threshold (10)
函数理解 threshold 英语的意思是门槛,门槛的意思说要么在门槛外,要么在门槛内,并且门槛具有一定的条件要求 接下来我们看在opencv中如何使用该函数 Imgproc.threshold(sr ...
- OpenCV二值化--cv2.threshold()函数、cv2.adaptiveThreshold()函数
@[toc] 目录 1.cv2.threshold()函数 2.cv2.adaptiveThreshold()函数 3.3.什么时候用cv2.adaptiveThreshold()函数 一.cv2.t ...
- python-opencv-cv2.threshold()二值化函数详解
文章目录 1.cv2.threshold()参数说明 2.代码示例 1.cv2.threshold()参数说明 cv2.threshold(src, thresh, maxval, type[, ds ...
最新文章
- 二叉树:路径之和 Path Sum
- VS2005中ajax安装指南[转]
- Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
- new,delete总结
- 如何恢复ORACLE数据(冷备份)
- Everything的下载
- 学习笔记~~~~LinkedHashMap
- 带你了解数据库的“吸尘器”:VACUUM
- php 反射类 解析注释,php反射获取类和方法中的注释
- 计算机组成原理—存储系统总结
- [Mac OS] Homebrew简介及安装wine
- 我的世界服务器修改金币上限,我的世界联机盒子修改金币方法
- fdfs-文件上传信息返回详情
- 组策略 禁止用户策略下发到指定计算机,使用组策略禁止域中计算机安装特定设备...
- 六种正确清理C盘的方法,解决你的红色烦恼
- 多通道国产源表之VCSEL老化测试
- 【数据增强】用cv2旋转图像并自定义填充背景颜色(主要用到cv2.getRotationMatrix2D 和 cv2.warpAffine)
- 免费的PDF在线合并工具,拿走不谢!
- 中国工业互联网行业发展预测及行业趋势调研报告2022-2028年版
- 强大好用的图片编辑效果实现,支持涂鸦、编辑、马赛克,可撤销和恢复