简体   繁体   English

Scikit 图像 otsu 阈值处理产生零阈值

[英]Scikit image otsu thresholding producing zero threshold

I am doing some preprocessing on an image, After applying Otsu thresholding on the image I am getting zero threshold while on another image it's working fine我正在对图像进行一些预处理,在图像上应用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 HS-1-G-01.tif 在此处输入图像描述

Threshold : 0阈值:0

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

Threshold : 204门槛:204

That is the correct result.那是正确的结果。 Your image is bi-level, it only has values of 0 and 255, so 0 is a threshold that will split the image into two values correctly when you do the next step:您的图像是双层的,它只有 0 和 255 的值,所以 0 是一个阈值,当您执行下一步时,它将正确地将图像分成两个值:

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

Try it for yourself with some dummy "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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM