形態學

Python 影像處理

Rebeca Gonzalez

Data Engineer

二值影像

Python 影像處理

形態學濾波

  • 更適用於二值影像
  • 可延伸至灰階

Python 影像處理

形態學運算

  • 膨脹
  • 侵蝕

Python 影像處理

結構元素

Python 影像處理

結構元素

Python 影像處理

scikit-image 的形狀

from skimage import morphology

square = morphology.square(4)
[[1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]]
rectangle = morphology.rectangle(4, 2)
[[1 1]
 [1 1]
 [1 1]
 [1 1]]
Python 影像處理

在 scikit-image 中做侵蝕

from skimage import morphology

# 設定長方形結構元素 selem = rectangle(12,6)
# 使用二值侵蝕取得侵蝕後影像 eroded_image = morphology.binary_erosion(image_horse, selem=selem)
Python 影像處理

在 scikit-image 中做侵蝕

# 顯示結果
plot_comparison(image_horse, eroded_image, 'Erosion')

Python 影像處理

使用預設結構元素的二值侵蝕

# 使用預設結構元素的二值侵蝕
eroded_image = morphology.binary_erosion(image_horse)

Python 影像處理

在 scikit-image 中做膨脹

from skimage import morphology

# 以二值膨脹取得膨脹後影像
dilated_image = morphology.binary_dilation(image_horse)

# 檢視結果 plot_comparison(image_horse, dilated_image, 'Erosion')
Python 影像處理

在 scikit-image 中做膨脹

Python 影像處理

一起來練習吧!

Python 影像處理

Preparing Video For Download...