首页 > 解决方案 > Scikit 图像 otsu 阈值处理产生零阈值

问题描述

我正在对图像进行一些预处理,在图像上应用Otsu 阈值处理后,我的阈值为零,而在另一个图像上它工作正常

from skimage import filters
from skimage.io import imread

img = imread(img_path, as_gray=True)

threshold = filters.threshold_otsu(img)
print(threshold)

HS-1-G-01.tif 在此处输入图像描述

阈值:0

original_1_1.png 在此处输入图像描述

门槛:204

标签: pythonimage-processingscikit-imageimage-thresholding

解决方案


那是正确的结果。您的图像是双层的,它只有 0 和 255 的值,所以 0 是一个阈值,当您执行下一步时,它将正确地将图像分成两个值:

threshold = filters.threshold_otsu(img)
binary = im > threshold

用一些虚拟的“图像”自己尝试一下:

filters.threshold_otsu(np.array([0,255],dtype=np.uint8))
0

filters.threshold_otsu(np.array([7,12],dtype=np.uint8)) 
7

filters.threshold_otsu(np.array([7,8,11,12],dtype=np.uint8))
8

推荐阅读