Python图像高级滤波之局部梯度法

2026-01-13 17:32:34

1、打开IDLE:

IDLE是Python shell界面。

Python图像高级滤波之局部梯度法

2、采用工具包:

Python的使用需要导入相关的工具包,这里使用的包如下,如果报错则可能没有安装相关的工具包,

from skimage import data,color

import matplotlib.pyplot as plt

from skimage.morphology import disk

import skimage.filters.rank as sfr

Python图像高级滤波之局部梯度法

3、读取图片:

这里读取一张skimage包内的图片,代码如下。

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

Python图像高级滤波之局部梯度法

4、滤波处理:

采用下面代码对图片进行处理,

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

Python图像高级滤波之局部梯度法

5、显示效果:

可采用下面代码画出我们滤波的效果,

plt.figure('gradient') 

plt.subplot(121) 

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

plt.subplot(122) 

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

plt.show()

Python图像高级滤波之局部梯度法

6、效果如下。

Python图像高级滤波之局部梯度法

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