Ejemplo n.º 1
0
        /// <summary>
        /// Get the quality in one of the components(Y/Cb/Cr)
        /// </summary>
        /// <param name="valueRef">component value of reference image</param>
        /// <param name="valueDis">component value of distorted image</param>
        /// <returns>quality</returns>
        private double GetComponentQuality(double[,] valueRef, double[,] valueDis)
        {
            double quality = 1;

            for (int scaleLevel = 1; scaleLevel <= MaxScaleLevel; scaleLevel++)
            {
                if (scaleLevel != 1)
                {
                    valueRef = Downscaler.DownscaleByFactor(valueRef, 2);
                    valueDis = Downscaler.DownscaleByFactor(valueDis, 2);
                }
                SsimParameters ssimParams = new SsimParameters(WindowWidth, WindowHeight, C1, C2, C3, Alpha[scaleLevel], Beta[scaleLevel], Gamma[scaleLevel]);
                quality *= new SsimCalculator(ssimParams).CalcMeanSsim(valueRef, valueDis);
            }
            return(quality);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the quality in one of the component(Y/Cb/Cr)
        /// </summary>
        /// <param name="valueRef">component value of reference image</param>
        /// <param name="valueDis">component value of distorted image</param>
        /// <returns>quality</returns>
        private double GetComponentQuality(double[,] valueRef, double[,] valueDis)
        {
            double quality = 1;

            for (int scaleLevel = 1; scaleLevel <= MaxScaleLevel; scaleLevel++)
            {
                if (scaleLevel != 1)
                {
                    valueRef = Downscaler.DownscaleByFactor(valueRef, 2);
                    valueDis = Downscaler.DownscaleByFactor(valueDis, 2);
                }
                SsimParameters ssimParams          = new SsimParameters(WindowWidth, WindowHeight, C1, C2, C3, Alphas[scaleLevel], Betas[scaleLevel], Gammas[scaleLevel]);
                double         intermediateQuality = new SsimCalculator(ssimParams).CalcMeanSsim(valueRef, valueDis);
                // make sure when the image is downscaled to less then 8x8 it can get a meaningful result.
                if (!Double.Equals(intermediateQuality, 0.0))
                {
                    quality *= intermediateQuality;
                }
            }
            return(quality);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }