ArrayBool2DToBitmap() 공개 정적인 메소드

public static ArrayBool2DToBitmap ( bool input ) : Bitmap
input bool
리턴 System.Drawing.Bitmap
 public Bitmap Apply(Bitmap srcimg)
 {
     bool[,] image = ImageUtils.BitmapToBoolArray2D(srcimg, 0);
     bool[,] tmp   = new bool[srcimg.Height, srcimg.Width];
     for (int i = 1; i < srcimg.Width - 1; i++)
     {
         for (int j = 1; j < srcimg.Height - 1; j++)
         {
             if (image[j, i] == false) //background pixel
             {
                 tmp[j, i] = image[j, i];
                 bool[] marks     = new bool[8];
                 int    nei_count = 0;
                 // 0 1 2
                 // 3 x 4
                 // 5 6 7
                 int count = 0;
                 for (int r = -1; r < 2; r++) //scan neighbors
                 {
                     for (int c = -1; c < 2; c++)
                     {
                         if (r == 0 && c == 0)
                         {
                             continue;
                         }
                         if (image[j + r, i + c])
                         {
                             count++;
                         }
                         marks[nei_count] = image[j + r, i + c];
                         nei_count++;
                     }
                 }
                 //convert one pixel gaps between lines
                 {
                     if ((marks[0] && marks[7]) || (marks[1] && marks[6]) ||
                         (marks[2] && marks[5]) || (marks[3] && marks[4]))
                     {
                         tmp[j, i] = true;
                     }
                 }
             }
             else
             {
                 tmp[j, i] = image[j, i];
             }
         }
     }
     for (int i = 1; i < srcimg.Width - 1; i++)
     {
         for (int j = 1; j < srcimg.Height - 1; j++)
         {
             image[j, i] = tmp[j, i];
         }
     }
     return(ImageUtils.ArrayBool2DToBitmap(image));
 }
예제 #2
0
        public Bitmap Apply(Bitmap srcimg)
        {
            srcimg = ImageUtils.ConvertGrayScaleToBinary(srcimg, 254);
            srcimg = ImageUtils.InvertColors(srcimg);

            MyConnectedComponentsAnalysisFast.MyBlobCounter char_bc    = new MyConnectedComponentsAnalysisFast.MyBlobCounter();
            List <MyConnectedComponentsAnalysisFast.MyBlob> char_blobs = char_bc.GetBlobs(srcimg);

            ushort[] char_labels = char_bc.objectLabels;

            HashSet <int> boarder_char_idx_set = new HashSet <int>();

            for (int i = 0; i < char_blobs.Count; i++)
            {
                if (char_blobs[i].bbx.X == 0 ||
                    char_blobs[i].bbx.Right == srcimg.Width ||
                    char_blobs[i].bbx.Top == 0 ||
                    char_blobs[i].bbx.Bottom == srcimg.Height)
                {
                    boarder_char_idx_set.Add(i);
                }
            }

            for (int i = 0; i < srcimg.Width * srcimg.Height; i++)
            {
                if (char_labels[i] != 0)
                {
                    int idx = char_labels[i] - 1;
                    if (boarder_char_idx_set.Contains(idx))
                    {
                        char_labels[i] = 0;
                    }
                }
            }
            bool[,] img = new bool[srcimg.Height, srcimg.Width];
            for (int i = 0; i < srcimg.Width; i++)
            {
                for (int j = 0; j < srcimg.Height; j++)
                {
                    if (char_labels[j * srcimg.Width + i] == 0)
                    {
                        img[j, i] = false;
                    }
                    else
                    {
                        img[j, i] = true;
                    }
                }
            }
            return(ImageUtils.ArrayBool2DToBitmap(img));
        }
예제 #3
0
        public Bitmap Apply(Bitmap srcimg, int char_size)
        {
            double min_pixel_area_size = 0.18;

            srcimg = ImageUtils.ConvertGrayScaleToBinary(srcimg, 254);
            srcimg = ImageUtils.InvertColors(srcimg);

            MyConnectedComponentsAnalysisFast.MyBlobCounter char_bc    = new MyConnectedComponentsAnalysisFast.MyBlobCounter();
            List <MyConnectedComponentsAnalysisFast.MyBlob> char_blobs = char_bc.GetBlobs(srcimg);

            ushort[] char_labels = char_bc.objectLabels;

            HashSet <int> noise_char_idx_set = new HashSet <int>();

            for (int i = 0; i < char_blobs.Count; i++)
            {
                if (((double)char_blobs[i].pixel_count / (double)char_blobs[i].area) < min_pixel_area_size) //line
                {
                    noise_char_idx_set.Add(i);
                }
                if (char_blobs[i].bbx.Width < char_size &&
                    char_blobs[i].bbx.Height < char_size)  // small cc
                {
                    noise_char_idx_set.Add(i);
                }
                if (char_blobs[i].bbx.Width <char_size && char_blobs[i].bbx.Height> char_size * 3)
                {
                    noise_char_idx_set.Add(i);
                }
                if (char_blobs[i].bbx.Height <char_size && char_blobs[i].bbx.Width> char_size * 3)
                {
                    noise_char_idx_set.Add(i);
                }
            }

            for (int i = 0; i < srcimg.Width * srcimg.Height; i++)
            {
                if (char_labels[i] != 0)
                {
                    int idx = char_labels[i] - 1;
                    if (noise_char_idx_set.Contains(idx))
                    {
                        char_labels[i] = 0;
                    }
                }
            }
            bool[,] img = new bool[srcimg.Height, srcimg.Width];
            for (int i = 0; i < srcimg.Width; i++)
            {
                for (int j = 0; j < srcimg.Height; j++)
                {
                    if (char_labels[j * srcimg.Width + i] == 0)
                    {
                        img[j, i] = false;
                    }
                    else
                    {
                        img[j, i] = true;
                    }
                }
            }
            return(ImageUtils.ArrayBool2DToBitmap(img));
        }