開始使用免費開始

套用閾值化

在這個練習中,你要判斷用哪一種閾值化方法來將一張包含編織與手作工具的影像二值化。這麼做可以讓你更清楚看出物件的形狀,從紙做的愛心到剪刀都更分明。

Several tools for handcraft art
影像已載入為 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')
編輯並執行程式碼