当前位置:   article > 正文

scikit-image 中用于图像分割的阈值算法(2)

scikit-image 中用于图像分割的阈值算法(2)

plt.show()

threshold_otsu(gray_image) 函数根据 Otsu二值化算法返回阈值。之后,使用此值构建二进制图像( dtype= bool ),最后应将其转换为 8 位无符号整数格式( dtype=uint8 )以进行可视化,使用img_as_ubyte() 函数完成转换过程。

程序输出如下图所示:

使用 scikit-image 进行阈值处理

接下来,介绍下如何使用 scikit-image 中的一些其它阈值技术。

scikit-image 中的其他阈值技术


接下来,将对比 OtsutriangleNiblackSauvola 阈值技术进行阈值处理的不同效果。 Otsutriangle 是全局阈值技术,而 NiblackSauvola 是局部阈值技术。当背景不均匀时,局部阈值技术则是更好的方法阈值处理方法。

同样的,第一步是导入所需的包:

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 对比执行阈值操作:

Otsu

thr

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号