Python图像处理模块ndimage用法实例分析

yipeiwu_com5年前Python基础

本文实例讲述了Python图像处理模块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程序设计有所帮助。

相关文章

使用selenium模拟登录解决滑块验证问题的实现

使用selenium模拟登录解决滑块验证问题的实现

本次主要是使用selenium模拟登录网页端的TX新闻,本来最开始是模拟请求的,但是某一天突然发现,部分账号需要经过滑块验证才能正常登录,如果还是模拟请求,需要的参数太多了,找的心累。不...

Python日期的加减等操作的示例

本文介绍了Python日期的加减等操作的示例,分享给大家,也给自己留个笔记 1. 日期输出格式化 所有日期、时间的api都在datetime模块内。 1. datetime =>...

Django使用Mysql数据库已经存在的数据表方法

使用scrapy爬取了网上的一些数据,存储在了mysql数据库中,想使用Django将数据展示出来,在网上看到都是使用Django的models和makemigration,migrat...

Python timer定时器两种常用方法解析

这篇文章主要介绍了Python timer定时器两种常用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 方法一,使用线程中现成...

Python3利用SMTP协议发送E-mail电子邮件的方法

Python3利用SMTP协议发送E-mail电子邮件的方法

前言 本文主要给大家介绍了关于Python3用SMTP协议发送电子邮件的相关内容,在介绍如何使用python程序向指定邮箱发送邮件之前,我们需要先介绍一下有关电子邮件的相关知识。 Ema...