Esempio n. 1
0
        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>
 /// Applies flood filling to all holes in the given volume.
 /// </summary>
 /// <param name="volume"></param>
 /// <param name="foregroundId"></param>
 /// <param name="backgroundId"></param>
 public static void FillHoles(
     this Volume2D <byte> volume,
     byte foregroundId = ModelConstants.MaskForegroundIntensity,
     byte backgroundId = ModelConstants.MaskBackgroundIntensity)
 => FillPolygon.FloodFillHoles(volume, foregroundId, backgroundId);