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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

Python利用flask sqlalchemy实现分页效果

Python利用flask sqlalchemy实现分页效果

Flask-sqlalchemy是关于flask一个针对数据库管理的。文中我们采用一个关于员工显示例子。 首先,我们创建SQLALCHEMY对像db。 from flask impo...

Python学习笔记之常用函数及说明

基本定制型 复制代码 代码如下:C.__init__(self[, arg1, ...]) 构造器(带一些可选的参数)C.__new__(self[, arg1, ...]) 构造器(带...

python中requests和https使用简单示例

requests 是一个非常小巧全面的库,应用它可以很容易写出与服务器进行交互的程序,今天遇到了一个问题,与服务器交互时,url都是https开头的,都进行了ssl加密处理,这样一来,就...

wxPython学习之主框架实例

wxPython学习之主框架实例

本文实例讲述了wxPython主框架的简单用法,分享给大家供大家参考。具体如下: 程序代码如下: import wx class MyApp(wx.App): def O...

Python实现线程池代码分享

原理:建立一个任务队列,然多个线程都从这个任务队列中取出任务然后执行,当然任务队列要加锁,详细请看代码 import threading import time import sig...