public void FloodFillTest2(string filename) { var path = GetTestDataPath(filename); var image = new Bitmap(path); var mask = image.ToByteArray(); Assert.IsTrue(mask.Any(x => x == 0)); Assert.IsTrue(mask.Any(x => x == 1)); Assert.IsTrue(mask.Length == image.Width * image.Height); var actual = new Volume2D <byte>(mask, image.Width, image.Height, 1, 1, new Point2D(), new Matrix2()); var contoursFilled = actual.ContoursFilled(); var expected = actual.CreateSameSize <byte>(); expected.Fill(contoursFilled, (byte)1); var stopwatch = Stopwatch.StartNew(); FillPolygon.FloodFillHoles(actual.Array, expected.DimX, expected.DimY, 0, 0, 1, 0); stopwatch.Stop(); actual.SaveBrushVolumeToPng(@"C:\Temp\Actual.png"); expected.SaveBrushVolumeToPng(@"C:\Temp\Expected.png"); Assert.AreEqual(expected.Array, actual.Array, "Extracting filled contours and filling those should give the same result as flood filling holes."); var contoursWithHoles = actual.ContoursWithHoles(); var filledWithHoles = actual.CreateSameSize <byte>(); filledWithHoles.Fill(contoursWithHoles, (byte)1); Assert.AreEqual(actual.Array, filledWithHoles.Array, "Extracting contours with holes and filling those in should not change the mask"); }
/// <summary> /// Creates volume of the same size as the argument, with pixel values equal to 1 for all /// pixels that have the given <paramref name="foregroundId"/>, and pixel value 0 for all others. /// </summary> /// <param name="volume"></param> /// <param name="foregroundId">The voxel value that should be considered foreground.</param> /// <returns></returns> private static Volume2D <byte> CreateBinaryVolume(Volume2D <byte> volume, byte foregroundId) { var binaryVolume = volume.CreateSameSize <byte>(); var binaryArray = binaryVolume.Array; var volumeArray = volume.Array; for (var index = 0; index < volumeArray.Length; index++) { binaryArray[index] = volumeArray[index] == foregroundId ? (byte)1 : (byte)0; } return(binaryVolume); }