【问题标题】:An opencv function similar to matlab's graythresh一个类似于matlab的graythresh的opencv函数
【发布时间】:2013-04-17 09:55:51
【问题描述】:

您好,我正在尝试将 matlab 代码转换为 opencv 代码。所以我需要一些可以做 matlab 中的graythesh 的东西,并为我的灰度图像提供一个适当的阈值。这是否已经在 opencv 中实现了,因为我找不到它。

谢谢

【问题讨论】:

  • OpenCV 阈值函数在此处描述:Basic Thresholding Operations
  • 这些是阈值函数,我已经知道了。我想要的是一个计算良好阈值的函数。当然是使用 otsu 的阈值方法。
  • 阈值函数link here有一个类型THRESH_OTSU。否则,有几种实现方式(herethere

标签: matlab opencv


【解决方案1】:

正如@georgesl 所说,将THRESH_OTSU 与其他类型结合起来,例如:

threshold ( grey_image, bin_image, 0, 255, THRESH_BINARY | THRESH_OTSU );

【讨论】:

    【解决方案2】:

    你可以使用 Opencv。为此,使用了 cv.threshold() 函数,其中 cv.THRESH_OTSU 作为额外标志传递。阈值可以任​​意选择。该算法然后找到作为第一个输出返回的最佳阈值。

    import cv2 as cv
    ret2,th2 = cv.threshold(img,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
    #th2 is the thresholded image
    

    来源:https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html

    【讨论】:

      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      相关资源
      最近更新 更多