private void connected_area()
        {
            Bit = (Bitmap)ConvertedImage.Image.Clone();
            int capacity = Bit.Height * Bit.Width;

            queue_i = new Queue <int>(capacity);
            queue_j = new Queue <int>(capacity);

            countt  = new int[capacity];
            visited = new bool[Bit.Width + 5][];

            #region initialization of visited boolean array
            for (int i = 0; i < Bit.Width + 5; i++)
            {
                visited[i] = new bool[Bit.Height + 5];
                for (int j = 0; j < Bit.Height + 5; j++)
                {
                    visited[i][j] = false;
                }
            }
            #endregion
            big = new int[Bit.Width + 5][];

            #region initialization of count region array
            for (int i = 0; i < Bit.Width + 5; i++)
            {
                big[i] = new int[Bit.Height + 5];
                for (int j = 0; j < Bit.Height + 5; j++)
                {
                    big[i][j] = 0;
                }
            }
            #endregion

            int max = 0, max_bit = 0;
            count_region = 1;
            for (int i = 0; i < Bit.Width; i++)
            {
                for (int j = 0; j < Bit.Height; j++)
                {
                    if (!visited[i][j] && (Bit.GetPixel(i, j).R == 0 && Bit.GetPixel(i, j).G == 0 && Bit.GetPixel(i, j).B == 0))
                    {
                        countt[count_region] = 0;
                        //MessageBox.Show(i+" "+j+" ");
                        BFS(i, j);
                        if (max < countt[count_region])
                        {
                            max     = countt[count_region];
                            max_bit = count_region;
                            //MessageBox.Show(max+" ");
                        }
                        count_region++;
                    }
                }
            }


            Bitmap bmp = new Bitmap(ConvertedImage.Image.Width, ConvertedImage.Image.Height);

            int min_x = Bit.Width;
            int max_x = 0;
            int max_y = 0;
            int min_y = Bit.Height;

            //MessageBox.Show(max_bit.ToString());
            for (int i = 0; i < Bit.Width; i++)
            {
                for (int j = 0; j < Bit.Height; j++)
                {
                    if (big[i][j] == max_bit)
                    {
                        bmp.SetPixel(i, j, Bit.GetPixel(i, j));

                        #region calculating max min x and y of shorted image frame
                        if (min_x >= i)
                        {
                            min_x = i;
                        }
                        if (max_x < i)
                        {
                            max_x = i;
                        }
                        if (min_y >= j)
                        {
                            min_y = j;
                        }
                        if (max_y < j)
                        {
                            max_y = j;
                        }
                        #endregion
                    }
                    else
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.White);
                    }
                }
            }

            //pictureBox2.Image = (Image)bmp;
            //MessageBox.Show("d");
            //bmp = shape((Bitmap)bmp.Clone());
            //pictureBox2.Image = (Image)bmp;
            //pictureBox2.Invalidate();
            //MessageBox.Show("d");


            int    w, h, t;
            double a, p;
            int    flagforidentification = 0;

            if (max_x - min_x >= 30 && max_y - min_x >= 30)
            {
                min_x = min_x - 30;
                min_y = min_y - 30;
                max_x = max_x + 30;
                max_y = max_y + 30;
                flagforidentification = 1;
            }

            if (min_x < 0)
            {
                min_x = 0;
            }

            if (min_y < 0)
            {
                min_y = 0;
            }

            if (max_x > Bit.Width)
            {
                max_x = Bit.Width;
            }

            if (max_y > Bit.Height)
            {
                max_y = Bit.Height;
            }
            a = max_x - min_x;
            p = a * 0.12;
            t = Convert.ToInt16(p);
            if (flagforidentification == 1)
            {
                max_x -= t;
                min_x += t;
                min_y += t;
            }
            a = max_x - min_x;
            w = Convert.ToInt16(a);
            h = Convert.ToInt16(w * 1.5);
            // MessageBox.Show(w.ToString());

            if (h + min_y > max_y)
            {
                h = max_y - min_y;
            }


            Bitmap bbbb = new Bitmap(w, h);
            Bitmap pic1 = (Bitmap)InputImage.Image.Clone();
            ConvertedImage.Image = System.Drawing.Image.FromFile(file_name);
            Bitmap fre = (Bitmap)ConvertedImage.Image;
            for (int i = min_x; i < max_x; i++)
            {
                for (int j = min_y; j < min_y + h; j++)
                {
                    //if(bmp.GetPixel(i,j).B==0)
                    bbbb.SetPixel(i - min_x, j - min_y, fre.GetPixel(i, j));
                    ////// bbbb.SetPixel(i - min_x, j - min_y, pic1.GetPixel(i, j));
                    pic1.SetPixel(i, j, System.Drawing.Color.Black);
                    //else
                    //bbbb.SetPixel(i - min_x, j - min_y, Color.White);
                }
            }

            //bbbb = shape((Bitmap)bbbb.Clone());

            ConvertedImage.Image = (Bitmap)bbbb;
            ConvertedImage.Invalidate();
            InputImage.Image = (System.Drawing.Image)pic1;
            queue_i.Clear();
            queue_j.Clear();
        }
        private void skin_color_segmentation()
        {
            Bitmap bm  = (Bitmap)InputImage.Image;
            Bitmap bmp = new Bitmap(InputImage.Image.Width, InputImage.Image.Height);

            double tot_pixel = bm.Height * bm.Width;

            tot_pixel /= 100;
            tot_pixel *= 10;
            int min_x = bm.Width + 5;// Convert.ToInt16(tot_pixel);
            int max_x = 0;
            int max_y = 0;
            int min_y = bm.Height + 5;// Convert.ToInt16(tot_pixel);

            System.Drawing.Color color = new System.Drawing.Color();
            double g, r, avg = 0;
            double f_upper, f_lower, w;
            bool   R1, R3, R4, s;
            double c, cr, cb;

            R1       = R3 = R4 = s = false;
            cr_start = 140;
            cr_end   = 170;
            cb_start = 105;
            cb_end   = 150;

            for (int i = 0; i < bm.Width; i++)
            {
                for (int j = 0; j < bm.Height; j++)
                {
                    color = bm.GetPixel(i, j);
                    r     = Convert.ToDouble(color.R) / Convert.ToDouble(color.R + color.G + color.B);
                    g     = Convert.ToDouble(color.G) / Convert.ToDouble(color.R + color.G + color.B);

                    f_upper = -1.3767 * r * r + 1.0743 * r + 0.1452;
                    f_lower = -0.776 * r * r + 0.5601 * r + 0.1766;

                    if (g > f_lower && g < f_upper)
                    {
                        R1 = true;
                    }
                    else
                    {
                        R1 = false;
                    }

                    w = Math.Pow((r - 0.33), 2) + Math.Pow((g - 0.33), 2);
                    //avg += w;
                    //MessageBox.Show(w.ToString());
                    if (w <= 0.0004)
                    {
                        avg++;
                    }

                    if (color.R > color.G && color.G > color.B)
                    {
                        R3 = true;
                    }
                    else
                    {
                        R3 = false;
                    }

                    if ((color.R - color.G) >= 45)
                    {
                        R4 = true;
                    }
                    else
                    {
                        R4 = false;
                    }

                    if (R3 && R4)//&& R1 && !R2)//if(R1 && R2)//
                    {
                        s = true;
                    }
                    else
                    {
                        s = false;
                    }

                    c  = 0.257 * Convert.ToDouble(color.R) + 0.504 * color.G + 0.098 * color.B + 16;
                    cb = 0.148 * Convert.ToDouble(color.R) - 0.291 * Convert.ToDouble(color.G) + 0.439 * Convert.ToDouble(color.B) + 128;
                    cr = 0.439 * Convert.ToDouble(color.R) - 0.368 * Convert.ToDouble(color.G) - 0.071 * Convert.ToDouble(color.B) + 128;


                    if (s)
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.Black);
                        R1 = R3 = R4 = s = false;
                        #region finding face rectangle

                        /*
                         * finding the minimum co-ordinate and maximum co-ordinate xy
                         * of the image between the Cb and Cr threshold value region
                         */

                        if (i < bm.Width / 2 && i < min_x)
                        {
                            min_x = i;
                        }
                        if ((i >= bm.Width / 2 && i < bm.Width) && i > max_x)
                        {
                            max_x = i;
                        }

                        if (j < bm.Height / 2 && j < min_y)
                        {
                            min_y = j;
                        }
                        if ((j >= bm.Height / 2 && i < bm.Height) && j > max_y)
                        {
                            max_y = j;
                        }
                        #endregion
                    }
                    else
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.White);
                    }
                }
            }

            ConvertedImage.Image = (Bitmap)bmp;
            ConvertedImage.Invalidate();
            //MessageBox.Show("End");
        }