public static SegmentationCoord Segment(TiffImage image, int N, float threshold)
        {
            CreatePixelMap(image, N);
            GrowUntilNoChange(threshold, N);

            return((x, y) => FindRoot(pixelMap[x][y]));
        }
Example #2
0
        // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
        public void overlaySegmentation(string filename, int N, Segmentation segmentation)
        {
            var newImage = new TiffImage(1 << N, 1 << N);

            var BLUE = unchecked ((int)0xFFFF0000); // ABGR

            for (var y = 0; y < newImage.height; y++)
            {
                for (var x = 0; x < newImage.width; x++)
                {
                    var a = segmentation(x, y);
                    if (x == newImage.width - 1 || x == 0 || !segmentation(x, y).Equals(segmentation(x - 1, y)) ||
                        y == newImage.height - 1 || y == 0 || !segmentation(x, y).Equals(segmentation(x, y - 1)))
                    {
                        newImage.setColour(new Coordinate(x, y), BLUE);
                    }
                    else
                    {
                        newImage.setColour(new Coordinate(x, y), getColour(new Coordinate(x, y)));
                    }
                }
            }

            newImage.saveImage(filename);
        }
        // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
        public void OverlaySegmentation(string filename, int N, Segment[,] segmentation)
        {
            var newImage = new TiffImage(1 << N, 1 << N);

            var BLUE = unchecked ((int)0xFFFF0000); // ABGR

            for (var y = 0; y < newImage.height; y++)
            {
                for (var x = 0; x < newImage.width; x++)
                {
                    //var a = segmentation(x, y);
                    //var b = segmentation(x - 1, y);
                    //var c = segmentation(x, y - 1);
                    if (x == newImage.width - 1 || x == 0 || !segmentation[x, y].Equals(segmentation[x - 1, y]) ||
                        y == newImage.height - 1 || y == 0 || !segmentation[x, y].Equals(segmentation[x, y - 1]))
                    {
                        newImage.SetColour(x, y, BLUE);
                    }
                    else
                    {
                        newImage.SetColour(x, y, GetColour(x, y));
                    }
                }
            }

            newImage.SaveImage(filename);
        }
Example #4
0
        static int Main(string[] args)
        {
            // filepath to the image
            string imagePath = args[0];

            TiffImage image = new TiffImage(imagePath);

            // testing using sub-image of size 32x32 pixels
            int N = 5;

            // increasing this threshold will result in more segment merging and therefore fewer final segments
            double threshold = 800.0;

            Segmentor segmentor = new Segmentor(N, threshold);

            // determine the segmentation for the (top left corner of the) image (2^N x 2^N) pixels
            Segment[,] segmentation = segmentor.SegmentImage(image);


            // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
            image.OverlaySegmentation("csharp-segmented.tif", N, segmentation);

            // return an integer exit code
            return(0);
        }
 //The Constructor for the Module, acept image, the size of the image and the threshhold as parameters
 public SegmentationModule(TiffImage image, int size, float threshold)
 {
     if (size > 0)
     {
         this.size = size;
     }
     this.image            = image;
     this.currentThreshold = threshold;
     this.pixelArray       = CreatePixelArray(this.size);
     moduleSegmentation    = new Dictionary <Segment, Segment>();
 }
Example #6
0
        static void Main(string[] args)
        {
            var image = new TiffImage("..\\TestImages\\L15-3792E-1717N-Q4.tif");

            var N         = 5;
            var threshold = 800.0F;

            var segmentation = new SegmentationService(image, N, threshold);

            image.overlaySegmentation("segmentedN" + N + ".tif", N, segmentation);
        }
Example #7
0
 // Initialise the segmentation with a Segment for every pixel in the image
 private void CreateSegmentationFromImage(TiffImage image)
 {
     // allocate and initialise segmentation
     segmentation = new Segment[size, size];
     for (int x = 0; x < size; x++)
     {
         for (int y = 0; y < size; y++)
         {
             Pixel pixel = new Pixel(x, y, image.GetColourBands(x, y));
             segmentation[x, y] = new Segment(pixel);
         }
     }
 }
