コード例 #1
0
 public static double GetEuclidianColor(ColorPoint @from, ColorPoint to)
 {
     // Compute the Euclidian distance between two colors in the 3D-space
     return(Math.Sqrt(Math.Pow(Math.Abs(@from.Color.R - to.Color.R), 2) +
                      Math.Pow(Math.Abs(@from.Color.G - to.Color.G), 2) +
                      Math.Pow(Math.Abs(@from.Color.B - to.Color.B), 2)));
 }
コード例 #2
0
        private List <ColorPoint> GenerateCentroids(Image <Rgba32> image, int amount)
        {
            var colorPoints = new List <ColorPoint>(amount);
            var random      = new Random();

            for (var i = 0; i < amount; ++i)
            {
                int randomX;
                int randomY;

                // Make sure the random position will be unique for the superpixel
                while (true)
                {
                    randomX = random.Next(0, image.Width);
                    randomY = random.Next(0, image.Height);

                    if (!colorPoints.Any(cp => cp.X == randomX && cp.Y == randomY))
                    {
                        break;
                    }
                }

                var colorPoint = new ColorPoint(randomX, randomY, image[randomX, randomY]);
                colorPoints.Add(colorPoint);
            }

            return(colorPoints);
        }
コード例 #3
0
 public KMeansFrame(Image <Rgba32> frame, List <ColorPoint> centroids, ColorPoint center)
 {
     Frame     = frame;
     Centroids = centroids;
     Center    = center;
 }
コード例 #4
0
 public static double GetEuclidianDistance(ColorPoint @from, ColorPoint to)
 {
     // Compute the Euclidian distance between two pixel in the 2D-space
     return(Math.Sqrt(Math.Pow(@from.X - to.X, 2) +
                      Math.Pow(@from.Y - to.Y, 2)));
 }