1 Median Filtering 中值滤波

The function medfilt1 implements one-dimensional median filtering, a nonlinear technique that applies a sliding window to a sequence.

medfilt1是中值滤波的一维实现,是一种对序列进行滑动窗口处理类的非线性技术。

The median filter replaces the center value in the window with the median value of all the points within the window [5].

在窗口内,中值滤波将中心点数值用所有点的中值来替代。

In computing this median, medfilt1 assumes zeros beyond the input points.

计算中值时,medfilt1假设输入点以外都是0.

When the number of elements n in the window is even, medfilt1 sorts the numbers, then takes the average of the n/2 and n/2 + 1 elements.

当序列的窗口内点数n为偶数个时,medfilt1首先对点号进行排序,然后取n/2和n/2+1个元素的平均。

Two simple examples with fourth- and third-order median filters are

下面给出四阶和三阶中值滤波的例子
medfilt1([4 3 5 2 8 9 1],4)
ans =
    1.500 3.500 3.500 4.000 6.500 5.000 4.500

首先看四阶的,序列为[4 3 5 2 8 9 1]

i=1时,窗口=[0 0 4 3] 第n/2个=0 第n/2+1个=3 均值为1.5

i=2时,窗口=[0 4 3 5] 第n/2个=3 第n/2+1个=4 均值为3.5

i=3时,窗口=[4 3 5 2] 第n/2个=3 第n/2+1个=4 均值为3.5

i=4时,窗口=[3 5 2 8] 第n/2个=3 第n/2+1个=5 均值为4

medfilt1([4 3 5 2 8 9 1],3)
ans =
     3     4     3     5     8     8     1

接下来看三阶的,序列为[4 3 5 2 8 9 1]

当i=1时,窗口=[0 4 3]中值为3

当i=2时,窗口=[4 3 5]中值为4

当i=3时,窗口=[3 5 2]中值为3

看完这个解释,我终于理解了中值滤波和均值滤波的区别

中值滤波就是取中数,均值滤波则完全是取均值。

你学费了吗?

Matlab甚至还为你准备好了参考文献:

[1] Kay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ: Prentice Hall, 1988.

[2] Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1989.

[3] Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1975, Section 10.5.3.

[4] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wiley & Sons, 1987.

[5] Pratt,W.K. Digital Image Processing. New York: John Wiley & Sons, 1991.

-------分隔线--------

上述为一维中值滤波的实现,看完算法后,我甚至都不想在举例说明了,因为确实是懂了。

就是因为取得是中值,所以就会消除尖刺噪声,但同时也会有保留边界的优点,且幅值不会下降(均值滤波就会有这个问题,因为是平均嘛)。

-------分隔线--------

下面来看看二维中值滤波

medfilt2

2 2-D median filtering 二维中值滤波

Note   The syntax medfilt2(A,[M N],(Mb Nb],...) has been removed.

注意:上述语法已经被移除,不再支持了。要使用下面的语法格式。
Syntax

B = medfilt2(A, [m n])
B = medfilt2(A)
B = medfilt2(A, 'indexed', ...)
B = medfilt2(..., padopt)

Description 使用指南

Median filtering is a nonlinear operation often used in image processing to reduce "salt and pepper" noise. A median filter is more effective than convolution when the goal is to simultaneously reduce noise and preserve edges.

中值滤波是一种非线性滤波器,在图像处理中常用于消除“盐和胡椒粉”这样的噪声。

如果你不知道啥是盐和胡椒粉,请看下图:

哈哈,说白了就是尖刺噪声。

B = medfilt2(A, [m n]) performs median filtering of the matrix A in two dimensions.

B = medfilt2(A, [m n]) 为对二维矩阵A进行中值滤波。

Each output pixel contains the median value in the m-by-n neighborhood around the corresponding pixel in the input image.

输出的每个像素点都处理为在其周围m行n列的邻近点阵的中值。

medfilt2 pads the image with 0s on the edges, so the median values for the points within [m n]/2 of the edges might appear distorted.

medfilt2在边界处用0进行扩边,因此对边界处[m n]/2内的点可能会产生畸变。

[编者多嘴]这点值得引起注意,其实完全可以用复制的方法扩边。这样更容易避免畸变。

B = medfilt2(A) performs median filtering of the matrix A using the default 3-by-3 neighborhood.

B = medfilt2(A) 为对矩阵A进行默认的3×3点中值滤波。

