function snr=SNR(I,In)<BR>% 计算信号噪声比函数<BR>% by Qulei <BR>% I :original signal<BR>% In:noisy signal<BR>% snr=10*log10(sigma2(I2)/sigma2(I2-I1))<BR><BR>[row,col,nchannel]=size(I);<BR><BR>snr=0;<BR>if nchannel==1%gray image<BR>Ps=sum(sum((I-mean(mean(I))).^2));%signal power<BR>Pn=sum(sum((I-In).^2));%noise power<BR>snr=10*log10(Ps/Pn);<BR>elseif nchannel==3%color image<BR>for i=1:3<BR>Ps=sum(sum((I(:,:,i)-mean(mean(I(:,:,i)))).^2));%signal power<BR>Pn=sum(sum((I(:,:,i)-In(:,:,i)).^2));%noise power<BR>snr=snr+10*log10(Ps/Pn);<BR>end<BR>snr=snr/3;<BR>end |