形态学

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 图像处理

Passons à la pratique !

Python 图像处理

Preparing Video For Download...