Python scipy.ndimage 图像处理实战:高斯、锐化与中值滤波

林见深
林见深
发布时间:2026-10-13| 6人浏览过
原创

本文通过 Python 的 scipy.ndimage 模块演示图像处理方法。内容涵盖原始图像显示、高斯滤波(sigma=7)实现模糊效果、结合 sigma=1 和 sigma=3 的高斯滤波进行边缘锐化(系数6),以及使用窗口大小7的中值滤波去除噪声。所有示例均基于 misc.face 测试图像,提供完整代码与运行结果参考。

Python scipy.ndimage 图像处理实战:高斯、锐化与中值滤波

本文详细介绍 Python 中 scipy.ndimage 模块的具体应用方法,旨在为读者提供实用的图像处理参考案例。

原始图像展示

一、原始图像展示

1. 实现代码


from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
face = misc.face()#face是测试图像之一
plt.figure()#创建图形
plt.imshow(face)#绘制测试图像
plt.show()#原始图像

2. 程序运行结果

高斯滤波处理

二、高斯滤波处理

1. 实现代码


from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
face = misc.face()#face是测试图像之一
plt.figure()#创建图形
blurred_face = ndimage.gaussian_filter(face, sigma=7)#高斯滤波
plt.imshow(blurred_face)
plt.show()

2. 程序运行结果

边缘锐化处理

三、边缘锐化处理

1. 实现代码


from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
face = misc.face()#face是测试图像之一
plt.figure()#创建图形
blurred_face1 = ndimage.gaussian_filter(face, sigma=1)#边缘锐化
blurred_face3 = ndimage.gaussian_filter(face, sigma=3)
sharp_face = blurred_face3 +6*(blurred_face3-blurred_face1)
plt.imshow(sharp_face)
plt.show()

2. 程序运行结果

中值滤波处理

四、中值滤波处理

1. 实现代码


from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
face = misc.face()#face是测试图像之一
plt.figure()#创建图形
median_face = ndimage.median_filter(face,7)#中值滤波
plt.imshow(median_face)
plt.show()

2. 程序运行结果

如需了解更多 Python 相关技术,可参考本站专题:《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》。

希望上述关于 Python 程序设计的内容能对读者有所帮助。

相关标签:

免责声明:本文内容仅供参考,不代表本站观点。转载或引用请注明出处。

Python 相关产品和应用

全部下载
Selenium

Selenium

4.51.0 · Windows

用于浏览器自动化和 Web 测试的 Python 工具。

scikit-learn

scikit-learn

1.9.1 · Windows

常用 Python 机器学习算法与模型评估工具库。

Black

Black

26.10.1 · Windows

强调一致性的 Python 自动代码格式化工具。

Ruff

Ruff

0.17.1 · macOS

由 Rust 编写的高速 Python 代码检查和格式化工具。

pytest

pytest

9.1.1 · Windows

简洁而强大的 Python 自动化测试框架。

FastAPI

FastAPI

0.146.0 · Windows

高性能 Python API 框架,支持类型提示和自动接口文档。

Flask

Flask

3.1.3 · Windows

轻量灵活的 Python Web 应用框架。

Django

Django

6.1.2 · Windows

成熟的 Python Web 框架,适合构建内容站点和业务系统。

Spyder

Spyder

6.1.7 · Windows

面向科学计算与数据分析的 Python 集成开发环境。

SciPy

SciPy

1.18.1 · Windows

面向科学、工程和技术计算的 Python 算法库。