Пример #1
0
 public static void Split_KCluster(int K)
 {
     Ks = new RGBPixelD[K];
     for (int i = 1; i < K; i++)
     {
         int       source = 0; int dest = 0;
         colorProb c = Prim.edge.pop();
         source = c.colour1; dest = c.colour2;
         if (Prim.MST.ContainsKey(dest))
         {
             Prim.MST[source].Remove(dest);
         }
         else
         {
             Prim.MST.Add(dest, new Dictionary <int, double>());
             Prim.MST[source].Remove(dest);
         }
     }
 }
Пример #2
0
 public minHeap(colorProb color)
 {
     this.distance = color.distance;
     this.colour1  = color.colour1;
     this.colour2  = color.colour2;
 }
Пример #3
0
 public void push(colorProb item)
 {
     count++;
     ListOfColors.Add(item);
     this.heapfyup();
 }
Пример #4
0
        public static void prim()
        {
            int      currentNode = size - 1;
            int      next = 0;
            RGBPixel RGB1, RGB2;
            double   minD = 1e9;

            for (int i = 0; i < size; i++)
            {
                distance[i] = 1e9;
                visited[i]  = false;
            }

            for (int i = 0; i < size - 1; i++)
            {
                if (visited[currentNode])
                {
                    continue;
                }
                visited[currentNode] = true;
                for (int j = 0; j < size; j++)
                {
                    if (currentNode != j)
                    {
                        if (!visited[j])
                        {
                            RGB1 = col_distinct[currentNode];
                            RGB2 = col_distinct[j];
                            double distanceD = Math.Sqrt(((RGB1.red - RGB2.red) * (RGB1.red - RGB2.red)) + (RGB1.green - RGB2.green) * (RGB1.green - RGB2.green) + (RGB1.blue - RGB2.blue) * (RGB1.blue - RGB2.blue));
                            if (distance[j] > distanceD)
                            {
                                distance[j] = distanceD;
                                parent[j]   = currentNode;
                            }
                            if (minD > distance[j])
                            {
                                minD = distance[j];
                                next = j;
                            }
                        }
                    }
                }
                if (minD != 1e9)
                {
                    mstCost += distance[next];
                    //add to heap
                    colorProb c = new colorProb();
                    c.distance = -1 * distance[next];
                    c.colour1  = parent[next];
                    c.colour2  = next;
                    edge.push(c);
                    //add to graph adjlist
                    if (!MST.ContainsKey(parent[next]))
                    {
                        MST.Add(parent[next], new Dictionary <int, double>());
                    }
                    MST[parent[next]].Add(next, distance[next]);
                    currentNode = next; minD = 1e9;
                }
            }
        }