Example #1
0
        private static Hole FindHole(HoleFinder holeFinder)
        {
            var hole = holeFinder.FindHole();

            if (hole != null)
            {
                Console.WriteLine($"Total holes pixels: {hole.HolePixels.Count}");
                Console.WriteLine($"Total boundary pixels: {hole.Boundary.Count}");
                foreach (var pt in hole.Boundary)
                {
                    Console.Write($"({pt.X}, {pt.Y}), ");
                }
                Console.WriteLine();
            }

            return(hole);
        }
Example #2
0
        public void BasicSanityTest()
        {
            // arrange
            var t = new float[, ]
            {
                { 0.1F, 0.2F, 0.3F },
                { 0.1F, -1F, 0.3F },
                { 0.1F, 0.2F, 0.3F }
            };

            var holeFinder = new HoleFinder(new ImageMatrix(t));

            // act
            var hole = holeFinder.FindHole(new MooreTrace());

            // assert
            Assert.AreEqual(hole.Boundary.Count, 8);
            Assert.AreEqual(hole.HolePixels.Count, 1);
        }
Example #3
0
        public void Edges8Test()
        {
            // arrange
            var t = new float[, ]
            {
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
            };

            var holeFinder = new HoleFinder(new ImageMatrix(t));

            // act
            var hole = holeFinder.FindHole(new MooreTrace());

            // assert
            Assert.IsNull(hole);
        }
Example #4
0
        public void DumbbellShapeTest()
        {
            // arrange
            var t = new float[, ]
            {
                { 0.1F, 0.2F, 0.2F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.2F, -1F, 0.3F, 0.4F, 0.5F },
                { 0.1F, -1F, -1F, -1F, -1F, 0.4F, 0.5F },
                { 0.1F, -1F, -1F, -1F, -1F, 0.2F, 0.5F },
                { 0.1F, 0.2F, 0.2F, 0.2F, 0.2F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.2F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.2F, 0.2F, 0.3F, 0.4F, 0.5F }
            };

            var holeFinder = new HoleFinder(new ImageMatrix(t));

            // act
            var hole = holeFinder.FindHole(new MooreTrace());

            // assert
            Assert.AreEqual(hole.Boundary.Count, 18);
            Assert.AreEqual(hole.HolePixels.Count, 9);
        }
Example #5
0
        public void Edges7Test()
        {
            // arrange
            var t = new float[, ]
            {
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { -1F, -1F, -1F, -1F, -1F, -1F, -1F },
                { 0.1F, 0.2F, 0.3F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.3F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.3F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.3F, 0.2F, 0.3F, 0.4F, 0.5F },
                { 0.1F, 0.2F, 0.3F, 0.2F, 0.3F, 0.4F, 0.5F }
            };

            var holeFinder = new HoleFinder(new ImageMatrix(t));

            // act
            var hole = holeFinder.FindHole(new MooreTrace());

            // assert
            Assert.AreEqual(hole.Boundary.Count, 7);
            // Assert.AreEqual(hole.HolePixels.Count, 4); - will fail, CoveringRectangle algorithm can't deal with this scenario
        }
Example #6
0
        static void Main(string[] args)
        {
            ImageHandler imgHandler = null;
            HoleFinder   holeFinder = null;
            HoleFixer    holeFixer  = null;

            string key = "";

            while (key != "q")
            {
                Console.WriteLine("Please choose what to do:");
                Console.WriteLine(" (L)oad an image ");
                if (imgHandler != null)
                {
                    Console.WriteLine(" (E)nter a hole location ");
                }
                if (imgHandler?.Matrix.IsHoled == true)
                {
                    Console.WriteLine(" (F)ind hole ");
                }
                if (holeFinder?.Hole != null)
                {
                    Console.WriteLine(" (M)end hole ");
                }
                if (imgHandler != null)
                {
                    Console.WriteLine(" (S)ave the image ");
                }
                Console.WriteLine(" (Q)uit ");

                key = Console.ReadLine();

                switch (key.ToUpper())
                {
                case "L":
                    Load(ref imgHandler, ref holeFinder, ref holeFixer);
                    break;

                case "E":
                    if (imgHandler != null)
                    {
                        EnterHole(imgHandler);
                    }
                    break;

                case "F":
                    if (imgHandler?.Matrix.IsHoled == true)
                    {
                        FindHole(holeFinder);
                    }
                    break;

                case "M":
                    if (imgHandler?.Matrix.IsHoled == true && holeFinder?.Hole != null)
                    {
                        MendHole(holeFinder.Hole, holeFixer);
                        holeFinder.FindHole();     // will set Hole to null if no hole found
                    }
                    break;

                case "S":
                    if (imgHandler != null)
                    {
                        SaveImage(imgHandler);
                    }
                    break;

                case "Q":
                    return;

                default:
                    Console.WriteLine("No such function; Please choose again");
                    break;
                }
                Console.WriteLine();
                Console.WriteLine("***************");
            }
        }