private void startTracking()
        {
            Bitmap[] images = new Bitmap[11];

            images[0]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C1.png"));
            images[1]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C2.png"));
            images[2]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\MergingTest.png"));
            images[3]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C4.png"));
            images[4]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C5.png"));
            images[5]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C6.png"));
            images[6]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C7.png"));
            images[7]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C8.png"));
            images[8]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C9.png"));
            images[9]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C10.png"));
            images[10] = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C11.png"));

            Tracking t = new Tracking();

            for (int i = 1; i < 11; i++)
            {
                // Repositioning finding and executing difference between the two images

                int[] positions = Matching_Robinson.RobinsonRepositioning(images[0], images[i]);

                Map resultDifference = DifferenceComputation.getManhattan(images[0], images[i], positions);

                List <Cluster> frameBlobs = FindObjects(resultDifference);

                Console.WriteLine("Tracking " + i + ": " + frameBlobs.Count + " blobs encountered");

                if (t.isEmpty())
                {
                    t.firstScan(frameBlobs, i);
                }
                else
                {
                    t.assignBlobs(frameBlobs, i);
                }

                Console.WriteLine();
            }

            List <List <Cluster> > results = t.getTracking();

            // Tracking results siso

            Console.WriteLine();
            Console.WriteLine(results.Count + " different blobs being tracked");

            List <double> numberOfColonies = new List <double>();

            ChartHandler ch = new ChartHandler();
            string       p, dir;

            string[] title;

            for (int i = 0; i < results.Count; i++)
            {
                double[] data = new double[results.ElementAt(i).Count];

                dir = (System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CharTest", "ClusterN" + i));
                Directory.CreateDirectory(dir);

                p = "ClusterTrack_" + i.ToString() + ".txt";

                FileStream f = File.Create(System.IO.Path.Combine(dir, p));

                f.Close();
                File.AppendAllText(System.IO.Path.Combine(dir, p), "Blob " + i + ": " + results.ElementAt(i).Count + " steps tracked" + Environment.NewLine);
                File.AppendAllText(System.IO.Path.Combine(dir, p), Environment.NewLine);

                for (int j = 0; j < results.ElementAt(i).Count; j++)
                {
                    data[j] = results.ElementAt(i).ElementAt(j).getSize();

                    File.AppendAllText(System.IO.Path.Combine(dir, p), "Track " + j + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    ID = " + results.ElementAt(i).ElementAt(j).getId() + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    Size = " + results.ElementAt(i).ElementAt(j).getSize() + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    Encounter step = " + results.ElementAt(i).ElementAt(j).getStep() + Environment.NewLine);

                    if (results.ElementAt(i).ElementAt(j).getFather() != -1)
                    {
                        File.AppendAllText(System.IO.Path.Combine(dir, p), "    Merged to branch : " + results.ElementAt(i).ElementAt(j).getFather() + Environment.NewLine);
                    }
                    if (results.ElementAt(i).ElementAt(j).getBranches().Count > 0)
                    {
                        for (int n = 0; n < results.ElementAt(i).ElementAt(j).getBranches().Count; n++)
                        {
                            File.AppendAllText(System.IO.Path.Combine(dir, p), "    Branch with ID: " + results.ElementAt(i).ElementAt(j).getBranches().ElementAt(n).Last().getId() + " added");

                            if (results.ElementAt(i).ElementAt(j).getBranches().ElementAt(n).Last().hasMergedWithDifferent())
                            {
                                File.AppendAllText(System.IO.Path.Combine(dir, p), " from a different colony." + Environment.NewLine);
                            }
                            else
                            {
                                File.AppendAllText(System.IO.Path.Combine(dir, p), " from the same colony." + Environment.NewLine);
                            }
                        }
                    }

                    File.AppendAllText(System.IO.Path.Combine(dir, p), Environment.NewLine);

                    if (numberOfColonies.Count <= results.ElementAt(i).ElementAt(j).getStep())
                    {
                        for (int n = numberOfColonies.Count; n < results.ElementAt(i).ElementAt(j).getStep() - 1; n++)
                        {
                            numberOfColonies.Add(0);
                        }

                        numberOfColonies.Add(1);
                    }
                    else
                    {
                        numberOfColonies[results.ElementAt(i).ElementAt(j).getStep() - 1]++;
                    }
                }

                title = new string[] { "Colony " + results.ElementAt(i).ElementAt(0).getId() + " Size evolution over time", " Size (pixels) ", " Capture " };
                p     = "SizeChart.png";
                ch.barCharConstruct(data, System.IO.Path.Combine(dir, p), title);
            }

            p     = "ColonyChart.png";
            dir   = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CharTest");
            title = new string[] { "Population evolution", " Number of colonies", " Capture " };
            ch.barCharConstruct(numberOfColonies.ToArray(), System.IO.Path.Combine(dir, p), title);

            this.Hide();
        }
Exemplo n.º 2
0
        private void startTracking()
        {
            Bitmap[] images = new Bitmap[11];

            images[0]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C1.png"));
            images[1]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C2.png"));
            images[2]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\MergingTest.png"));
            images[3]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C4.png"));
            images[4]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C5.png"));
            images[5]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C6.png"));
            images[6]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C7.png"));
            images[7]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C8.png"));
            images[8]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C9.png"));
            images[9]  = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C10.png"));
            images[10] = new Bitmap(System.Drawing.Image.FromFile(@"Resources\Captures\C11.png"));

            Tracking t = new Tracking();

            for (int i = 1; i < 11; i++)
            {
                // Repositioning finding and executing difference between the two images

                int[] positions = Matching_Robinson.RobinsonRepositioning(images[0], images[i]);

                int[,] resultDifference = DifferenceComputation.getManhattan(images[0], images[i], positions);

                List <Cluster> frameBlobs = FindObjects(resultDifference);

                Console.WriteLine("Tracking " + i + ": " + frameBlobs.Count + " blobs encountered");

                if (t.isEmpty())
                {
                    t.firstScan(frameBlobs, i);
                }
                else
                {
                    t.assignBlobs(frameBlobs, i);
                }

                Console.WriteLine();
            }

            List <List <Cluster> > results = t.getTracking();

            // Tracking results siso

            Console.WriteLine();
            Console.WriteLine(results.Count + " different blobs being tracked");

            for (int i = 0; i < results.Count; i++)
            {
                double[] data = new double[results.ElementAt(i).Count];

                string dir = (System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CharTest", "ClusterN" + i));
                Directory.CreateDirectory(dir);

                string p = "ClusterTrack_" + i.ToString() + ".txt";

                FileStream f = File.Create(System.IO.Path.Combine(dir, p));

                f.Close();
                File.AppendAllText(System.IO.Path.Combine(dir, p), "Blob " + i + ": " + results.ElementAt(i).Count + " steps tracked" + Environment.NewLine);
                File.AppendAllText(System.IO.Path.Combine(dir, p), Environment.NewLine);

                for (int j = 0; j < results.ElementAt(i).Count; j++)
                {
                    data[j] = results.ElementAt(i).ElementAt(j).getSize();

                    File.AppendAllText(System.IO.Path.Combine(dir, p), "Track " + j + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    ID = " + results.ElementAt(i).ElementAt(j).getId() + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    Size = " + results.ElementAt(i).ElementAt(j).getSize() + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), "    Encounter step = " + results.ElementAt(i).ElementAt(j).getStep() + Environment.NewLine);
                    File.AppendAllText(System.IO.Path.Combine(dir, p), Environment.NewLine);
                }

                ChartHandler ch = new ChartHandler();
                ch.barCharConstruct(data, i, dir);
            }

            this.Hide();
        }