您的位置首页百科问答

求MATLAB中filter2函数的源代码。

求MATLAB中filter2函数的源代码。

的有关信息介绍如下:

问题补充说明:求MATLAB中二维滤波函数filter2的编码程序。。。急急~

求MATLAB中filter2函数的源代码。

若需要函数体,我可以来自传文件给你。下面是其代码议植派零转坏均劳functiony=filter2(b,x,shape)

%FILTER2Two-dimensionaldigita360问答lfilter.

%Y=FILTER2(B,X)filtersthedata被北齐权inXwiththe除叶混妈耐用么吸全林2-DFIR

%filte段美消径入油rinthematrixB.Theresult括满,Y,iscomputed

%using2-DcorrelationandisthesamesizeasX.

%

%Y=FILTER2(B,X,'shape')returnsYcomputedvia2-D

%correlationwithsizespecifiedby'shape':

%'same'-(default)r台错冷剧止落田eturnsthecentr军态段矛杀影alpartofthe

%correlationthatisthesamesizeasX.

%'valid'-returnsonlythos七春大右创劳景斤鲁epartsofthecorrelation

%thatarecompute量赶稳好改地dwithoutthezero-padd运提停载洋ed

%edges,size(Y)<s六较为ize(X).

%'full'-returnsthefull2-Dco级题断读rrelation,

%size(Y)>size(X).

%

%FILTE露R2usesCON状蛋包甲V2todomostofthework.2-Dcorrelation

%isrelatedto2-Dconvolutionby山立用留赵a180degreerotationofthe

%filtermatrix力模女弱毫百压.

%

%ClasssupportforinputsB,X:

%float:double,single

%

%SeealsoFILTER,CONV2.%Copyright1984-2004TheMathWorks,Inc.

%$Revision:5.13.4.2$$Date:2查诉克复酒次怕哥004/03/0916:16:19$error(nargchk(2,3,nargin));

ifnargin<3,shape='same';endif(~isa(b,'float')),b=double(b);end

if(~isa(x,'float')),x=double(x);endcode=[shape,''];code=code(1);

ifisempty(find(code=='svf'))

error('MATLAB:filter2:InvalidParam','Unknownshapeparameter.');

end[mx,nx]=size(x);

stencil=rot90(b,2);

[ms,ns]=size(stencil);%1-Dstencil?

if(ms==1)

y=conv2(1,stencil,x,shape);

elseif(ns==1)

y=conv2(stencil,1,x,shape);

else

if(ms*ns>mx*nx)

%Thefilterisbiggerthantheinput.Thisisanontypical

%case,anditmaybecounterproductivetocheckthe

%separabilityofthestencil.

y=conv2(x,stencil,shape);

else

separable=false;

ifall(isfinite(stencil(:)))

%Checkrank(separability)ofstencil

[u,s,v]=svd(stencil);

s=diag(s);

tol=length(stencil)*eps(max(s));

rank=sum(s>tol);

separable=(rank==1);

end

ifseparable

%Separablestencil

hcol=u(:,1)*sqrt(s(1));

hrow=conj(v(:,1))*sqrt(s(1));

if(all(all((round(stencil)==stencil)))&all(all((round(x)==x))))

%Outputshouldbeinteger

y=round(conv2(hcol,hrow,x,shape));

else

y=conv2(hcol,hrow,x,shape);

end

else

%Nonseparablestencil

y=conv2(x,stencil,shape);

end

end

end