示例#1
0
文件: MSE.cs 项目: PSE-2012/MMWTV
        /// <summary>
        /// Method to generate the analysis data.
        /// </summary>
        public AnalysisInfo analyse(System.Drawing.Bitmap frameRef, System.Drawing.Bitmap frameProc)
        {
            AnalysisInfo analyse = null;
            if (frameRef != null && frameProc != null)
            {
                Bitmap resultFrame = new Bitmap(frameRef.Width, frameRef.Height);
                double sum = 0;
                double sumR = 0;
                double sumG = 0;
                double sumB = 0;

                //int rb = (propertiesView.getRb());
                float[] resultValues = new float[4];

                for (int i = 0; i < frameRef.Height - 1; i++)
                {
                    for (int j = 0; j < frameRef.Width - 1; j++)
                    {
                        int newPixel = 0;

                        //Get Color from Proc
                        Color colorProc = frameProc.GetPixel(j, i);
                        int alphaProc = colorProc.A;
                        int redProc = colorProc.R;
                        int greenProc = colorProc.G;
                        int blueProc = colorProc.B;

                        //Get Color from Ref
                        Color colorRef = frameRef.GetPixel(j, i);
                        int alphaRef = colorRef.A;
                        int rotRef = colorRef.R;
                        int grunRef = colorRef.G;
                        int blauRef = colorRef.B;

                        //RGB
                        int newRed = (int)Math.Pow((redProc - rotRef), 2);
                        int newGreen = (int)Math.Pow((greenProc - grunRef), 2);
                        int newBlue = (int)Math.Pow((blueProc - blauRef), 2);

                        sum += newBlue / 3 + newGreen / 3 + newRed / 3;
                        sumR += newRed;
                        sumG += newGreen;
                        sumB += newBlue;

                        switch (radioButton)
                        {
                            case 0:
                                newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRed << 16) | (newGreen << 8) | newBlue;
                                break;

                            case 1:
                                newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRed << 16) | (0 << 8) | 0;
                                break;

                            case 2:
                                newPixel = (((alphaProc + alphaRef) / 2) << 24) | (0 << 16) | (newGreen << 8) | 0;
                                break;

                            case 3:
                                newPixel = (((alphaProc + alphaRef) / 2) << 24) | (0 << 16) | (0 << 8) | newBlue;
                                break;
                        }
                        resultFrame.SetPixel(j, i, Color.FromArgb(newPixel));
                    }
                }
                resultValues[0] = (float)sum / (frameProc.Height * frameProc.Width);
                resultValues[1] = (float)sumR / (frameProc.Height * frameProc.Width);
                resultValues[2] = (float)sumG / (frameProc.Height * frameProc.Width);
                resultValues[3] = (float)sumB / (frameProc.Height * frameProc.Width);
                analyse = new AnalysisInfo(resultFrame, resultValues);
            }
            return analyse;
        }
示例#2
0
文件: PSNR.cs 项目: PSE-2012/MMWTV
        /// <summary>
        /// Method to generate the analysis data.
        /// </summary>
        public AnalysisInfo analyse(System.Drawing.Bitmap frameRef, System.Drawing.Bitmap frameProc)
        {
            Bitmap resultFrame = new Bitmap(frameRef.Width, frameRef.Height);
            double summe = 0;

            float[] resultValues = new float[1];

            for (int i = 0; i < frameRef.Height - 1; i++)
            {
                for (int j = 0; j < frameRef.Width - 1; j++)
                {
                    int newPixel = 0;

                    Color colorProc = frameProc.GetPixel(j, i);

                    int alphaProc = colorProc.A;
                    int rotProc = colorProc.R;
                    int grunProc = colorProc.G;
                    int blauProc = colorProc.B;

                    Color colorRef = frameRef.GetPixel(j, i);

                    int alphaRef = colorRef.A;
                    int rotRef = colorRef.R;
                    int grunRef = colorRef.G;
                    int blauRef = colorRef.B;

                    //RGB
                    int newRot = (int)Math.Pow((rotProc - rotRef), 2);
                    int newGrun = (int)Math.Pow((grunProc - grunRef), 2);
                    int newBlau = (int)Math.Pow((blauProc - blauRef), 2);

                    summe = summe + newBlau  + newGrun + newRot ;
                     newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRot << 16) | (newGrun << 8) | newBlau;

                    resultFrame.SetPixel(j, i, Color.FromArgb(newPixel));
                }
            }

            float mse = (float)summe / (frameProc.Height * frameProc.Width*3);

            if(0<=mse&&mse<=1)
            {
                resultValues[0] = -1;
            }
            else
            {
                resultValues[0] = (float)(20*Math.Log10(255)-10*Math.Log10(mse));
            }

            AnalysisInfo analyse = new AnalysisInfo(resultFrame, resultValues);
            return analyse;
        }
示例#3
0
        public static void MyClassInitialize(TestContext testContext)
        {
            PSNR testMSE = new PSNR();
            refBitmap = new Bitmap(100, 100);
            for (int height = 0; height < refBitmap.Height; height++)
            {
                for (int width = 0; width < refBitmap.Width; width++)
                {
                    refBitmap.SetPixel(width, height, Color.White);
                    width++;
                    refBitmap.SetPixel(width, height, Color.Black);
                    width++;
                    refBitmap.SetPixel(width, height, Color.Red);
                    width++;
                    refBitmap.SetPixel(width, height, Color.Green);
                    width++;
                    refBitmap.SetPixel(width, height, Color.Blue);
                }
            }

            procBitmap = new Bitmap(100, 100);
            for (int width = 0; width < refBitmap.Width; width++)
            {
                for (int height = 0; height < procBitmap.Height; height++)
                {
                    procBitmap.SetPixel(width, height, Color.White);
                    height++;
                    procBitmap.SetPixel(width, height, Color.Black);
                    height++;
                    procBitmap.SetPixel(width, height, Color.Red);
                    height++;
                    procBitmap.SetPixel(width, height, Color.Green);
                    height++;
                    procBitmap.SetPixel(width, height, Color.Blue);
                }
            }
            analysisInfo = testMSE.analyse(refBitmap, procBitmap);
            analysedBitmap = analysisInfo.frame;
        }