Example #1
0
        public void DetectBlobsSingle()
        {
            // single blob
            string[] inGrid =
            {
                "XXXXXX",
                "X..XXX",
                "X....X",
                "X.XXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "@@@@@@",
                "@AA@@@",
                "@AAAA@",
                "@A@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            var compareBlobs = new List<BlobMap.Blob> { new BlobMap.Blob(new Rect(1, 1, 4, 3), 7) };

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Example #2
0
        public void DetectBlobsNone()
        {
            // no blob
            string[] inGrid =
            {
                "XXXXXX",
                "XXXXXX",
                "XXXXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "@@@@@@",
                "@@@@@@",
                "@@@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            List<BlobMap.Blob> compareBlobs = new List<BlobMap.Blob>();

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Example #3
0
        public void DetectBlobsCorners()
        {
            // diagonal attached blobs
            string[] inGrid =
            {
                "..XX..",
                "..XX..",
                "XXXXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "AA@@BB",
                "AA@@BB",
                "@@@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            var compareBlobs = new List<BlobMap.Blob>
            {
                new BlobMap.Blob(new Rect(0, 0, 2, 2), 4),
                new BlobMap.Blob(new Rect(4, 0, 2, 2), 4),
            };

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Example #4
0
        /// <summary>
        /// Fill the holes in the binary image
        /// </summary>
        /// <param name="b"></param>
        protected Bitmap FillHoles(Bitmap b)
        {
            // clone and invert the bitmap ( which turns holes into islands ! )

            Bitmap nb = new Bitmap(b);

            // invert it

            BlobMap.InvertImage(nb);

            // create a temporary blob map which will capture the former holes as islands

            BlobMap bm = new BlobMap(nb);

            // fill holes

            bm.FillHoles(nb);

            // invert image with holes filled again !

            BlobMap.InvertImage(nb);

            // return the image with the holes fill

            return(nb);
        }
Example #5
0
 protected override bool AttemptBlob(T map, BlobMap blobMap, int blobIdx)
 {
     //TODO: blob can be placed if it does not touch the mainland
     //but it does touch water that touches the mainland
     return(false);
 }
Example #6
0
        /// <summary>
        /// Create a new image based on the given sub image with the candidate red eye removed
        /// </summary>
        /// <param name="b"></param>
        public Bitmap ProcessImage(Bitmap b)
        {
            // temporary images used to remove red eye

            Bitmap rednessMask = null, rednessThreshold = null, falseColor = null, noSmallIslands = null, noHoles = null, blured = null;

            // the image to return

            Bitmap newImage = null;

            try
            {
                // get a CIEMap of the image and the min/max CIE L values for the image

                double minL, maxL;

                CIELab[] cieMap = this.GetCIELABImage(b, out minL, out maxL);

                // get redness mask image

                rednessMask = this.GetMaskImage(cieMap, b.Width, b.Height);

                // get a threshold of the redness mask

                rednessThreshold = this.Threshold(rednessMask);

                // create a blob map from the threasholded image

                BlobMap blobmap = new BlobMap(rednessThreshold);

                // create a false color copy of the thresholded images

                falseColor = (Bitmap)rednessThreshold.Clone();

                blobmap.ColorIslands(falseColor);

                // remove all islands meeting a certain size criteria

                noSmallIslands = (Bitmap)rednessThreshold.Clone();

                blobmap.RemoveIslands(noSmallIslands);

                // create a version with the holes filled

                noHoles = this.FillHoles(noSmallIslands);

                // get a guassian blurred version of the final mask

                float[] kernel = ImageUtility.GetGaussianBlurKernel(3, 15);

                blured = ImageUtility.Convolve(noHoles, kernel, 3);

                // create new image

                newImage = this.GetNewImage(cieMap,                                                                             // CIE Lab image of the source
                                            minL, maxL,                                                                         // min/max CIE L* values in the map
                                            blured);                                                                            // the final mask to be used

                // return new image

                return(newImage);
            }
            catch (Exception)
            {
            }
            finally
            {
                // cleanup any temporaries used


                if (rednessMask != null)
                {
                    rednessMask.Dispose();
                }
                if (rednessThreshold != null)
                {
                    rednessThreshold.Dispose();
                }
                if (falseColor != null)
                {
                    falseColor.Dispose();
                }
                if (noSmallIslands != null)
                {
                    noSmallIslands.Dispose();
                }
                if (noHoles != null)
                {
                    noHoles.Dispose();
                }
                if (blured != null)
                {
                    blured.Dispose();
                }
            }

            // return new image

            return(newImage);
        }