Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
0
 private IList <IntegerSegment> FindVerticalZeroSegments(int ix, int minimalSegmentLength)
 {
     return(IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetVerticalStripe(ix)), minimalSegmentLength));
 }
Exemplo n.º 3
0
 private IList <IntegerSegment> FindHorizontalZeroSegments(int iy, int minimalSegmentLength)
 {
     return(IntegerSegmentUtils.FindZeroSegments(FlatImage.GetDerivative(this.GetHorizontalStripe(iy)), minimalSegmentLength));
 }