官方文档:参考链接
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
src | Source 8-bit single-channel image. |
dst | Destination image of the same size and the same type as src. |
maxValue | Non-zero value assigned to the pixels for which the condition is satisfied |
adaptiveMethod | Adaptive thresholding algorithm to use, see AdaptiveThresholdTypes. The BORDER_REPLICATE | BORDER_ISOLATED is used to process boundaries. |
thresholdType | Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV, see ThresholdTypes. |
blockSize | Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on. |
C | Constant 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)
sigma | Gaussian 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_BINARY和THRESH_BINARY_INV中的一个)
blockSize:用来做自适应kernel的块大小(3,5,7...)
C:最终要从得到的均值或加权均值减去的值,这个值可以是正,0,负
2.4 自适应阈值类型
ADAPTIVE_THRESH_MEAN_C 均值
ADAPTIVE_THRESH_GAUSSIAN_C 高斯
3.Demo
后面再补