colormoon 发表于 2006-5-26 15:28

[求助]matlab中有无求信噪比的函数

<P>如题</P>

happy 发表于 2006-5-26 15:34

回复:(colormoon)[求助]matlab中有无求信噪比的函数...

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>=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

colormoon 发表于 2006-5-26 15:45

多谢 happy 教授!

zhyuer 发表于 2006-5-26 19:29

xiexie

hui66 发表于 2006-6-2 09:08

回复:(happy)回复:(colormoon)[求助]matlab中有...

<P>我用这个程序时出现错误:<BR>??? Error using ==&gt; -<BR>Function '-' is not defined for values of class 'uint8'.</P>
<P>Error in ==&gt; D:\work\SNR.m<BR>On line 17==&gt; Ps=sum(sum((I(:,:,i)-mean(mean(I(:,:,i)))).^2));%signal power<BR>我是新手,还请happy教授多多指点!!</P>

happy 发表于 2006-6-2 09:11

回复:(colormoon)[求助]matlab中有无求信噪比的函数...

<P>看一下你这里i的数据类型是不是'uint8'<BR>如果是的需要用double转化一下</P>

colormoon 发表于 2006-6-2 15:25

<P>% ===求信噪比================<BR>% SNR=10*log10(i_sum/o_sum)<BR>% ==========================</P>
<P>function SNR=snr(sp,noise)</P>
<P><BR>spPower=sum(abs(sp(:)).^2)/length(sp(:));<BR>noPower=sum(abs(noise(:)).^2)/length(noise(:));</P>
<P>spPower=10*log10(spPower);<BR>noPower=10*log10(noPower);</P>
<P>SNR=spPower-noPower;<BR><BR>我又重新写了一个简单一点的,向happy教授请教,不知对否?</P>

多情清秋 发表于 2006-6-2 16:14

回复:(colormoon)[求助]matlab中有无求信噪比的函数...

<P><FONT color=#ff0000>colormoon happy加威望2点,hui66加威望1点</FONT></P>
<P>多情清秋<BR>06.6.2</P>

hui66 发表于 2006-6-5 08:21

谢谢

多谢happy教授指导!!
页: [1]
查看完整版本: [求助]matlab中有无求信噪比的函数