应用阈值分割
在本练习中,您将判断使用哪种阈值分割方式来二值化一张编织与手工工具的图像。完成后,您将能更清晰地看到物体的形状,从纸质爱心到剪刀等。
图像已加载为
tools_image。
根据图像的特征,您会使用哪种阈值分割?背景的光照与强度是均匀还是不均匀?
本练习是课程的一部分
Python 图像处理
练习说明
- 导入合适的阈值分割函数和
rgb2gray()。 - 将图像转换为灰度图。
- 获取最优阈值。
- 应用阈值分割,得到二值图像。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import threshold and gray convertor functions
from skimage.____ import ____
from skimage.color import ____
# Turn the image grayscale
gray_tools_image = ____
# Obtain the optimal thresh
thresh = ____(gray_tools_image)
# Obtain the binary image by applying thresholding
binary_image = gray_tools_image > ____
# Show the resulting binary image
show_image(binary_image, 'Binarized image')