我正在使用Python并尝试对图像进行Otsu阈值化,但仅限于遮罩内部(是的,我有一个图像和一个遮罩图像)。这意味着在计算Otsu阈值的直方图中将包含较少的图像像素。在
我目前使用的是cv2.threshold
函数,没有掩码图像,不知道如何完成这种工作。在
ret, OtsuMat = cv2.threshold(GaborMat, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
因为这个函数也包含了遮罩之外的像素,我认为它会给出一个不太精确的阈值。在
以下是图像及其遮罩的示例:
https://drive.google.com/drive/folders/1p8JMhncJs19oOWO9RdkWuEADVGqE-gzQ?usp=sharing
希望有一个OpenCV或其他lib函数可以很容易地完成(也可以使用快速计算),但任何帮助都将不胜感激。在
我尝试过使用skimage中的
threshold_otsu()
方法和Numpy掩码数组。我不知道是否有更快的方法,撇油通常都是非常优化的。如果其他人想取我的样本数据并尝试其他想法,请随时免费-尽管服务费为一票赞成;-)这就给了我们这个:
^{pr2}$
测试数据的直方图如下所示,x轴为0..255
根据您自己的样本数据,我得到:
相关问题 更多 >
编程相关推荐