opencv3.0 函数学习 6——threshold 二值化

本文介绍了OpenCV 3.0中的threshold函数,用于全局二值化处理图像。该函数根据设定的阈值T,将图像分为两部分,大于T的像素设为白色,小于T的设为黑色。参数包括输入图像、输出图像、阈值和最大值。此外,还提到了可选择的Otsu's和Triangle算法,它们能自动计算最优阈值,特别是适用于8位图像。Otsu's方法基于最大类间方差,而Triangle算法的资料较少。
摘要由CSDN通过智能技术生成

threshold 全局二值化

一幅图像包括目标物体、背景还有噪声,要想从多值的数字图像中直接提取出目标物体,最常用的方法就是设定一个全局的阈值T,用T将图像的数据分成两部分:大于T的像素群和小于T的像素群。将大于T的像素群的像素值设定为白色(或者黑色),小于T的像素群的像素值设定为黑色(或者白色)。


函数参数

double threshold( InputArray src, OutputArray dst,
                               double thresh, double maxval, int type );  (  项目中自己设置 maxval默认的值为255,thresh由用户调节)

double cv::threshold ( InputArray  src,
    OutputArray  dst,
    double  thresh,      (需调节)
    double  maxval,    (定义为255)
    int  type            (需要调节)
  )    

Applies a fixed-level threshold to each array element.

The function applies fixed-level thresholding to a single-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image (cv::compare could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several types of thresholding supported by the function. They are determined by type parameter.

Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the above values. In these cases, the function determines the optimal threshold value using the Otsu's or Triangle algorithm and uses it instead of the specified thresh . The function returns the computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit images.

Parameters
src input array (single-channel, 8-bit or 32-bit floating point).
dst output array of the same size and type as src.
thresh threshold value.
maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.
type thresholding type (see the cv::ThresholdTypes).



enum cv::ThresholdTypes

type of the threshold operation

threshold.png
threshold types
Enumerator
THRESH_BINARY 

dst(x,y)={ maxval
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值