B = medfilt2(A, 'indexed', ...) processes A as an indexed image, padding with 0s if the class of A is uint8, or 1s if the class of A is double.

B = medfilt2(A, 'indexed', ...) 用来处理被索引的图像A,如果A的类型是uint8就用0扩边,是双精度浮点数就用1扩边。

B = medfilt2(..., padopt) controls how the matrix boundaries are padded. padopt may be 'zeros' (the default), 'symmetric', or 'indexed'.

B = medfilt2(..., padopt) 用来控制矩阵边界的扩边方式,参数padopt默认为'zeros'也就是0,还可以是'symmetric'对称,或者'indexed'被索引的。

If padopt is 'symmetric', A is symmetrically extended at the boundaries. If padopt is 'indexed', A is padded with ones if it is double; otherwise it is padded with zeros.

如果padopt设置为'symmetric',矩阵A就会被以对称的方式扩边,如果是'indexed',如果A是双精度实数,就会扩边为1,否则就是扩边为0。

综合来看,medfilt2也就是使用方式更灵活,更有针对性。

Class Support 类的支持

The input image A can be of class logical or numeric (unless the 'indexed' syntax is used, in which case A cannot be of class uint16). The output image B is of the same class as A.

输入图像A可以是逻辑的或者数值的(如果没用'indexed'语法,那么A不能为uint16类型),输出图像B和A的类型保持一致。

Note   For information about performance considerations, see ordfilt2.

注意:想了解更多关于运算性能及条件,清参见ordfilt2函数。

Tips 官方小贴士

If the input image A is of an integer class, all the output values are returned as integers.

如果输入图像A是整数类型,输出格式也会是整数类型。

If the number of pixels in the neighborhood (i.e., m*n) is even, some of the median values might not be integers. In these cases, the fractional parts are discarded. Logical input is treated similarly.

如果窗口内(即, m*n)像素点为偶数,那么像素点可能不是整数。这时候,小数部分会舍去。逻辑类型的数据(只有0和1)也是类似的处理办法。

For example, suppose you call medfilt2 using 2-by-2 neighborhoods, and the input image is a uint8 array that includes this neighborhood.
1 5
4 8

例如,假设你用2×2的窗口来处理,输入图像A是uint8类型,且窗口内为

1 5
4 8
medfilt2 returns an output value of 4 for this neighborhood, although the true median is 4.5.

其中值就是4和5,均值就是4.5,舍去小数就是4。

Examples 官方示例

Add salt and pepper noise to an image and then restore the image using medfilt2.

下面,我们使用盐和胡椒面来污染一个图像,然后再用medfilt2来提纯

% 读取原始图像

I = imread('eight.tif');

% 添加噪声
J = imnoise(I,'salt & pepper',0.02);

% 中值滤波
K = medfilt2(J);

% 绘图对比效果
imshow(J), figure, imshow(K)

效果还是棒棒的。

Algorithms 算法

medfilt2 uses ordfilt2 to perform the filtering.

medfilt2 使用 ordfilt2 函数来实现滤波。

References 官方参考文献
[1] Lim, Jae S., Two-Dimensional Signal and Image Processing, Englewood Cliffs, NJ, Prentice Hall, 1990, pp. 469-476.
See Also 更多内容...

filter2 | ordfilt2 | wiener2

