当背景并不明显时
有时,背景并不容易识别。如果图像背景比较均匀,您可以像之前练习的那样使用 threshold_otsu() 进行全局阈值分割。另一方面,如果背景光照不均,使用自适应阈值 threshold_local()(也称局部阈值)通常能得到更好的结果。
在本练习中,您将比较这两种阈值方法(全局与局部),以找到获取所需二值图像的最佳方式。
图像已加载为
page_image。
本练习是课程的一部分
Python 图像处理
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the otsu threshold function
from skimage.____ import ____
# Obtain the optimal otsu global thresh value
global_thresh = ____(page_image)
# Obtain the binary image by applying global thresholding
binary_global = page_image ____ ____
# Show the binary image obtained
show_image(binary_global, 'Global thresholding')