/// <summary>
        /// Verify whether the given image is similar as the base image
        /// This method is used for SUT display verification when using some compress codec like remote FX
        /// This method used an image comparison algorithm to assess input image with a base image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="shift"></param>
        /// <param name="compareRect"></param>
        /// <param name="assessValueThreshold"></param>
        /// <returns></returns>
        private bool IsSimilar(Image image, Point shift, Rectangle compareRect, double assessValueThreshold)
        {
            Bitmap bitmap = null;

            if (image is Bitmap)
            {
                bitmap = image as Bitmap;
            }
            else
            {
                bitmap = new Bitmap(image);
            }

            Bitmap referenceImage = BaseImage.Clone(compareRect, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Bitmap inputImage     = bitmap.Clone(new Rectangle(shift.X + compareRect.Left, shift.Y + compareRect.Top, compareRect.Width, compareRect.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            // Extend image if necessary, so as to make sure the image used for IQA assess is not smaller than size requested by SSIM/MS-SSIM/G-SSIM algorithm
            referenceImage = ExtendImage(referenceImage, ImageQualityAccessment.Ssim.MinWidth, ImageQualityAccessment.Ssim.MinHeight);
            inputImage     = ExtendImage(inputImage, ImageQualityAccessment.Ssim.MinWidth, ImageQualityAccessment.Ssim.MinWidth);

            if (IQAAssessY)
            {
                // Assess Y component
                ImageQualityAccessment.AssessResult res = iqaIndex.Assess(referenceImage, inputImage, ImageQualityAccessment.UseComponent.Luma);
                double assessValueY = res.Luma;

                site.Log.Add(LogEntryKind.Comment, "SimulatedScreen: Assess Y component of Images using {0} algorithm, assess value is {1}, assess value threshold is {2}.", iqaIndex.IndexName, assessValueY, assessValueThreshold);
                if (assessValueY < assessValueThreshold)
                {
                    return(false);
                }
            }

            if (IQAAssessCb)
            {
                // Assess Cb component
                ImageQualityAccessment.AssessResult res = iqaIndex.Assess(referenceImage, inputImage, ImageQualityAccessment.UseComponent.Cb);
                double assessValueCb = res.Cb;

                site.Log.Add(LogEntryKind.Comment, "SimulatedScreen: Assess Cb component of Images using {0} algorithm, assess value is {1}, assess value threshold is {2}.", iqaIndex.IndexName, assessValueCb, assessValueThreshold);
                if (assessValueCb < assessValueThreshold)
                {
                    return(false);
                }
            }

            if (IQAAssessCr)
            {
                // Assess Cr component
                ImageQualityAccessment.AssessResult res = iqaIndex.Assess(referenceImage, inputImage, ImageQualityAccessment.UseComponent.Cr);
                double assessValueCr = res.Cr;

                site.Log.Add(LogEntryKind.Comment, "SimulatedScreen: Assess Cr component of Images using {0} algorithm, assess value is {1}, assess value threshold is {2}.", iqaIndex.IndexName, assessValueCr, assessValueThreshold);
                if (assessValueCr < assessValueThreshold)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        public override AssessResult Assess(System.Drawing.Bitmap reference, System.Drawing.Bitmap distorted, UseComponent component)
        {
            double       Max        = 255;
            var          mseCalc    = new Mse();
            AssessResult mseResult  = mseCalc.Assess(reference, distorted, UseComponent.Luma | UseComponent.Cb | UseComponent.Cr);
            double       mse        = (mseResult.Luma + mseResult.Cb + mseResult.Cr) / 3;
            double       psnr       = 20 * Math.Log10(Max) - 10 * Math.Log10(mse);
            var          psnrResult = new AssessResult();

            psnrResult.Luma = psnr;
            psnrResult.Cb   = psnr;
            psnrResult.Cr   = psnr;
            return(psnrResult);
        }
Пример #3
0
        public override AssessResult Assess(System.Drawing.Bitmap reference, System.Drawing.Bitmap distorted, UseComponent component)
        {
            var result = new AssessResult();

            InitBitmaps(reference, distorted);

            // MSE
            double sum = 0.0;

            for (int i = 0; i < LumaReference.GetLength(0); i++)
            {
                for (int j = 0; j < LumaReference.GetLength(1); j++)
                {
                    sum += (LumaReference[i, j] - LumaDistorted[i, j]) * (LumaReference[i, j] - LumaDistorted[i, j]);
                }
            }
            result.Luma = sum / LumaReference.Length;

            sum = 0.0;
            for (int i = 0; i < CbReference.GetLength(0); i++)
            {
                for (int j = 0; j < CbReference.GetLength(1); j++)
                {
                    sum += (CbReference[i, j] - CbDistorted[i, j]) * (CbReference[i, j] - CbDistorted[i, j]);
                }
            }
            result.Cb = sum / CbReference.Length;

            sum = 0.0;
            for (int i = 0; i < CrReference.GetLength(0); i++)
            {
                for (int j = 0; j < CrReference.GetLength(1); j++)
                {
                    sum += (CrReference[i, j] - CrDistorted[i, j]) * (CrReference[i, j] - CrDistorted[i, j]);
                }
            }
            result.Cr = sum / CrReference.Length;

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Assess Mean MS-SSIM of a distorted bitmap with the reference bitmap
        /// </summary>
        /// <param name="reference">Reference bitmap</param>
        /// <param name="distorted">Distorted bitmap</param>
        /// <param name="component">Specify which components will be assessed, multiple components can be set by using bitwise-or</param>
        /// <exception cref="ArgumentNullException">Thrown when at least one param is null</exception>
        /// <exception cref="ArgumentException">Thrown when the size of the two bitmaps are not illegal for assessment (Sizes are not same, Size too small, etc.)</exception>
        /// <returns>A new AssessResult object indicates the assess results in every specified component.</returns>
        public override AssessResult Assess(Bitmap reference, Bitmap distorted, UseComponent component)
        {
            InitBitmaps(reference, distorted);
            LumaReference = Downscaler.DownscaleByKeepMinLength(LumaReference, ScaleMinLength);
            LumaDistorted = Downscaler.DownscaleByKeepMinLength(LumaDistorted, ScaleMinLength);

            AssessResult res = new AssessResult();

            if (component.HasFlag(UseComponent.Luma))
            {
                res.Luma = GetComponentQuality(LumaReference, LumaDistorted);
            }
            if (component.HasFlag(UseComponent.Cb))
            {
                res.Cb = GetComponentQuality(CbReference, CbDistorted);
            }
            if (component.HasFlag(UseComponent.Cr))
            {
                res.Cr = GetComponentQuality(CrReference, CrDistorted);
            }
            return(res);
        }
Пример #5
0
        /// <summary>
        /// Assess Mean G-SSIM of a distorted bitmap with the reference bitmap
        /// </summary>
        /// <param name="reference">Reference bitmap</param>
        /// <param name="distorted">Distorted bitmap</param>
        /// <param name="component">Specify which components will be assessed, multiple components can be set by using bitwise-or</param>
        /// <exception cref="ArgumentNullException">Thrown when at least one param is null</exception>
        /// <exception cref="ArgumentException">Thrown when the size of the two bitmaps are not illegal for assessment (Sizes are not same, Size too small, etc.)</exception>
        /// <returns>A new AssessResult object indicates the assess results in every specified component.</returns>
        public override AssessResult Assess(Bitmap reference, Bitmap distorted, UseComponent component)
        {
            InitBitmaps(reference, distorted);
            LumaReference = Downscaler.DownscaleByKeepMinLength(LumaReference, ScaleMinLength);
            LumaDistorted = Downscaler.DownscaleByKeepMinLength(LumaDistorted, ScaleMinLength);

            SsimParameters gssimParams = new SsimParameters(WindowWidth, WindowHeight, C1, C2, C3);
            GssimCalculator gssimCalc = new GssimCalculator(gssimParams);
            AssessResult res = new AssessResult();
            if (component.HasFlag(UseComponent.Luma))
            {
                res.Luma = gssimCalc.CalcMeanGssim(LumaReference, LumaDistorted);
            }
            if (component.HasFlag(UseComponent.Cb))
            {
                res.Cb = gssimCalc.CalcMeanGssim(CbReference, CbDistorted);
            }
            if (component.HasFlag(UseComponent.Cr))
            {
                res.Cr = gssimCalc.CalcMeanGssim(CrReference, CrDistorted);
            }
            return res;
        }
Пример #6
0
        /// <summary>
        /// Assess Mean G-SSIM of a distorted bitmap with the reference bitmap
        /// </summary>
        /// <param name="reference">Reference bitmap</param>
        /// <param name="distorted">Distorted bitmap</param>
        /// <param name="component">Specify which components will be assessed, multiple components can be set by using bitwise-or</param>
        /// <exception cref="ArgumentNullException">Thrown when at least one param is null</exception>
        /// <exception cref="ArgumentException">Thrown when the size of the two bitmaps are not illegal for assessment (Sizes are not same, Size too small, etc.)</exception>
        /// <returns>A new AssessResult object indicates the assess results in every specified component.</returns>
        public override AssessResult Assess(Bitmap reference, Bitmap distorted, UseComponent component)
        {
            InitBitmaps(reference, distorted);
            LumaReference = Downscaler.DownscaleByKeepMinLength(LumaReference, ScaleMinLength);
            LumaDistorted = Downscaler.DownscaleByKeepMinLength(LumaDistorted, ScaleMinLength);

            SsimParameters  gssimParams = new SsimParameters(WindowWidth, WindowHeight, C1, C2, C3);
            GssimCalculator gssimCalc   = new GssimCalculator(gssimParams);
            AssessResult    res         = new AssessResult();

            if (component.HasFlag(UseComponent.Luma))
            {
                res.Luma = gssimCalc.CalcMeanGssim(LumaReference, LumaDistorted);
            }
            if (component.HasFlag(UseComponent.Cb))
            {
                res.Cb = gssimCalc.CalcMeanGssim(CbReference, CbDistorted);
            }
            if (component.HasFlag(UseComponent.Cr))
            {
                res.Cr = gssimCalc.CalcMeanGssim(CrReference, CrDistorted);
            }
            return(res);
        }
Пример #7
0
        /// <summary>
        /// Assess Mean MS-SSIM of a distorted bitmap with the reference bitmap
        /// </summary>
        /// <param name="reference">Reference bitmap</param>
        /// <param name="distorted">Distorted bitmap</param>
        /// <param name="component">Specify which components will be assessed, multiple components can be set by using bitwise-or</param>
        /// <exception cref="ArgumentNullException">Thrown when at least one param is null</exception>
        /// <exception cref="ArgumentException">Thrown when the size of the two bitmaps are not illegal for assessment (Sizes are not same, Size too small, etc.)</exception>
        /// <returns>A new AssessResult object indicates the assess results in every specified component.</returns>
        public override AssessResult Assess(Bitmap reference, Bitmap distorted, UseComponent component)
        {
            InitBitmaps(reference, distorted);
            LumaReference = Downscaler.DownscaleByKeepMinLength(LumaReference, ScaleMinLength);
            LumaDistorted = Downscaler.DownscaleByKeepMinLength(LumaDistorted, ScaleMinLength);

            AssessResult res = new AssessResult();
            if (component.HasFlag(UseComponent.Luma))
            {
                res.Luma = GetComponentQuality(LumaReference, LumaDistorted);
            }
            if (component.HasFlag(UseComponent.Cb))
            {
                res.Cb = GetComponentQuality(CbReference, CbDistorted);
            }
            if (component.HasFlag(UseComponent.Cr))
            {
                res.Cr = GetComponentQuality(CrReference, CrDistorted);
            }
            return res;
        }