赞
踩
plt.show()
threshold_otsu(gray_image)
函数根据 Otsu
的二值化算法返回阈值。之后,使用此值构建二进制图像( dtype= bool
),最后应将其转换为 8 位无符号整数格式( dtype=uint8
)以进行可视化,使用img_as_ubyte()
函数完成转换过程。
程序输出如下图所示:
接下来,介绍下如何使用 scikit-image
中的一些其它阈值技术。
接下来,将对比 Otsu
、triangle
、Niblack
和 Sauvola
阈值技术进行阈值处理的不同效果。 Otsu
和 triangle
是全局阈值技术,而 Niblack
和 Sauvola
是局部阈值技术。当背景不均匀时,局部阈值技术则是更好的方法阈值处理方法。
同样的,第一步是导入所需的包:
from skimage.filters import threshold_otsu, threshold_triangle, threshold_niblack, threshold_sauvola
from skimage import img_as_ubyte
import cv2
import matplotlib.pyplot as plt
调用每个阈值方法( threshold_otsu()
、threshold_niblack()
、threshold_sauvola()
和 threshold_triangle()
),以使用 scikit-image
对比执行阈值操作:
thr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。