Exemple #1
0
        public void Run()
        {
            Bitmap bitmap = GetImage();

            int width  = bitmap.Width;
            int height = bitmap.Height;

            double[][] image = ImageTools.BitmapToArray(bitmap);

            var kMeans = new Clustering.KMeans(20, 6, 0, 255, image, SCDE);

            int[,] map = new int[width, height];

            int currentCluster = 0;

            foreach (var cluster in kMeans.clusters)
            {
                foreach (int index in cluster.indeces)
                {
                    int x = (int)Math.Floor(index / (double)bitmap.Height);
                    int y = index % bitmap.Height;

                    map[x, y] = currentCluster;
                }

                currentCluster++;
            }

            Save(FeatureExtraction.CellularAutomata(map, 12, 0, 0, 6), kMeans, "4-0-0-6");

            //map = FloodFill.Fill(map);

            /*
             * foreach (var cluster in kMeans.clusters) {
             *
             *  double[] mean = cluster.GetMean();
             *  Color color = Color.FromArgb((int)mean[0],(int)mean[1],(int)mean[2]);
             *
             *  foreach (int index in cluster.indeces) {
             *
             *      int x = (int)Math.Floor(index / (double)bitmap.Height);
             *      int y = index % bitmap.Height;
             *
             *      newImage.SetPixel(x,y,color);
             *  }
             * }
             */
        }
Exemple #2
0
        public void Save(int[,] map, Clustering.KMeans kMeans, string name)
        {
            Bitmap newImage = new Bitmap(map.GetLength(0), map.GetLength(1));

            Color[] colors = new Color[kMeans.clusters.Length];

            for (int i = 0; i < colors.Length; i++)
            {
                double[] mean = kMeans.clusters[i].GetMean();
                colors[i] = Color.FromArgb((int)mean[0], (int)mean[1], (int)mean[2]);
            }

            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    newImage.SetPixel(x, y, colors[map[x, y]]);
                }
            }

            newImage.Save(rootPath + name + " - " + random.Next() + ".png", ImageFormat.Png);
        }