备注
前往结尾 下载完整示例代码。或在 Binder 上通过浏览器运行此示例。
均值滤波器#
此示例比较了排名过滤器包中的以下均值过滤器:
局部均值:属于结构元素的所有像素,用于计算平均灰度级别。
百分位均值:仅使用百分位 p0 和 p1 之间的值(这里为 10% 和 90%)。
双边均值:仅使用结构元素中灰度值位于 g-s0 和 g+s1 之间的像素(此处为 g-500 和 g+500)
百分位数和通常的均值在这里给出了类似的结果,这些滤波器平滑了整个图像(背景和细节)。双边均值对连续区域(即背景)表现出高滤波率,而较高的图像频率保持不变。

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 分钟 0.380 秒)