Exemplo n.º 1
0
        public double MstPrim(List <RgbPixel> distinctColors)
        {
            int u = 0, curntNode = 0;
            var mstCost = 0d;

            _key[0]    = 0;
            _parent[0] = -1;
            for (int i = 0; i < _VertixSize; i++)
            {
                _visted[u] = true;
                int miniCost = Int32.MaxValue;
                for (int j = 0; j < _VertixSize; j++)
                {
                    if (_visted[j] == false)
                    {
                        var cost = RgbPixel.EuclideanDistance(distinctColors[u], distinctColors[j]);
                        if (cost < _key[j])
                        {
                            _parent[j] = u;
                            _key[j]    = cost;
                        }
                        if (_key[j] < miniCost)
                        {
                            curntNode = j;
                            miniCost  = _key[j];
                        }
                    }
                }
                u        = curntNode;
                mstCost += miniCost;
            }

            return(Math.Round(mstCost, 1));
        }
Exemplo n.º 2
0
        public double MstPrim(List <RgbPixel> distinctColors)                                                // Θ(V^2)
        {
            var mstCost = 0d;                                                                                // Θ(1)
            int startNode = 0, nextNode = 0;                                                                 // Θ(1)

            _key[0]    = 0;                                                                                  // Θ(1)
            _parent[0] = 0;                                                                                  // Θ(1)
            for (var i = 0; i < _VertixSize - 1; i++)                                                        // Θ(v * body)
            {
                _visted[startNode] = true;                                                                   // Θ(1)
                double miniCost = Int32.MaxValue;                                                            // Θ(1)
                for (var j = 0; j < _VertixSize; j++)                                                        // Θ(v * body)
                {
                    if (_visted[j] == false)                                                                 // Θ(1)
                    {
                        var cost = RgbPixel.EuclideanDistance(distinctColors[startNode], distinctColors[j]); // Θ(1)
                        if (cost < _key[j])                                                                  // Θ(1)
                        {
                            _parent[j] = startNode;                                                          // Θ(1)
                            _key[j]    = cost;                                                               // Θ(1)
                        }
                        if (_key[j] < miniCost)                                                              // Θ(1)
                        {
                            nextNode = j;                                                                    // Θ(1)
                            miniCost = _key[j];                                                              // Θ(1)
                        }
                    }
                }
                startNode = nextNode;                                                // Θ(1)
                mstCost  += _key[startNode];                                         // Θ(1)
                edges.Add(new Edge(startNode, _parent[startNode], _key[startNode])); // Θ(1)
            }

            return(Math.Round(mstCost, 2));  // Θ(1)
        }
Exemplo n.º 3
0
        public static double EuclideanDistance(RgbPixel p1, RgbPixel p2)
        {
            int redDistance   = p1.red - p2.red;
            int greenDistance = p1.green - p2.green;
            int blueDistance  = p1.blue - p2.blue;

            double squareDistance = redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance;

            return(Math.Sqrt(squareDistance));
        }
Exemplo n.º 4
0
        private List <RgbPixel> CountDistinctColors()
        {
            var uniqColors = new SortedSet <int>();
            var uColors    = new List <RgbPixel>();

            foreach (var pixel in ImageMatrix)
            {
                var color = RgbPixel.ConvertToRgbPixel(pixel).RGBToInt();
                uniqColors.Add(color);
            }

            foreach (var uniqColor in uniqColors)
            {
                var color = RgbPixel.IntToRGB(uniqColor);
                uColors.Add(color);
            }

            return(uColors);
        }
Exemplo n.º 5
0
        public static RgbPixel ConvertToRgbPixel(RGBPixel pixel)
        {
            RgbPixel p = new RgbPixel(pixel.red, pixel.green, pixel.blue);

            return(p);
        }