Ejemplo n.º 1
0
        public void ShrinksImagesToHalfItsSize()
        {
            var sampleImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 0, 0, 0, 0, 0 },
            });

            var expected = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 0 },
            });

            var result = Shrinker.ShrinkByHalf(sampleImage);

            result.Should().Be(expected,
                               $"result:\r\n{result.ToMatrixString()}\r\n should be as expected:\r\n{expected.ToMatrixString()}");
        }
Ejemplo n.º 2
0
        public void AppliesThinningOnImage()
        {
            var structuringElement = new StructuringElement(
                new[, ]
            {
                { 0, 0, -1 },
                { 1, 1, -1 },
                { -1, -1, -1 }
            });

            var inputImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 1, 1, 1 },
                { 1, 1, 1 }
            });

            var expected = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 1, 0, 0 },
                { 1, 1, 1 }
            });

            var structuringElements = new[] { structuringElement };
            var result = Thinner.Thinning(inputImage, structuringElements);

            result.Should().Be(
                expected,
                $"result:\r\n{result.ToMatrixString()}\r\n should be as expected:\r\n{expected.ToMatrixString()}");
        }
Ejemplo n.º 3
0
        public void InterpretsMatrixCoordinatesCorrectly()
        {
            var sampleImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 1, 0 },
                { 1, 0, 1 },
                { 1, 0, 0 }
            });

            // first row
            int m = 0;

            sampleImage[m, 0].Should().Be(BinaryImage.White);
            sampleImage[m, 1].Should().Be(BinaryImage.Black);
            sampleImage[m, 2].Should().Be(BinaryImage.White);

            // second row: m=1
            m = 1;
            sampleImage[m, 0].Should().Be(BinaryImage.Black);
            sampleImage[m, 1].Should().Be(BinaryImage.White);
            sampleImage[m, 2].Should().Be(BinaryImage.Black);

            // third row: m=2
            m = 2;
            sampleImage[m, 0].Should().Be(BinaryImage.Black);
            sampleImage[m, 1].Should().Be(BinaryImage.White);
            sampleImage[m, 2].Should().Be(BinaryImage.White);
        }
Ejemplo n.º 4
0
        public void ClonesImages()
        {
            var firstImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 1, 1, 0 },
                { 0, 0, 1 }
            });

            var secondImage = firstImage.Clone();

            firstImage.Should().Be(secondImage);
        }
Ejemplo n.º 5
0
        public void WritesImageToMatrixString()
        {
            const string Expected = "010\r\n110\r\n001";

            var sampleImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 1, 0 },
                { 1, 1, 0 },
                { 0, 0, 1 }
            });

            string result = sampleImage.ToMatrixString();

            result.Should().Be(Expected);
        }
Ejemplo n.º 6
0
        public void GetNeighborMatrixFromPosition()
        {
            var sampleImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 1, 1, 1, 1, 0 },
                { 0, 0, 0, 0, 0, 0 },
            });

            sampleImage.GetNeighborMatrixFromPosition(0, 0, 2).ToString().Should().Be("00\r\n01");
            sampleImage.GetNeighborMatrixFromPosition(1, 0, 2).ToString().Should().Be("01\r\n01");
            sampleImage.GetNeighborMatrixFromPosition(0, 1, 2).ToString().Should().Be("00\r\n11");
            sampleImage.GetNeighborMatrixFromPosition(1, 1, 2).ToString().Should().Be("11\r\n11");
        }
Ejemplo n.º 7
0
        public void ComparesTwoImages()
        {
            var firstImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 0 }
            });

            var secondImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 0 }
            });

            firstImage.Should().Be(secondImage);
        }
Ejemplo n.º 8
0
        public void CropsLargeImages()
        {
            var sampleImage = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 1, 0, 0 },
                { 0, 0, 0, 1, 1, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 0, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            var expected = BinaryImage.FromByteArray(
                new byte[, ]
            {
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 0, 0 },
                { 0, 0, 0, 1, 1, 1, 0, 0 },
                { 0, 0, 1, 1, 1, 1, 0, 0 },
                { 0, 0, 0, 1, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            var result = Cropper.CropAroundFigures(sampleImage);

            result.Should().Be(expected);
        }