嗨,我正在尝试将 matlab 代码转换为 opencv 代码。所以我需要一些能graythesh
在 matlab 中做的事情,并为我的灰度图像提供一个适当的阈值。这是否已经在 opencv 中实现了,因为我找不到它。
谢谢
正如@georgesl 提到的,结合THRESH_OTSU
其他类型,例如:
threshold ( grey_image, bin_image, 0, 255, THRESH_BINARY | THRESH_OTSU );
您可以使用 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