永发信息网

求MATLAB中filter2函数的源代码。

答案:1  悬赏:60  手机版
解决时间 2021-04-30 03:16

求MATLAB中二维滤波函数filter2的编码程序。。。

急急~

最佳答案

若需要函数体,我可以传文件给你。下面是其代码


function y = filter2(b,x,shape)
%FILTER2 Two-dimensional digital filter.
% Y = FILTER2(B,X) filters the data in X with the 2-D FIR
% filter in the matrix B. The result, Y, is computed
% using 2-D correlation and is the same size as X.
%
% Y = FILTER2(B,X,'shape') returns Y computed via 2-D
% correlation with size specified by 'shape':
% 'same' - (default) returns the central part of the
% correlation that is the same size as X.
% 'valid' - returns only those parts of the correlation
% that are computed without the zero-padded
% edges, size(Y) < size(X).
% 'full' - returns the full 2-D correlation,
% size(Y) > size(X).
%
% FILTER2 uses CONV2 to do most of the work. 2-D correlation
% is related to 2-D convolution by a 180 degree rotation of the
% filter matrix.
%
% Class support for inputs B,X:
% float: double, single
%
% See also FILTER, CONV2.


% Copyright 1984-2004 The MathWorks, Inc.
% $Revision: 5.13.4.2 $ $Date: 2004/03/09 16:16:19 $


error(nargchk(2,3,nargin));
if nargin<3, shape = 'same'; end


if (~isa(b,'float')), b = double(b); end
if (~isa(x,'float')), x = double(x); end


code = [shape,' ']; code = code(1);
if isempty(find(code=='svf'))
error('MATLAB:filter2:InvalidParam', 'Unknown shape parameter.');
end


[mx,nx] = size(x);
stencil = rot90(b,2);
[ms,ns] = size(stencil);


% 1-D stencil?
if (ms == 1)
y = conv2(1,stencil,x,shape);
elseif (ns == 1)
y = conv2(stencil,1,x,shape);
else
if (ms*ns > mx*nx)
% The filter is bigger than the input. This is a nontypical
% case, and it may be counterproductive to check the
% separability of the stencil.
y = conv2(x,stencil,shape);
else
separable = false;
if all(isfinite(stencil(:)))
% Check rank (separability) of stencil
[u,s,v] = svd(stencil);
s = diag(s);
tol = length(stencil) * eps(max(s));
rank = sum(s > tol);
separable = (rank ==1);
end
if separable
% Separable stencil
hcol = u(:,1) * sqrt(s(1));
hrow = conj(v(:,1)) * sqrt(s(1));
if (all(all((round(stencil) == stencil))) & all(all((round(x) == x))))
% Output should be integer
y = round(conv2(hcol, hrow, x, shape));
else
y = conv2(hcol, hrow, x, shape);
end
else
% Nonseparable stencil
y = conv2(x,stencil,shape);
end
end
end

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
我得JJ硬起来有15厘米,这正常吗?
河南都拍过什么电影?
武汉平成日语培训上学期开课时间表
冬妮鲜花总汇地址有知道的么?有点事想过去
技术等级证上哪补办
600036后市如何?
怎样设置一个有权限设置的电脑账户?
坟地栽什么树好,坟地种什么树不好?
OPPO s39 是P4 还是P5 ?除蓝色 还有别的颜色
可打印黑白元素周期表
icey这个游戏怎么样
蜀山游戏的孽之重怎么解
一百个人,一百个砖头
银监会塔城监管分局乌苏监管办事处地址在哪,
五菱宏光换机油多少钱,五菱宏光S原装轮胎是什
推荐资讯
DNF一上游戏 无论什么声音的嗡嗡的、。
3岁左右的孩子喝什么样的牛奶好?
PSP检测到名为“ChiaNet”的接入点、密码是什
诺基亚N-GAGE这个游戏软件,该怎么下载?谁有
谁知隆回滩头镇苏塘乡陈艳霞的详细资料吗?
还是求个高手帮忙,还是语文,
深圳市到樟树市驾车怎么走 我不走高速
^ 这个数学符号是什么意思?比如a^3是什么意
芭克硅胶软膏15g多少钱
我是一个班的班长,有个生物老师看不上我总和
会配情侣网名的小跑、
我6月20号来的量也不多而且是黑红色的、可现
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?