平均值濾波器#

此範例比較排序濾波器套件的以下平均值濾波器

  • 局部平均值:屬於結構元素的所有像素,以計算平均灰度級。

  • 百分位數平均值:僅使用百分位數 p0 和 p1 之間的數值(這裡為 10% 和 90%)。

  • 雙邊平均值:僅使用灰度級位於 g-s0 和 g+s1 內部(這裡為 g-500 和 g+500)的結構元素像素

百分位數和一般的平均值在此處給出相似的結果,這些濾波器會平滑整個影像(背景和細節)。雙邊平均值對於連續區域(即背景)顯示出高濾波率,同時較高的影像頻率保持不變。

Original, Percentile mean, Bilateral mean, Local mean
import matplotlib.pyplot as plt

from skimage import data
from skimage.morphology import disk
from skimage.filters import rank


image = data.coins()
footprint = disk(20)

percentile_result = rank.mean_percentile(image, footprint=footprint, p0=0.1, p1=0.9)
bilateral_result = rank.mean_bilateral(image, footprint=footprint, s0=500, s1=500)
normal_result = rank.mean(image, footprint=footprint)

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 10), sharex=True, sharey=True)
ax = axes.ravel()

titles = ['Original', 'Percentile mean', 'Bilateral mean', 'Local mean']
imgs = [image, percentile_result, bilateral_result, normal_result]
for n in range(0, len(imgs)):
    ax[n].imshow(imgs[n], cmap=plt.cm.gray)
    ax[n].set_title(titles[n])
    ax[n].axis('off')

plt.tight_layout()
plt.show()

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

由 Sphinx-Gallery 產生的圖庫