始める無料で始める

エッジ検出

この演習では、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")
コードを編集して実行