Scikit 图像 otsu 阈值产生零阈值

Scikit image otsu thresholding producing zero threshold

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

from skimage import filters
from skimage.io import imread

img = imread(img_path, as_gray=True)

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

H-S-1-G-01.tif

阈值:0

original_1_1.png

阈值:204

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

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

用一些假人自己试试 "images":

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