Example #8
0
        // Loop over every segment in dither order and attempt to grow it until no change in the segmentation
        // attempt to grow a segment
        // get the neighbour segments
        // if their are no neighbours we are done and we can bail out
        // get the best neighbour segments
        // if there are no best neighbours then bail out and indicate that nothing has changed
        // get the mutually optimal neighbour segments
        // if none do "gradient descent" merging
        // else merge the optimal neighbours and exit, indicate that something has changed
        public Segment[,] SegmentImage(TiffImage image)
        {
            // Build an initial segmentation
            CreateSegmentationFromImage(image);

            bool unfinished = true;

            while (unfinished)
            {
                unfinished = TryGrowAllSegments();
            }
            return(segmentation);
        }
        public static void CreatePixelMap(TiffImage image, float N)
        {
            pixelMap = new Pixel[(int)Math.Pow(2, N)][];

            for (int i = 0; i < Math.Pow(2, N); i++)
            {
                pixelMap[i] = new Pixel[(int)Math.Pow(2, N)];

                for (int j = 0; j < Math.Pow(2, N); j++)
                {
                    pixelMap[i][j] = new Pixel(Tuple.Create(i, j), image.getColourBands(i, j));
                }
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            var image = new TiffImage(args[0]);

            var N = 5;

            var threshold = 800.0F;

            var segmentation = SegmentationModule.Segment(image, N, threshold);

            image.overlaySegmentation("segmented.tif", N, segmentation);

            return; // We're all good in the hood
        }
Example #11
0
        static void Main(string[] args)
        {
            // load a Tiff image
            var image = new TiffImage(args[0]);

            // testing using sub-image of size 32x32 pixels
            var N = 5;

            // increasing this threshold will result in more segment merging and therefore fewer final segments
            var threshold = 800.0f;

            // determine the segmentation for the (top left corner of the) image (2^N x 2^N) pixels
            var segmentation = new Segmenter(image, N, threshold);

            // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
            image.overlaySegmentation("segmented.tif", N, segmentation);
        }
        static void Main(string[] args)
        {
            // the size for the image
            int       size  = 6;
            TiffImage image = new TiffImage("D:/SegmentationSkeleton/TestImages/L15-3662E-1902N-Q4.tif");
            //passing the image, the size (2*size x 2*size image ) and the threshhol into the segmentation module
            SegmentationModule module1 = new SegmentationModule(image, size, 800);

            //grow the Segmentation in the module from an emty dictionary
            module1.GrowUntilNoChange();
            // determine the segmentation for the (top left corner of the) image (2^N x 2^N) pixels
            Segmentation segmentation = new Segmentation(module1.Segment);

            // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
            image.overlaySegmentation("C#output.tif", size, segmentation);
            // Notify the Console when the output is finished.
            Console.WriteLine("finish");

            Console.ReadKey();
        }
Example #13
0
        static void Main(string[] args)
        {
            // load a Tiff image
            // FIX HERE
            TiffImage image = new TiffImage("..//TestImages//L15-3792E-1717N-Q4.tif");

            // testing using sub-image of N 32x32 pixels
            // let N =5, execution time: 5 secs
            int N = 5;

            // increasing this threshold will result in more segment merging and therefore fewer final segments
            int threshold = 800;

            //passing the image, the N (2*N x 2*N image ) and the threshold into the segmentation module
            SegmentationModule segmentation = new SegmentationModule(image, N, threshold);

            //grow the Segmentation in the module from an emty dictionary
            segmentation.GrowUntilNoChange();

            // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
            image.overlaySegmentation("csharpSegmented.tif", N, segmentation.Segment);
        }
Example #14
0
 public Segmenter(TiffImage image, int N, float threshold)
 {
     this.Image     = image;
     this.N         = N;
     this.Threshold = threshold;
 }