Python图像高级滤波之均值滤波

时间:2026-02-15 10:53:53

1、打开idle界面:

Python图像高级滤波之均值滤波

2、导入库:

代码如下,如果报错,可能是没有安装相关的库文件

from skimage import data,color

import matplotlib.pyplot as plt

from skimage.morphology import disk

import skimage.filters.rank as sfr

Python图像高级滤波之均值滤波

3、读取图片:

读取自己要处理的图片,并且将其进行灰度化处理,代码如下。

img=color.rgb2gray(data.astronaut())

4、均值滤波:

采用以下语句对图片进行均值滤波。

dst =sfr.mean(img, disk(5))

Python图像高级滤波之均值滤波

5、查看滤波结果:

采用以下代码人进行画图显示查看效果。

plt.figure('filters',figsize=(8,8)) 

plt.subplot(121) 

plt.title('origin image') 

plt.imshow(img,plt.cm.gray) 

plt.subplot(122) 

plt.title('filted image') 

plt.imshow(dst,plt.cm.gray)

plt.show()

Python图像高级滤波之均值滤波

6、效果。

Python图像高级滤波之均值滤波

© 2026 一点知道
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com