使用均值滤波器进行二维矩阵平滑

收录时间:2014-04-13
资源分类:Matlab 工具:MATLAB 7.4 (R2007a)

该程序对二维矩阵数据进行了平滑,忽略了NaN。

使用均值滤波对大小为(2*Nr+1)-by-(2*Nc+1)的矩阵进行平滑。基本上,你结束取代元件“i”时,“i”为矩形的平均值。任何NaN元素会被忽略如果元素的“i是NaN那么它在输出将被保留NaN

 

smooth2a

Smooths 2D array data. Ignores NaN's.

 

function matrixOut = smooth2a(matrixIn,Nr,Nc)

 

This function smooths the data in matrixIn using a mean filter over a

rectangle of size (2*Nr+1)-by-(2*Nc+1). Basically, you end up replacing

element "i" by the mean of the rectange centered on "i". Any NaN

elements are ignored in the averaging. If element "i" is a NaN, then it

will be preserved as NaN in the output. At the edges of the matrix,

where you cannot build a full rectangle, as much of the rectangle that

fits on your matrix is used (similar to the default on Matlab's builtin

function "smooth").

 

"matrixIn": original matrix

"Nr": number of points used to smooth rows

"Nc": number of points to smooth columns. If not specified, Nc = Nr.

 

"matrixOut": smoothed version of original matrix

 

%%%%%%%%%

 

Explanation of screenshot:

The left plot is a pcolor (shading interp, axis equal) of a "jagged" 906x1024 matrix. Note that the edges have NaN values (white coloring). On the right, pcolor of output of smooth2a, with Nr = Nc = 50. NaN's are preserved, but do not affect the smoothing of adjacent elements.

文件下载列表
smooth2a.zip (1.30KB)  
附件内容
smooth2a.m  
标签: 平滑 均值滤波器 
更多

目前尚无评论

用户反馈   关于我们
Copyright (©) ZHIHUISHI.COM 2013 All Rights Reserved.
京ICP备18060134号-2