Matlab 中值滤波原理分析相关推荐

  1. matlab图像处理-中值滤波原理

    中值滤波原理   中值滤波本质上是一种统计排序滤波器.对于原图像中某点(i,j),中值滤波以该点为中心的邻域内的所有像素的统计排序中值作为(i,j)点的响应.   中值不同于均值,是指排序队列中位于中 ...

  2. java 中值滤波_matlab图像处理-中值滤波原理(示例代码)

    中值滤波原理 ??中值滤波本质上是一种统计排序滤波器.对于原图像中某点(i,j),中值滤波以该点为中心的邻域内的所有像素的统计排序中值作为(i,j)点的响应. ??中值不同于均值,是指排序队列中位于中 ...

  3. FPGA中值滤波实现并Modelsim仿真,与MATLAB中值滤波进行对比

    文章目录 一.中值滤波算法 二.FPGA实现中值滤波 2.1 3*3窗口的生成 2.2 排序模块 2.3中值滤波模块 2.4 整体RTL图 三.modeslim仿真 四.matlab中值滤波 五.效果 ...

  4. 中值滤波原理及其代码实现

    本文主要是对高斯滤波,中值滤波原理进行简单介绍,随后用代码实现高斯噪声和椒盐噪声.以及用高斯滤波和中值滤波对这两种图像进行相关的处理. 高斯噪声:就是服从高斯正态分布的噪声,通常是因为高温或者是传感器 ...

  5. 中值滤波原理及其C++实现与CUDA优化

    对于数字图像的去噪,前边我们讲了均值滤波算法与高斯滤波算法,此外很常见的还有中值滤波算法,这些滤波算法都属于空间滤波,即对于每一个像素点,都选取其周围矩形区域中的像素点来计算滤波值.最近在项目中要使用 ...

  6. 3 3中值滤波 matlab,MATLAB中值滤波在灰度图像处理中的应用研究和仿真(3)

    MATLAB中值滤波在灰度图像处理中的应用研究和仿真(3) 时间:2016-11-30 21:28来源:毕业论文 3.2 中值滤波的仿真 3.2.1 中值滤波仿真函数介绍 MATLAB能够支持多种图像 ...

  7. 中值滤波原理及matlab实现代码

    一.基本原理 上述均值滤波虽然可以降低噪声,但是也会导致图像模糊.而中值滤波在一定条件下可以克服线性滤波带来的图像细节模糊的问题,它对处理椒盐噪声非常有效. 中值滤波通常采用一个含有奇数个点的滑动窗口 ...

  8. 中值滤波原理及MATLAB算法实现

    中值滤波是一种非线性滤波方式,它依靠模板来实现. 对于一维中值滤波,设模板的尺寸为 M ,M=2*r+1,r为模板半径,给定一维信号f(i),i = 1,2,3--N,则中值滤波输出为: g(i) = ...

  9. Matlab中值滤波

        'medfilt2' 是 MATLAB 中的一个函数,用于对二维图像进行中值滤波.中值滤波是一种非线性滤波方法,它将每个像素的值替换为该像素周围邻域内像素的中值. 该函数语法如下: B = m ...

  10. 中值滤波原理及c++实现

    写在前面 中值滤波器是一种非线性滤波器,或者叫统计排序滤波器. 应用:中值滤波对脉冲噪声(如椒盐噪声)的抑制十分有用. 缺点:易造成图像的不连续性. 原理 原理很简单,如果一个信号是平缓变化的,那么某 ...

最新文章

  1. 关于Verilog HDL的一些技巧、易错、易忘点(不定期更新)
  2. Bleve:来自Couchbase、基于Go语言的全文索引与检索库
  3. 035_jdbc-mysql-dbutils的使用
  4. OpenGL百分比更紧密过滤
  5. Linux环境下基于策略的路由
  6. 2020最常用的8个代码编辑器推荐
  7. 智能翻译android,离线翻译SDK,让智能小设备如虎添翼
  8. window使用fliqlo 教程
  9. 【转载】数据库操作系统——Visual FoxPro 6.0安装步骤
  10. 计量经济学实验报告计算机,计量经济学实验报告记录.doc
  11. 读懂以太坊的客户端多样性,为何如此重要?
  12. 【小万出生记——第3篇】小万升级为家用服务机器人
  13. 海信电视E7H和E5H哪个好?有什么区别
  14. 第四次机考(2019) C. f1二
  15. 电脑无法识别扫码枪怎么办?看4点解决方法就知道
  16. 大数据毕设 - 网络游戏数据分析与可视化(python 大数据)
  17. 数据库----MySQL
  18. 2020年年假期间规划
  19. java 帕斯卡,帕斯卡三角 有多少种可能,java编程 帕斯卡三角形 立刻求高手!! 给满分...
  20. matlab位置1处索引超出数组边界错误怎么改呢

热门文章

  1. Java selenium 设置代理
  2. 微商新手如何选产品?史上最详细操作指南!
  3. Kylo调研总结(二)
  4. 校园招聘数电模电笔试题
  5. mysql数据库默认管理员是_数据库管理员密码的设置
  6. 五线四相步进电机C语言程序,stm32四相五线步进电机驱动程序
  7. 微信小程序测试点总结
  8. payjs 源码_ZFAKA发卡系统用宝塔安装详细图文教程+对接Payjs个人支付版本
  9. Python学习第二章:变量和简单类型
  10. 数据大屏产品介绍PPT_精品推荐 | 产品介绍、公司宣传、解决方案 | 可编辑PPT(收藏)...