均值滤波

此示例比较等级过滤器包的以下平均过滤器:

  • 局部平均 :属于结构元素的所有像素,以计算平均灰度级。

  • 百分位数平均值 :仅使用百分位数p0和p1之间的值(此处为10%和90%)。

  • 双边平均数 :仅使用灰度位于g-s0和g+s1内的结构元素的像素(此处为g-500和g+500)

百分位数和通常平均值在这里给出类似的结果,这些过滤器平滑完整的图像(背景和细节)。双边均值对连续区域(即背景)具有较高的滤波率,而较高的图像频率保持不变。

Original, Percentile mean, Bilateral mean, Local mean

输出:

/scikit-image/doc/examples/filters/plot_rank_mean.py:31: FutureWarning:

`selem` is a deprecated argument name for `mean_percentile`. It will be removed in version 1.0. Please use `footprint` instead.

/scikit-image/doc/examples/filters/plot_rank_mean.py:32: FutureWarning:

`selem` is a deprecated argument name for `mean_bilateral`. It will be removed in version 1.0. Please use `footprint` instead.

/scikit-image/doc/examples/filters/plot_rank_mean.py:33: FutureWarning:

`selem` is a deprecated argument name for `mean`. It will be removed in version 1.0. Please use `footprint` instead.

import matplotlib.pyplot as plt

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


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

percentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)
bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)
normal_result = rank.mean(image, selem=selem)

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分0.477秒)

Gallery generated by Sphinx-Gallery