C#和matlab给出了不同的图像手段?

时间:2015-11-08 21:11:42

标签: c# matlab

我正在计算C#和matlab中RGB通道的平均值,结果略有不同? (我使用0-255像素值...)

差别不大但我似乎无法理解原因...

这是常见的吗?还是由于图像的位图实现?还是精确问题?或者这是否意味着我的代码出了问题?

代码:

Matlab的

I = imread('Photos\hv2512.jpg');
Ir=double(I(:,:,1));
Ig=double(I(:,:,2));
Ib=double(I(:,:,3));


avRed=mean2(Ir)
avGn=mean2(Ig)
avBl=mean2(Ib)

C#

        Bitmap bmp= new Bitmap(open.FileName)
        double[,] Red = new double[bmp.Width, bmp.Height];
        double[,] Green = new double[bmp.Width, bmp.Height];
        double[,] Blue = new double[bmp.Width, bmp.Height];

        int PixelSize = 3;
        BitmapData bmData = null;

        if (Safe)
        {
            Color c;

            for (int j = 0; j < bmp.Height; j++)
            {
                for (int i = 0; i < bmp.Width; i++)
                {
                    c = bmp.GetPixel(i, j);
                    Red[i, j] =   (double) c.R;
                    Green[i, j] = (double) c.G;
                    Blue[i, j] =  (double) c.B;



                }
            }
        }
            double avRed = 0, avGrn = 0, avBlue = 0;
            double sumRed = 0, sumGrn = 0, sumBlue = 0;
            int cnt = 0;

            for (int rws = 0; rws < Red.GetLength(0); rws++)
                for (int clms = 0; clms < Red.GetLength(1); clms++)
                {
                    sumRed = sumRed + Red[rws, clms];
                    sumGrn = sumGrn + Green[rws, clms];
                    sumBlue = sumBlue + Blue[rws, clms];

                    cnt++;
                }


            avRed = sumRed / cnt;
            avGrn = sumGrn / cnt;
            avBlue = sumBlue / cnt; 

This is the image I am using

0 个答案:

没有答案