数学之路-python计算实战(17)-机器视觉-滤波去噪(中值滤波)
Blurs an image using the median filter.
- C++: void medianBlur(InputArray src, OutputArray dst, int ksize)
highlight=smooth#void medianBlur(InputArray src, OutputArray dst, int ksize)" title="Permalink to this definition" style="color: rgb(101, 161, 54); text-decoration: none; visibility: hidden; font-size: 0.8em; padding: 0px 4px;">
- Python: cv2.medianBlur(src, ksize[, dst]) → dst
highlight=smooth#cv2.medianBlur" title="Permalink to this definition" style="color: rgb(101, 161, 54); text-decoration: none; visibility: hidden; font-size: 0.8em; padding: 0px 4px;">
-
Parameters: - src – input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.
- dst – destination array of the same size and type as src.
- ksize – aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
The function smoothes an image using the median filter with the
aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.
中值滤波将图像的每一个像素用邻域 (以当前像素为中心的正方形区域)像素的 中值 取代 。
与邻域平均法相似,但计算的是中值
本博客全部内容是原创,假设转载请注明来源
http://blog.csdn.net/myhaspl/
#用中值法
for y in xrange(1,myh-1):
for x in xrange(1,myw-1):
lbimg[y,x]=np.median(tmpimg[y-1:y+2,x-1:x+2]
以下是调用opencv 的函数
# -*- coding: utf-8 -*-
#code:myhaspl@myhaspl.com
#中值滤波
import cv2
import numpy as np
fn="test3.jpg"
myimg=cv2.imread(fn)
img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY) #加上椒盐噪声
#灰阶范围
w=img.shape[1]
h=img.shape[0]
newimg=np.array(img)
#噪声点数量
noisecount=50000
for k in xrange(0,noisecount):
xi=int(np.random.uniform(0,newimg.shape[1]))
xj=int(np.random.uniform(0,newimg.shape[0]))
newimg[xj,xi]=255 #滤波去噪
lbimg=cv2.medianBlur(newimg,3)
cv2.imshow('src',newimg)
cv2.imshow('dst',lbimg)
cv2.waitKey()
cv2.destroyAllWindows()
中值滤波忽略了较高阶灰度和较低阶灰度,直接取中值,由于有效得过滤椒盐噪声
对高斯噪声的滤波
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbXloYXNwbA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
数学之路-python计算实战(17)-机器视觉-滤波去噪(中值滤波)的更多相关文章
- 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
# -*- coding: utf-8 -*- #code:myhaspl@myhaspl.com #归一化块滤波 import cv2 import numpy as np fn="tes ...
- 数学之路-python计算实战(21)-机器视觉-拉普拉斯线性滤波
拉普拉斯线性滤波,.边缘检測 . When ksize == 1 , the Laplacian is computed by filtering the image with the follow ...
- 数学之路-python计算实战(20)-机器视觉-拉普拉斯算子卷积滤波
拉普拉斯算子进行二维卷积计算,线性锐化滤波 # -*- coding: utf-8 -*- #线性锐化滤波-拉普拉斯算子进行二维卷积计算 #code:myhaspl@myhaspl.com impor ...
- 数学之路-python计算实战(14)-机器视觉-图像增强(直方图均衡化)
我们来看一个灰度图像,让表示灰度出现的次数,这样图像中灰度为 的像素的出现概率是 是图像中全部的灰度数, 是图像中全部的像素数, 实际上是图像的直方图,归一化到 . 把 作为相应于 的累计概率 ...
- 数学之路-python计算实战(19)-机器视觉-卷积滤波
filter2D Convolves an image with the kernel. C++: void filter2D(InputArray src, OutputArray dst, int ...
- 数学之路-python计算实战(9)-机器视觉-图像插值仿射
插值 Python: cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dst interpolation – interpol ...
- 数学之路-python计算实战(13)-机器视觉-图像增强
指数变换的基本表达式为:y=bc(x-a)-1 当中參数b.c控制曲线的变换形状,參数a控制曲线的位置. 指数变换的作用是扩展图像的高灰度级.压缩低灰度级.能够用于亮度过高的图像 本博客全部内容是原创 ...
- 数学之路-python计算实战(16)-机器视觉-滤波去噪(邻域平均法滤波)
# -*- coding: utf-8 -*- #code:myhaspl@myhaspl.com #邻域平均法滤波,半径为2 import cv2 import numpy as np fn=&qu ...
- 数学之路-python计算实战(18)-机器视觉-滤波去噪(双边滤波与高斯滤波 )
高斯滤波就是对整幅图像进行加权平均的过程.每个像素点的值,都由其本身和邻域内的其它像素值经过加权平均后得到.高斯滤波的详细操作是:用一个模板(或称卷积.掩模)扫描图像中的每个像素.用模板确定的邻域内像 ...
随机推荐
- 如何创建C# Closure?
JavaScript中一个重要的概念就是闭包,闭包在JavaScript中有大量的应用,但是你知道么?C#也可以创建Closure.下面就介绍一下如何在C#中创建神奇的闭包. 在这之前,我们必须先知道 ...
- Windows Server 2008不能Ping改为允许的方法
用了Windows Server 2008朋友肯定都知道,2008在很多设置方面与2003不同,尤其在安全上进行了加强,例如:默认情况下Windows 2008是不允许PING的,那么如何打开允许PI ...
- 关于联想笔记本不能连接无线网(wifi),注销后重新登录才可以连接
解决联想笔记本wifi问题(果果) 最近很多使用联想的朋友都遇到了这样一个问题,那就是笔记本的wifi突然不能用了,好吧,其实我个人也遇到了这个问题,但是网上貌似对这个问题并没有给出一个可以解决的办法 ...
- Redis 注册为 widows 服务
redis-server.exe --service-install redis.windows.conf --loglevel verbose
- R语言学习 - 热图简化
绘制热图除了使用ggplot2,还可以有其它的包或函数,比如pheatmap::pheatmap (pheatmap包中的pheatmap函数).gplots::heatmap.2等. 相比于gg ...
- 执行join_paired_ends.py报错Cannot find fastq-join
通过 conda 安装 qiime 1后,在执行join_paired_ends.py时报错: burrito.util.ApplicationNotFoundError: Cannot find f ...
- 导出功能在数据库内容为数字,excel表格中是汉字的时候
代码如下: @ExcelField(title = "饮水器评价",dictType = "waterer_rate" ,align = 2, sort = 2 ...
- JAVA程序员面试笔试宝典2
1.Java集合框架 2.迭代器 使用容器的iterator()方法返回一个iterator,然后通过iterator的next()方法返回第一个元素 使用iterator的hasnext()方法判断 ...
- 新安装数据库sqlserver2008r2,使用javaweb连接不上问题处理
鼠标右键[计算机]-->[管理],打开界面如下: 选择自己数据库的实例名: 选择TCP/IP:右键[属性],将所有TCP动态端口的[0]删掉,TCP端口设为1433:重启服务,即可连接. PS: ...
- Extjs定时操作
查看api可知: // 启动一个简单的时钟任务,每秒执行一次更新一个 div var task = { run: function(){ Ext.fly('clock').update(new Dat ...