python数字图像处理(10):图像简单滤波
对图像进行滤波,可以有两种效果:一种是平滑滤波,用来抑制噪声;另一种是微分算子,可以用来检测边缘和特征提取。
skimage库中通过filters模块进行滤波操作。
1、sobel算子
sobel算子可用来检测边缘
函数格式为:skimage.filters.sobel(image, mask=None)
from skimage import data,filters
import matplotlib.pyplot as plt
img = data.camera()
edges = filters.sobel(img)
plt.imshow(edges,plt.cm.gray)

2、roberts算子
roberts算子和sobel算子一样,用于检测边缘
调用格式也是一样的:
edges = filters.roberts(img)
3、scharr算子
功能同sobel,调用格式:
edges = filters.scharr(img)
4、prewitt算子
功能同sobel,调用格式:
edges = filters.prewitt(img)
5、canny算子
canny算子也是用于提取边缘特征,但它不是放在filters模块,而是放在feature模块
函数格式:skimage.feature.canny(image,sigma=1.0)
可以修改sigma的值来调整效果
from skimage import data,filters,feature
import matplotlib.pyplot as plt
img = data.camera()
edges1 = feature.canny(img) #sigma=1
edges2 = feature.canny(img,sigma=3) #sigma=3 plt.figure('canny',figsize=(8,8))
plt.subplot(121)
plt.imshow(edges1,plt.cm.gray) plt.subplot(122)
plt.imshow(edges2,plt.cm.gray) plt.show()

从结果可以看出,sigma越小,边缘线条越细小。
6、gabor滤波
gabor滤波可用来进行边缘检测和纹理特征提取。
函数调用格式:skimage.filters.gabor_filter(image, frequency)
通过修改frequency值来调整滤波效果,返回一对边缘结果,一个是用真实滤波核的滤波结果,一个是想象的滤波核的滤波结果。
from skimage import data,filters
import matplotlib.pyplot as plt
img = data.camera()
filt_real, filt_imag = filters.gabor_filter(img,frequency=0.6) plt.figure('gabor',figsize=(8,8)) plt.subplot(121)
plt.title('filt_real')
plt.imshow(filt_real,plt.cm.gray) plt.subplot(122)
plt.title('filt-imag')
plt.imshow(filt_imag,plt.cm.gray) plt.show()

以上为frequency=0.6的结果图。

以上为frequency=0.1的结果图
7、gaussian滤波
多维的滤波器,是一种平滑滤波,可以消除高斯噪声。
调用函数为:skimage.filters.gaussian_filter(image, sigma)
通过调节sigma的值来调整滤波效果
from skimage import data,filters
import matplotlib.pyplot as plt
img = data.astronaut()
edges1 = filters.gaussian_filter(img,sigma=0.4) #sigma=0.4
edges2 = filters.gaussian_filter(img,sigma=5) #sigma=5 plt.figure('gaussian',figsize=(8,8))
plt.subplot(121)
plt.imshow(edges1,plt.cm.gray) plt.subplot(122)
plt.imshow(edges2,plt.cm.gray) plt.show()

可见sigma越大,过滤后的图像越模糊
8.median
中值滤波,一种平滑滤波,可以消除噪声。
需要用skimage.morphology模块来设置滤波器的形状。
from skimage import data,filters
import matplotlib.pyplot as plt
from skimage.morphology import disk
img = data.camera()
edges1 = filters.median(img,disk(5))
edges2= filters.median(img,disk(9)) plt.figure('median',figsize=(8,8)) plt.subplot(121)
plt.imshow(edges1,plt.cm.gray) plt.subplot(122)
plt.imshow(edges2,plt.cm.gray) plt.show()

从结果可以看出,滤波器越大,图像越模糊。
9、水平、垂直边缘检测
上边所举的例子都是进行全部边缘检测,有些时候我们只需要检测水平边缘,或垂直边缘,就可用下面的方法。
水平边缘检测:sobel_h, prewitt_h, scharr_h
垂直边缘检测: sobel_v, prewitt_v, scharr_v
from skimage import data,filters
import matplotlib.pyplot as plt
img = data.camera()
edges1 = filters.sobel_h(img)
edges2 = filters.sobel_v(img) plt.figure('sobel_v_h',figsize=(8,8)) plt.subplot(121)
plt.imshow(edges1,plt.cm.gray) plt.subplot(122)
plt.imshow(edges2,plt.cm.gray) plt.show()

上边左图为检测出的水平边缘,右图为检测出的垂直边缘。
10、交叉边缘检测
可使用Roberts的十字交叉核来进行过滤,以达到检测交叉边缘的目的。这些交叉边缘实际上是梯度在某个方向上的一个分量。
其中一个核:
0 1
-1 0
对应的函数:
roberts_neg_diag(image)
例:
from skimage import data,filters
import matplotlib.pyplot as plt
img =data.camera()
dst =filters.roberts_neg_diag(img) plt.figure('filters',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray) plt.subplot(122)
plt.title('filted image')
plt.imshow(dst,plt.cm.gray)

