一个关于用C#计算图像峰值信噪比的问题
下面的代码是我写的用于计算两个图像峰值信噪比的代码,可问题是,不论我用什么图像进行比较,最后得到的psnr值都是正无穷大。
     我想问一下,计算峰值信噪比需要考虑哪些因素,需要考虑图片的类型什么的么?还是用一种方法就可以计算所有图了?
     麻烦大侠指导一下~谢了~~
public double countPSNR(string formerFpath, string laterFpath)
         {
             Bitmap formerImage=new Bitmap(formerFpath);
             Bitmap laterImage=new Bitmap(laterFpath);
             double sumR = 0;
             double sumG = 0;
             double sumB = 0;
             for (int i = 0; i < formerImage.Width - 1; i++)
             {
                 for (int j = 0; j < formerImage.Height - 1; j++)
                 {
                     Color color1 = formerImage.GetPixel(i, j);
                     Color color2 = laterImage.GetPixel(i, j);
                     int retR = color1.R - color2.R;
                     int retG = color1.G - color2.G;
                     int retB = color1.B - color2.B;
                     sumR = sumR + retR * retR;
                     sumG = sumG + retG * retG;
                     sumB = sumB + retB * retB;
                 }
             }
             double sum=sumR+sumG+sumB;
             double MSE = (1 / (3 * formerImage.Width * formerImage.Height)) * sum;
             double PSNR = 20 * Math.Log10(255 / Math.Sqrt(MSE));
             return PSNR;
         }
------解决方案--------------------不知道在说什么 不过感觉好强大的样子!
------解决方案--------------------
double MSE = (sum / (3 * formerImage.Width * formerImage.Height)) ;
改成这样