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()}"); }
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()}"); }
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); }
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); }
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); }
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"); }
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); }
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); }