---
title: "图像处理模块ndimage"
author: "cakin24"
date: "2017-08-04T23:36:36Z"
tags: []
categories: ["编程语言"]
slug: "ndimage"
draft: false
lastmod: "2017-08-04T23:36:36Z"
id: 2388390
url: "https://cakin24.iteye.com/blog/2388390"
---

**一 原始图像** 

1 代码

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

2 运行结果

![](http://dl2.iteye.com/upload/attachment/0126/4169/44f078b1-df7a-3ede-a7ad-6a1495e4709a.png)  
 

 

**二 高斯滤波**

1 代码

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

2 运行结果

![](http://dl2.iteye.com/upload/attachment/0126/4171/244b9c8c-a97b-3e64-94f0-9635abada7e4.png)  
 

 

**三 边缘锐化处理**

1代码

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

2运行结果

![](http://dl2.iteye.com/upload/attachment/0126/4173/aca13b33-838b-3725-9aee-dc7d487b582a.png)  
 

 

**四 中值滤波** 

1 代码

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

2 运行结果

![](http://dl2.iteye.com/upload/attachment/0126/4175/364db0ac-1b29-397e-9c03-59b091d8bc34.png)