基于Matlab的图像信噪比计算

话不多说 直接上代码 复制即可使用!!!
如果觉得可用 可以给咱点个赞

I=imread('D:\601\p\2.JPG');%单引号里面是图片的绝对位置
I=rgb2gray(I);%彩色转灰度

In=imread('D:\601\p\3.JPG');
In=rgb2gray(In);
In1=imread('D:\601\p\4.JPG');
In1=rgb2gray(In1);
 function snr=SNR1(I,In)
 
    [row,col,nchannel]=size(I);
    snr=0;
    if nchannel==1%gray image
    Ps=sum(sum((I-mean(mean(I))).^2));%signal power
    Pn=sum(sum((I-In).^2));%noise power
    snr=10*log10(Ps/Pn)
    elseif nchannel==3%color image
        for i=1:3
            Ps=sum(sum((I(:,:,i)-mean(mean(I(:,:,i)))).^2));%signal power
            Pn=sum(sum((I(:,:,i)-In(:,:,i)).^2));%noise power
            snr=snr+10*log10(Ps/Pn);
        end
        snr=snr/3;
     end
 end

命令行: x=snr(I,In);

    原文作者:磨磨蹭蹭的走
    原文地址: https://blog.csdn.net/skx0000/article/details/116715710
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