1、打开IDLE:IDLE的界面如下。
2、导入工具包:导入我们需要用到的库,代码如下,如果报错可能没有安装相应的工具包。from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfr
3、读取图片:读取我们要处理的图片,并进行灰度化处理,这里读取skimage库中的图片。img=color.rgb2gray(data.camera())
4、最小值滤波:采用下面代码实现最小值滤波。dst =sfr.minimum(img, disk(5))
5、查看效果:plt.figure('filters')plt.subplot(121)plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.imshow(dst,plt.cm.gray)plt.show()
6、效果对比: