示例#1
0
        /// <summary>
        /// Calculates sizes and other metrics for the given images. Stores
        /// relevant metrics in the result.
        /// </summary>
        /// <param name="result">Comparison result to set metrics on.</param>
        protected void CalculateMetrics(ComparisonResult result)
        {
            // Calculate sizes.
            GraphicsUnit unit       = GraphicsUnit.Pixel;
            RectangleF   masterRect = MasterImage.GetBounds(ref unit);

            this.masterSize = new Size((int)masterRect.Width, (int)masterRect.Height);
            RectangleF sampleRect = SampleImage.GetBounds(ref unit);

            this.sampleSize      = new Size((int)sampleRect.Width, (int)sampleRect.Height);
            this.masterRectangle =
                new Rectangle(0, 0, MasterSize.Width, MasterSize.Height);
            this.sampleRectangle =
                new Rectangle(0, 0, SampleSize.Width, SampleSize.Height);
            this.maxErrorCount = (int)
                                 (MasterPixelCount * Criteria.MaxErrorProportion);

            // Add relevant metrics to comparison result.
            result.SetMasterImagePixelCount(MasterPixelCount);
            result.SetErrorProportion(Criteria.MaxErrorProportion);
        }
示例#2
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public methods.

        /// <summary>Executes the comparison operation.</summary>
        /// <returns>The results of the comparison operation.</returns>
        public ComparisonResult Execute()
        {
            System.Diagnostics.Debug.Assert(this.criteria != null);
            if (MasterImage == null)
            {
                throw new InvalidOperationException("Cannot compare images with null master image");
            }
            if (SampleImage == null)
            {
                throw new InvalidOperationException("Cannot compare images with null sample image");
            }

            ComparisonAlgorithm algorithm = SelectAlgorithm();

            algorithm.Criteria    = Criteria;
            algorithm.MasterImage = MasterImage;
            algorithm.SampleImage = SampleImage;

            ComparisonResult result = algorithm.Execute();

            result.FinishedComparison();

            return(result);
        }
示例#3
0
        /// <summary>
        /// Checks whether a pixel has an acceptable neighbouring value.
        /// </summary>
        private unsafe void CheckPixel(int x, int y,
                                       ComparisonResult result, ref int errorCount)
        {
            //
            // Locals used to mark whether we're below or above range.
            // If both, below wins arbitrarily.
            //
            float belowDistance = 0;
            float aboveDistance = 0;
            bool  belowFound    = false;
            bool  aboveFound    = false;

            PixelData *masterPixel = GetPixelDataAt(
                masterData, x, y, MasterScanLineWidth);

            for (int i = 0; i < positions.Length; i++)
            {
                PositionDelta d       = positions[i];
                int           sampleX = x + d.X;
                int           sampleY = y + d.Y;
                if (sampleX < 0 || sampleX > SampleSize.Width)
                {
                    continue;
                }
                if (sampleY < 0 || sampleY > SampleSize.Height)
                {
                    continue;
                }

                PixelData *samplePixel = GetPixelDataAt(
                    sampleData, sampleX, sampleY, SampleScanLineWidth);

                float distance = ColorUtils.GetSquareLinearDistance(
                    masterPixel, samplePixel);

                if (minSquareDistance > distance)
                {
                    aboveFound    = true;
                    aboveDistance = distance;
                }
                else if (distance > maxSquareDistance)
                {
                    belowFound    = true;
                    belowDistance = distance;
                }
                else
                {
                    // Acceptable value found.
                    return;
                }
            }

            if (aboveFound)
            {
                result.AddDifference(
                    new ColorDistanceDifference(x, y,
                                                minSquareDistance, aboveDistance,
                                                ValueComparison.AboveValue));
            }
            else
            {
                System.Diagnostics.Debug.Assert(belowFound);
                result.AddDifference(new ColorDistanceDifference(
                                         x, y, maxSquareDistance, belowDistance,
                                         ValueComparison.BelowValue));
            }
            errorCount++;
        }