Ejemplo n.º 1
0
        private void btnInitialize_Click(object sender, EventArgs e)
        {
            kmeans = new KMeans(k);

            kmeans.Compute(mixture);

            // Classify all instances in mixture data
            int[] classifications = kmeans.Classify(mixture);

            // Draw the classifications
            updateGraph(classifications);
        }
Ejemplo n.º 2
0
        public void KMeansConstructorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);


            // Declare some observations
            double[][] observations =
            {
                new double[] { -5, -2, -1 },
                new double[] { -5, -5, -6 },
                new double[] {  2,  1,  1 },
                new double[] {  1,  1,  2 },
                new double[] {  1,  2,  2 },
                new double[] {  3,  1,  2 },
                new double[] { 11,  5,  4 },
                new double[] { 15,  5,  6 },
                new double[] { 10,  5,  6 },
            };

            // Create a new K-Means algorithm with 3 clusters
            KMeans kmeans = new KMeans(3);

            // Compute the algorithm, retrieving an integer array
            //  containing the labels for each of the observations
            int[] labels = kmeans.Compute(observations);

            // As a result, the first two observations should belong to the
            //  same cluster (thus having the same label). The same should
            //  happen to the next four observations and to the last three.

            Assert.AreEqual(labels[0], labels[1]);

            Assert.AreEqual(labels[2], labels[3]);
            Assert.AreEqual(labels[2], labels[4]);
            Assert.AreEqual(labels[2], labels[5]);

            Assert.AreEqual(labels[6], labels[7]);
            Assert.AreEqual(labels[6], labels[8]);

            Assert.AreNotEqual(labels[0], labels[2]);
            Assert.AreNotEqual(labels[2], labels[6]);
            Assert.AreNotEqual(labels[0], labels[6]);


            int[] labels2 = kmeans.Classify(observations);
            Assert.IsTrue(labels.IsEqual(labels2));
        }
        public Bitmap ProcessImage(Bitmap image, List <Color> cenotridColorList)
        {
            Bitmap resultImage = new Bitmap(image.Width, image.Height);       //resultimage bitmapinin uzunluk ve genişliğini tanımladık

            for (int i = 0; i < resultImage.Height; i++)                      //yüksekliğine kadar aldık
            {
                for (int j = 0; j < resultImage.Width; j++)                   //genişliğine kadar aldık
                {
                    Color    c              = image.GetPixel(i, j);           ////image in pixellerini c ye atadık
                    double[] pixelArray     = new double[] { c.R, c.G, c.B }; // bu pixelleri rneklerine ayırdık
                    int      resultCentroid = _kmeans.Classify(pixelArray);
                    Color    centroidColor  = cenotridColorList[resultCentroid];
                    resultImage.SetPixel(i, j, centroidColor);
                }
            }

            return(resultImage);
        }
Ejemplo n.º 4
0
        private void btnPresentResults_Click(object sender, EventArgs e)
        {
            frmPresenter presenter = new frmPresenter();
            int          cluster   = 0;

            foreach (Centroid c in _centroids)
            {
                presenter.AddList(String.Format("Cluster: {0}", cluster));
                cluster++;
            }

            foreach (string file in _files)
            {
                Bitmap   bmpImage      = ResizeImage(file, new Size(400, 200));
                double[] processResult = GetAverageRGB(bmpImage);
                int      clusterIndex  = _kMeans.Classify(processResult);
                presenter.AddItemToList(clusterIndex, file);
            }

            presenter.Show();
        }
Ejemplo n.º 5
0
        public void KMeansConstructorTest()
        {

            Accord.Math.Tools.SetupGenerator(0);


            // Declare some observations
            double[][] observations = 
            {
                new double[] { -5, -2, -1 },
                new double[] { -5, -5, -6 },
                new double[] {  2,  1,  1 },
                new double[] {  1,  1,  2 },
                new double[] {  1,  2,  2 },
                new double[] {  3,  1,  2 },
                new double[] { 11,  5,  4 },
                new double[] { 15,  5,  6 },
                new double[] { 10,  5,  6 },
            };

            // Create a new K-Means algorithm with 3 clusters 
            KMeans kmeans = new KMeans(3);

            // Compute the algorithm, retrieving an integer array
            //  containing the labels for each of the observations
            int[] labels = kmeans.Compute(observations);

            // As a result, the first two observations should belong to the
            //  same cluster (thus having the same label). The same should
            //  happen to the next four observations and to the last three.

            Assert.AreEqual(labels[0], labels[1]);

            Assert.AreEqual(labels[2], labels[3]);
            Assert.AreEqual(labels[2], labels[4]);
            Assert.AreEqual(labels[2], labels[5]);

            Assert.AreEqual(labels[6], labels[7]);
            Assert.AreEqual(labels[6], labels[8]);

            Assert.AreNotEqual(labels[0], labels[2]);
            Assert.AreNotEqual(labels[2], labels[6]);
            Assert.AreNotEqual(labels[0], labels[6]);


            int[] labels2 = kmeans.Classify(observations);
            Assert.IsTrue(labels.IsEqual(labels2));
        }
Ejemplo n.º 6
0
        private void btnInitialize_Click(object sender, EventArgs e)
        {
            kmeans = new KMeans(k);

            kmeans.Compute(mixture);

            // Classify all instances in mixture data
            int[] classifications = kmeans.Classify(mixture);

            // Draw the classifications
            updateGraph(classifications);
        }