matlab filter函数源码,求MATLAB中filter2函数的源代码求MATLAB中二维 爱问知识人

若需要函数体,我可以传文件给你。下面是其代码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)。

%

% 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 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。

全部

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值