python - 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)
阈值:0
门槛:204
解决方案
那是正确的结果。您的图像是双层的,它只有 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
推荐阅读
- data-structures - 哪个是更好的循环与真正的方程
- python-3.x - 从现有句子中提取特定单词
- rust - 如何有效地找到 Rust 中 u64 整数的 2 的下一个幂?
- matlab - 从 .mat 文件中的结构中提取数据
- sql - 有没有办法在 SPARK-SQL 中获得这个解决方案,我们需要在记录分组后应用过滤器?
- upgrade - SAP Commerce/Hybris 升级多个版本
- django - 如何使用 django 制作高度可扩展的聊天应用程序?
- c# - C# Telerik winforms radDropDownList 多选
- python - 如何使 python matplotlib 栏从低数字而不是高数字开始?
- javascript - 更改处理程序以避免单击两次要求 - React