使用頂帽濾波器移除灰階影像中的小物體#

此範例顯示如何從灰階影像中移除小物體。頂帽變換 [1] 是一種從給定影像中提取小元素和細節的操作。這裡我們使用白色頂帽變換,其定義為輸入影像與其(數學形態學)開啟之間的差異。

Original, White tophat, Complementary
import matplotlib.pyplot as plt

from skimage import data
from skimage import color, morphology

image = color.rgb2gray(data.hubble_deep_field())[:500, :500]

footprint = morphology.disk(1)
res = morphology.white_tophat(image, footprint)

fig, ax = plt.subplots(ncols=3, figsize=(20, 8))
ax[0].set_title('Original')
ax[0].imshow(image, cmap='gray')
ax[1].set_title('White tophat')
ax[1].imshow(res, cmap='gray')
ax[2].set_title('Complementary')
ax[2].imshow(image - res, cmap='gray')

plt.show()

腳本的總執行時間: (0 分鐘 0.849 秒)

由 Sphinx-Gallery 產生