Пример #1
0
        public bool CompareWithFragmentWithTolerance(FlatImage fragment, int startX, int startY)
        {
            for (var x = 0; x < fragment.Width; x++)
            {
                for (var y = 0; y < fragment.Height; y++)
                {
                    if (MidDiff(this.pixels[x + startX, y + startY], fragment.pixels[x, y]) > 2)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public Models.Geometry.Rectangle FindBoundsOfInnerImage()
        {
            // TODO: implement more robust algorithm
            // TODO: add more tests for this method
            const int minimalSegmentLength = 8;

            var stripeCH = IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetHorizontalStripe(this.Height / 2)), minimalSegmentLength);
            var stripeCV = IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetVerticalStripe(this.Width / 2)), minimalSegmentLength);

            // TODO: optimize code
            for (var iy = 1 * this.Height / 4; iy < 3 * this.Height / 4; iy += minimalSegmentLength)
            {
                stripeCH = IntegerSegmentUtils.IntersectionOfSegments(new[]
                {
                    stripeCH,
                    FindHorizontalZeroSegments(iy, minimalSegmentLength)
                });
            }

            for (var ix = 1 * this.Width / 4; ix < 3 * this.Width / 4; ix += minimalSegmentLength)
            {
                stripeCV = IntegerSegmentUtils.IntersectionOfSegments(new[]
                {
                    stripeCV,
                    FindVerticalZeroSegments(ix, minimalSegmentLength)
                });
            }

            if ((stripeCH.Count > 1) && (stripeCV.Count > 1))
            {
                var maxH = IntegerSegmentUtils.SegmentsWithMaxDistance(stripeCH);
                var maxV = IntegerSegmentUtils.SegmentsWithMaxDistance(stripeCV);

                return(new Geometry.Rectangle
                {
                    X = maxH.Start + 1,
                    Y = maxV.Start + 1,
                    Width = maxH.End - maxH.Start - 2,
                    Height = maxV.End - maxV.Start - 2,
                });
            }
            else
            {
                return(new Geometry.Rectangle());
            }
        }
Пример #3
0
 private IList <IntegerSegment> FindVerticalZeroSegments(int ix, int minimalSegmentLength)
 {
     return(IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetVerticalStripe(ix)), minimalSegmentLength));
 }
Пример #4
0
 private IList <IntegerSegment> FindHorizontalZeroSegments(int iy, int minimalSegmentLength)
 {
     return(IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetHorizontalStripe(iy)), minimalSegmentLength));
 }