另外一个核:
1 0
0 -1
对应函数为:
roberts_pos_diag(image)
from skimage import data,filters
import matplotlib.pyplot as plt
img =data.camera()
dst =filters.roberts_pos_diag(img) plt.figure('filters',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray) plt.subplot(122)
plt.title('filted image')
plt.imshow(dst,plt.cm.gray)

python数字图像处理(10):图像简单滤波的更多相关文章
- python数字图像处理(四) 频率域滤波
import matplotlib.pyplot as plt import numpy as np import cv2 %matplotlib inline 首先读入这次需要使用的图像 img = ...
- python数字图像处理(17):边缘与轮廓
在前面的python数字图像处理(10):图像简单滤波 中,我们已经讲解了很多算子用来检测边缘,其中用得最多的canny算子边缘检测. 本篇我们讲解一些其它方法来检测轮廓. 1.查找轮廓(find_c ...
- 「转」python数字图像处理(18):高级形态学处理
python数字图像处理(18):高级形态学处理 形态学处理,除了最基本的膨胀.腐蚀.开/闭运算.黑/白帽处理外,还有一些更高级的运用,如凸包,连通区域标记,删除小块区域等. 1.凸包 凸包是指一 ...
- Win8 Metro(C#) 数字图像处理--1 图像打开,保存
原文:Win8 Metro(C#) 数字图像处理--1 图像打开,保存 作为本专栏的第一篇,必不可少的需要介绍一下图像的打开与保存,一便大家后面DEMO的制作. Win8Metro编程中,图像相关 ...
- Win8 Metro(C#)数字图像处理--2.56简单统计法图像二值化
原文:Win8 Metro(C#)数字图像处理--2.56简单统计法图像二值化 [函数名称] 简单统计法图像二值化 WriteableBitmap StatisticalThSegment(Wr ...
- python数字图像处理(1):环境安装与配置
一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...
- 初始----python数字图像处理--:环境安装与配置
一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...
- Win8 Metro(C#)数字图像处理--4图像颜色空间描述
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述 图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
- python数字图像处理(五) 图像的退化和复原
import cv2 import numpy as np import matplotlib.pyplot as plt import scipy import scipy.stats %matpl ...
随机推荐
- IOS开发中返回值为null时的处理
在IOS开发中,如果得到了null返回值很容易造成程序崩溃,null和nil的判断方法不同. nil的判断方法: if(data==nil) { NSLog(@"data is n ...
- Monyer's game Google Hack关的BT玩法
玩Monyer's game的朋友都知道里面有Google Hack这关,其实这里本来应该用到的技术是逆向回溯搜索,但因为有好几个人都说利用其他方式看到的密码,所以Monyer不得不重新站在玩家的角度 ...
- Ubuntu 环境 运行Asp.net mvc +EntityFramework+ Mysql
关键词:ubuntu,mono,.Net framework 4.5,asp.net mvc 4,Entityframework 6,Mysql Mono安装 参考文章: Install Mono o ...
- PS网页设计教程XXVII——设计一个大胆和充满活力的作品集
作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...
- SpringMVC 返回 html 视图页面,SpringMVC与Servlet,Servlet重定向与转发
1. SpringMVC与Servlet的关系 SpringMVC框架是建立在Servlet之上的,提供各种功能,各种封装,各种方便的同时,它一点儿也没有限制Servlet,我们完全可以在Spring ...
- 【mysql】使用脚本对mysql状态进行监控
1.mysqladmin 使用mysqladmin extended-status命令可以获得所有MySQL性能指标,即show global status的输出,不过,因为多数这些指标都是累计值,如 ...
- 【mysql】添加对emoji的支持
1.简介 涉及无线相关的 MySQL 数据库建议都提前采用 utf8mb4 字符集,避免 emoji 表情符号带来的问题 MySQL Server > 5.5.3 2.配置+升级 当前配置 m ...
- PHPDBG
一.简介 PHPDBG的是一个轻量级.强大.易用的PHP调试平台.可以在PHP5.4和之上版本中使用.在php5.6和之上版本将内部集成. 二.安装 PHP源码下载 http://php.net/gi ...
- Linux 下从头再走 GTK+-3.0 (六)
在 GTK3 中增加了一个 GtkApplicaton 类,便于我们处理多窗口程序,同时有了 GtkApplication 我们也更容易创建灵活,易用,界面美观的应用程序. 在前面的几个例子中,演示了 ...
- 转载:HttpClient使用详解
原文地址:http://blog.csdn.net/wangpeng047/article/details/19624529 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自 ...