开始使用免费开始使用

边缘检测

在本练习中,您将通过应用 Sobel 滤波器来检测图像中的边缘。

蓝色背景中心形和矩形状的香皂片
图像已预加载为 soaps_image

show_image() 函数已为您加载。

让我们看看它是否能找到图像中的所有形状。

本练习是课程的一部分

Python 图像处理

查看课程

练习说明

  • 导入 color 模块,以便将图像转换为灰度图。
  • filters 模块导入 sobel() 函数。
  • 使用 color 模块中的合适方法将 soaps_image 转为灰度图。
  • 在得到的灰度图 soaps_image_gray 上应用 Sobel 边缘检测滤波器。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the color module
from ____ import ____

# Import the filters module and sobel function
from skimage.____ import ____

# Make the image grayscale
soaps_image_gray = ____.____(soaps_image)

# Apply edge detection filter
edge_sobel = ____(____)

# Show original and resulting image to compare
show_image(soaps_image, "Original")
show_image(edge_sobel, "Edges with Sobel")
编辑并运行代码