【问题标题】:Adaptive Threshold parameters confusion自适应阈值参数混淆
【发布时间】:2015-02-27 10:56:59
【问题描述】:

谁能告诉我这些自适应阈值函数中的参数是什么以及它们如何控制黑白像素。

cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
            cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,11,2)

【问题讨论】:

标签: python opencv


【解决方案1】:
Python: cv2.adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C[, dst]) → dst

参数:

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. See the details below.
adaptiveMethod – Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C . See the details below.
thresholdType – Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .
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.

取自here:,它还更详细地解释了该方法。

【讨论】:

【解决方案2】:

添加到 GPPK 的答案。

函数根据公式将灰度图像转换为二值图像:

  • THRESH_BINARY

  • THRESH_BINARY_INV

其中 T(x,y) 是为每个像素单独计算的阈值。

  • 对于 ADAPTIVE_THRESH_MEAN_C 方法,阈值 T(x,y) 是 (x, y) 的 blockSize x blockSize 邻域减去 C 的平均值。
  • 对于 ADAPTIVE_THRESH_GAUSSIAN_C 方法,阈值 T(x, y) 是 (x, y) 的 blockSize x blockSize 邻域减去 C 的加权和(与高斯窗口的互相关)。默认的 sigma(标准差)用于指定的 blockSize。

【讨论】:

    猜你喜欢
    • 2017-02-15
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    相关资源
    最近更新 更多