Example #1
0
 internal Label GetRoot()
 {
     if (this.Root != this)
     {
         this.Root = this.Root.GetRoot();
     }
     return this.Root;
 }
        public Dictionary<int, List<Point>> Find()
        {
            Point currentPoint;
            Label currentLabel = new Label(0);
            int labelCount = 0;
            Dictionary<int, int> neighboringLabels;
            Dictionary<int, Label> allLabels = new Dictionary<int, Label>();

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    currentPoint = new Point(j, i);

                    if (binaryArray[j, i] != 0)
                    {
                        neighboringLabels = GetNeighboringLabels(currentPoint);

                        if (neighboringLabels.Count == 0)
                        {
                            ++labelCount;
                            currentLabel.ID = labelCount;
                            allLabels.Add(currentLabel.ID, new Label(currentLabel.ID));
                        }
                        else
                        {
                            foreach (int label in neighboringLabels.Keys)
                            {
                                currentLabel.ID = label;//set currentLabel to the first label found in neighboring cells
                                break;
                            }
                            MergeLabels(currentLabel.ID, neighboringLabels, allLabels);
                        }
                        componentArray[j, i] = currentLabel.ID;
                    }
                }
            }

            Dictionary<int, List<Point>> Patterns = AggregatePatterns(allLabels);

            return Patterns;
        }