一个图像降噪的程序问题
大虾们,帮帮忙!我从书上荡了一个图像降噪的问题,可是使用MATLAB就是仿真不起来,不知道问题出在哪里,本人刚学MATLAB对程序不是很了解,请大虾们帮忙看看,到底哪里出问题了!帮帮忙!谢谢了
Close all
Clear
Clc
Addpath' rwt'
X=imread("图片位置");
X=double(X);
[N,ny]=size(X);
Sigma=25;
Seed=0;
Randn('state',seed);
Y=X+sigma*randn(size(x));
H=daubcqf(8,"min');
L=4:
R=3;
XX=abs(fft2(Y)).^2;
XXX=zeros(N,N);
For xx=1:N
For yy=1:N
P=0;
For i1=-R:R
For i2=-R:R
Xx1=xx1+i1;yy1=yy+i2;
If xx1<1
Xx1=N+xx1;
Elseif xx1>N
Xx1=xx1-N;
End
If yy1<1
Yy1=N+yy1;
Elseif yy1>N
Yy1=yy1-N;
End
P=p+XX(xx1,yy1);
End
End
XXX(xx,yy)=p/(2*R+1)^2-N*N*sigma^2;
If XXX(xx,yy)<=0.1*N*N*sigma^2
XXX(xx,yy)=0.1*N*N*sigma^2;
End
End
End
XXX=5*XXX;
Ffilter=XXX./(XXX+N*N*sigma^2);
xF=real(ifft2(Ffilter.*fft2(Y)));
%计算有色噪声在每一个子带中的方差
J=log2(N);
L1=J-L;
Noisevarw=zeros(L,3);
For j=L1:J-1
Tempw=zeros(N,N);
TEMPW(1,N/2^(J-j-1))=1;
[cwave,1]=midwt(tempw,h,L);
CWAVE=fft2(cwave);
CWAVE=CWAVE.*abs(Ffilter).^2;
CWAVE=real(ifft2(CWAVE));
CWAVE=CWAVE.*cwave;
Noisevarw(j-L1+1,1)=sqrt(sum(CWAVE(: )))*sigma;
Tempw=zeros(N,N);
Tempw(N/2^(J-j-1),1)=1;
[cwave,1]=midwt(tempw,h,L);
CWAVE=fft2(cwave);
CWAVE=CWAVE.*abs(Ffilter).^2;
CWAVE=real(ifft2(CWAVE));
CWAVE=CWAVE.*cwave;
Noisevarw(j-L1+1,2)=sqrt(sum(CWAVE(: )))*sigma;
End
[xw,k]=mdwt(xF,h,L);
Wcoefth=fo(xw,L,noisevarw);
[out,1]=midwt(wcoefth,,L);
Clear tempw temps
Figure('Position',[500,100,480,240])
Subplot('position',[0.001 0.03 0.48 0.96])
Imagesc(Y)
Axis off
SE=norm(out-x,'fro')^2;
PSNR=10*log10(N*N*255^2/SE)
子程序
Function f=fo(wcoef,L,nw)
%initialisations
[nx,ny]=size(wcoef);
J=log2(nx);
Wcoef_th=wcoef;
R=1;
Matrxtemp=zeros(2*R+1,2*R+1);
L=J-L;
For j=L:J-1
For x1=2^(j)+1:2^(j+1)
For y1=1:2^j
P=0;
For i1=-R:+R
For i2=-R:+R
Xx=x1+i1;yy=y1+i2;
If xx<2^j+1
Xx=2^(j+1)+i1+1;
Elseif xx>2^(j+1)
Xx=2^j+i1;
End
If yy<1
Yy=2^j+i2+1;
Elseif yy>2^j
Yy=i2;
End
Matrxtemp(R+i1+1,R+i2+1)wcoef(xx,yy);
End
End
M1=Matrxtemp;
M1=M1.^2/(2*R+1)^2;
S1=sum(M1(: ));
Esigma2=nw(j-L+1,2)^2;
P=s1-esigma2;
If p<0
P=eps;
End
p=p/(p+esigma2);
wcoef_th(x1,y1)=wcoef(x1,y1)*p;
End
End
End
F=wcoef_th;
MATLAB提示的错误是这样的??? Undefined function or variable 'Clear'.
可能是我把图片改掉了,跟作者的不一样,不过我对MATLAB实在是个菜,就是没弄懂
上传的图像 boat.jpg (7.8 KB, 2 次查看)
此帖于 2009-06-04 10:15 AM 被 okey1986 编辑。