コード例 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        private void btnQuantize_Click(object sender, EventArgs e)
        {
            int K = (int)ClusterK.Value;                                                         // -> O(1)

            txtDisColor.Text = ImageAnalytics.Find_Distinct_Color(ImageMatrix).ToString();       // -> O(W*H)
            txtMST.Text      = (Math.Round(ImageAnalytics.MinimumSpanningTree(), 2)).ToString(); // -> O(E Log V)
            DetectNumOfClusters x = new DetectNumOfClusters(ImageAnalytics.edges);               // -> O(E*V)

            if (K == 0)
            {
                K = x.k;                                             // -> O(1)
            }
            QuantizeImage.Extract_K_Cluster(K);                      // -> O(K*D)
            QuantizeImage.Find_K_Cluster();                          // -> O(D)
            ImageOperations.DisplayImage(ImageMatrix, PostImage, 1); //O(N^2) where N is the height or the weight of image
            ClusterK.Value = K;                                      // print the number of cluster if changed // -> O(1)
        }
コード例 #2
0
        private void btnQuantize_Click(object sender, EventArgs e)
        {
            long before = System.Environment.TickCount;                                          // get the current time in miliseconds  // -> O(1)
            int  K      = (int)ClusterK.Value;                                                   // -> O(1)

            txtDisColor.Text = ImageAnalytics.Find_Distinct_Color(ImageMatrix).ToString();       // -> O(W*H)
            txtMST.Text      = (Math.Round(ImageAnalytics.MinimumSpanningTree(), 2)).ToString(); // -> O(E Log V)
            DetectNumOfClusters x = new DetectNumOfClusters(ImageAnalytics.edges);               // -> O(E*V)

            if (K == 0)
            {
                K = x.k;                                               // -> O(1)
            }
            QuantizeImage.Extract_K_Cluster(K);                        // -> O(K*D)
            QuantizeImage.Find_K_Cluster();                            // -> O(D)
            ImageOperations.DisplayImage(ImageMatrix, pictureBox2, 1); //O(N^2) where N is the height or the weight of image
            ClusterK.Value = K;                                        // print the number of cluster if changed // -> O(1)
            long   after = System.Environment.TickCount;               // get the current time // -> O(1)
            double total = after - before;                             // Calculate the taken time // -> O(1)

            total         /= 60000;                                    // convert miliseconds to minutes // -> O(1)
            total          = Math.Round(total, 3);                     // Round the Minutes to three decimal digits // -> O(1)
            TimeLable.Text = total.ToString() + " M (s)";              // -> O(1)
        }
コード例 #3
0
        /// <summary>
        /// Display the given image on the given PictureBox object
        /// </summary>
        /// <param name="ImageMatrix">2D array that contains the image</param>
        /// <param name="PicBox">PictureBox object to display the image on it</param>
        /// <param name="choice">to know it should make qunatization image or simple display (0/1) </param>
        public static void DisplayImage(RGBPixel[,] ImageMatrix, PictureBox PicBox, int choice) // -> O(W*H)
        {
            int Height = GetHeight(ImageMatrix);                                                // -> O(1)
            int Width  = GetWidth(ImageMatrix);                                                 // -> O(1)

            Bitmap ImageBMP = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);            // -> O(1)

            if (choice == 1)
            {
                QuantizeImage.Quantize_Image(); // -> O(N)
                // Create Image:
                //==============



                unsafe
                {
                    BitmapData bmd    = ImageBMP.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, ImageBMP.PixelFormat); // -> O(1)
                    int        nWidth = 0;                                                                                                    // -> O(1)
                    nWidth = Width * 3;                                                                                                       // -> O(1)
                    int   nOffset = bmd.Stride - nWidth;                                                                                      // -> O(1)
                    byte *p       = (byte *)bmd.Scan0;                                                                                        // -> O(1)
                    for (int i = 0; i < Height; i++)                                                                                          // -> O(Height) * O(Width) --->> (H*W)
                    {
                        for (int j = 0; j < Width; j++)                                                                                       // -> O(Width) *  O(1)
                        {
                            p[2] = QuantizeImage.final_image[ImageMatrix[i, j].red, ImageMatrix[i, j].green, ImageMatrix[i, j].blue].red;
                            p[1] = QuantizeImage.final_image[ImageMatrix[i, j].red, ImageMatrix[i, j].green, ImageMatrix[i, j].blue].green;
                            p[0] = QuantizeImage.final_image[ImageMatrix[i, j].red, ImageMatrix[i, j].green, ImageMatrix[i, j].blue].blue;
                            p   += 3; // -> O(1)
                        }

                        p += nOffset;         // -> O(1)
                    }
                    ImageBMP.UnlockBits(bmd); // -> O(1)
                }
            }
            else
            {
                unsafe
                {
                    BitmapData bmd    = ImageBMP.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, ImageBMP.PixelFormat); // -> O(1)
                    int        nWidth = 0;                                                                                                    // -> O(1)
                    nWidth = Width * 3;                                                                                                       // -> O(1)
                    int   nOffset = bmd.Stride - nWidth;                                                                                      // -> O(1)
                    byte *p       = (byte *)bmd.Scan0;                                                                                        // -> O(1)
                    for (int i = 0; i < Height; i++)                                                                                          // -> O(Height) * O(Width) --->> (H*W)
                    {
                        for (int j = 0; j < Width; j++)                                                                                       // -> O(Width) *  O(1)
                        {
                            p[2] = ImageMatrix[i, j].red;                                                                                     // -> O(1)
                            p[1] = ImageMatrix[i, j].green;                                                                                   // -> O(1)
                            p[0] = ImageMatrix[i, j].blue;                                                                                    // -> O(1)
                            p   += 3;                                                                                                         // -> O(1)
                        }

                        p += nOffset;         // -> O(1)
                    }
                    ImageBMP.UnlockBits(bmd); // -> O(1)
                }
            }
            PicBox.Image = ImageBMP; // -> O(1)
        }