開始使用免費開始

邊緣偵測

在這個練習中,你將套用 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")
編輯並執行程式碼