Exemplo n.º 1
0
 public void PropertyMaxPixelValue()
 {
     using (var refImage = Image("lenna.png"))
         using (var psnr = QualityPSNR.Create(refImage))
         {
             const double value = 123.456;
             psnr.MaxPixelValue = value;
             Assert.Equal(value, psnr.MaxPixelValue, 6);
         }
 }
Exemplo n.º 2
0
        public void StaticCompute()
        {
            using (var refImage = Image("lenna.png"))
                using (var targetImage = new Mat())
                {
                    Cv2.GaussianBlur(refImage, targetImage, new Size(5, 5), 15);

                    var value = QualityPSNR.Compute(refImage, targetImage, null);
                    Assert.Equal(28.813382, value[0], 6);
                    Assert.Equal(28.171064, value[1], 6);
                    Assert.Equal(30.828286, value[2], 6);
                }
        }
Exemplo n.º 3
0
        public void Compute()
        {
            using (var refImage = Image("lenna.png"))
                using (var targetImage = new Mat())
                    using (var psnr = QualityPSNR.Create(refImage))
                    {
                        Cv2.GaussianBlur(refImage, targetImage, new Size(5, 5), 15);

                        var value = psnr.Compute(targetImage);
                        Assert.Equal(28.893586, value[0], 6);
                        Assert.Equal(28.26987, value[1], 6);
                        Assert.Equal(31.088282, value[2], 6);
                    }
        }
Exemplo n.º 4
0
        private void IdentifyDifferencesSingleFrame(int inFileIndex)
        {
            if (inFileIndex + 1 < _inputFramesFileNames.Count)
            {
                var frameA = Cv2.ImRead(_inputFramesFileNames[inFileIndex]);
                var frameB = Cv2.ImRead(_inputFramesFileNames[inFileIndex + 1]);

                var frameAResized = ScaleFrame(frameA);
                var frameBResized = ScaleFrame(frameB);

                var grayFrameA = new Mat();
                var grayFrameB = new Mat();
                Cv2.CvtColor(frameAResized, grayFrameA, ColorConversionCodes.RGB2GRAY);
                Cv2.CvtColor(frameBResized, grayFrameB, ColorConversionCodes.RGB2GRAY);

                Parallel.For(0, _frameDivisionDimensionY, new ParallelOptions {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                }, ih =>
                {
                    for (int iw = 0; iw < _frameDivisionDimensionX; iw++)
                    {
                        var x = grayFrameA.Width / _frameDivisionDimensionX * iw;
                        var y = grayFrameA.Height / _frameDivisionDimensionY * ih;
                        var h = grayFrameA.Height / _frameDivisionDimensionY;
                        var w = grayFrameA.Width / _frameDivisionDimensionX;

                        var grayFrameBlockA = grayFrameA[y, y + h, x, x + w];
                        var grayFrameBlockB = grayFrameB[y, y + h, x, x + w];

                        var qualityMetrics = QualityPSNR.Compute(grayFrameBlockA, grayFrameBlockB, null);

                        if (qualityMetrics.Val0 <= _similarityThreshold)
                        {
                            _frameCollector.CollectTempBlock(inFileIndex, iw, ih);
                        }
                    }
                });
            }
        }
        public static double PSNR(Bitmap reference, Bitmap compare)
        {
            Scalar scalar = QualityPSNR.Compute(InputArray.Create(BitmapConverter.ToMat(reference)), InputArray.Create(BitmapConverter.ToMat(compare)), null);

            return((scalar[0] + scalar[1] + scalar[2]) / 3);
        }