[OpenCV4] cv :: adaptiveThreshold() 自适应阈值函数

 

官方文档:参考链接

1.函数原型

2.解释

2.1 头文件

#include <opencv2/imgproc.hpp>

2.2 功能

Applies an adaptive threshold to an array.

对于图片施加自适应阈值操作。

The function transforms a grayscale image to a binary image according to the formulae:

该函数可以将一个灰度图根据下面的公式转换为二值图:

  • THRESH_BINARY

     

  • THRESH_BINARY_INV

     

    where T(x,y) is a threshold calculated individually for each pixel (see adaptiveMethod parameter).
  • T(x,y) 对于每一个像素单独进行计算

The function can process the image in-place.

该函数直接对原图像进行操作。

2.3 参数说明

Parameters

srcSource 8-bit single-channel image.
dstDestination image of the same size and the same type as src.
maxValueNon-zero value assigned to the pixels for which the condition is satisfied
adaptiveMethodAdaptive thresholding algorithm to use, see AdaptiveThresholdTypes. The BORDER_REPLICATE | BORDER_ISOLATED is used to process boundaries.
thresholdTypeThresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV, see ThresholdTypes.
blockSizeSize of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.
CConstant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.

src:8bit单通道输入图像

dst:与src相同大小和类型的输出图像

maxValue:非0值,在满足特定情况的时候被赋值给特定像素

adaptiveMethod:自适应阈值方法,OpenCV给出了两种标准自适应阈值方法:

1.ADAPTIVE_THRESH_MEAN_C (Python: cv.ADAPTIVE_THRESH_MEAN_C)

the threshold value T(x,y) is a mean of the blockSize×blockSize neighborhood of (x,y) minus C

这种阈值是(x, y) 点对应的Block*Block大小的邻域的平局值

 

2.ADAPTIVE_THRESH_GAUSSIAN_C (Python: cv.ADAPTIVE_THRESH_GAUSSIAN_C)

the threshold value T(x,y) is a weighted sum (cross-correlation with a Gaussian window) of the blockSize×blockSize neighborhood of (x,y) minus C . The default sigma (standard deviation) is used for the specified blockSize . See getGaussianKernel

这种阈值是有权重的加权和(在高斯滑窗中的互相关)在像素 (x, y)的blockSize*blockSize的邻域滑窗中每个像素都要-C

默认的sigma值(标准差)被在特定的块大小。计算公式如下:(ksize为kernel size)

sigmaGaussian standard deviation. If it is non-positive, it is computed from ksize as sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8.

thresholdType:阈值类型( THRESH_BINARYTHRESH_BINARY_INV中的一个)

blockSize:用来做自适应kernel的块大小(3,5,7...)

C:最终要从得到的均值或加权均值减去的值,这个值可以是正,0,负

 

2.4 自适应阈值类型

ADAPTIVE_THRESH_MEAN_C 均值

ADAPTIVE_THRESH_GAUSSIAN_C 高斯

 

3.Demo

后面再补

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值