public List<TextString> Apply(Bitmap srcimg, Bitmap dilatedimg) { width = srcimg.Width; height = srcimg.Height; max_width = width / 2; max_height = height / 2; //ashish srcimg = ImageUtils.ConvertGrayScaleToBinary(srcimg, threshold: 128); srcimg = ImageUtils.InvertColors(srcimg); dilatedimg = ImageUtils.ConvertGrayScaleToBinary(dilatedimg, threshold: 128); dilatedimg = ImageUtils.InvertColors(dilatedimg); MyConnectedComponentsAnalysisFast.MyBlobCounter char_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> char_blobs = char_bc.GetBlobs(srcimg); ushort[] char_labels = char_bc.objectLabels; MyConnectedComponentsAnalysisFast.MyBlobCounter string_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> string_blobs = string_bc.GetBlobs(dilatedimg); ushort[] string_labels = string_bc.objectLabels; List<TextString> initial_string_list = new List<TextString>(); int string_count = string_blobs.Count; for (int i = 0; i < string_count; i++) { initial_string_list.Add(new TextString()); initial_string_list.Last().mass_center = string_blobs[i].mass_center; } for (int i = 0; i < char_blobs.Count; i++) { if (char_blobs[i].bbx.Width > 1 && char_blobs[i].bbx.Height > 1) { char_blobs[i].string_id = string_labels[char_blobs[i].sample_y * width + char_blobs[i].sample_x] - 1; initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[i]); } } for (int i = 0; i < initial_string_list.Count; i++) { if( (initial_string_list[i].char_list.Count == 0) || (initial_string_list[i].bbx.Width<min_width || initial_string_list[i].bbx.Height < min_height) || (initial_string_list[i].bbx.Width > max_width || initial_string_list[i].bbx.Height > max_height)) { initial_string_list.RemoveAt(i); i--; } } for (int i = 0; i < initial_string_list.Count; i++) { PrintSubStringsSmall(char_labels, initial_string_list[i], 0); } return initial_string_list; }
public string Apply(int tnum, Bitmap srcimg, double size_ratio, double ang_threshold, bool preprocessing, string outImagePath) { this.tnum = tnum; this.width = srcimg.Width; this.height = srcimg.Height; int iteration = 2; this.size_ratio = size_ratio; this.ang_threshold = ang_threshold; //input image: white as forground srcimg = ImageUtils.ConvertGrayScaleToBinary(srcimg, 128); if (preprocessing) { ConnectingGap cg = new ConnectingGap(); srcimg = cg.Apply(srcimg); } // Log.WriteBitmap2Debug(srcimg, "start"); srcimg = ImageUtils.InvertColors(srcimg); minimum_distance_between_CCs_in_string = iteration; MyConnectedComponentsAnalysisFast.MyBlobCounter char_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); this.char_blobs = char_bc.GetBlobs(srcimg); this.char_labels = new short[width * height]; // Log.WriteBitmap2Debug(Printnumb(), "num"); // initialize for (int i = 0; i < char_blobs.Count; i++) { char_blob_idx_max_size_table.Add(i, Math.Max(char_blobs[i].bbx.Width, char_blobs[i].bbx.Height)); // original size of the character expendable_char_blob_idx_set.Add(i); connected_char_blob_idx_set_list.Add(new HashSet<int>()); } original_char_labels = char_bc.objectLabels; for (int i = 0; i < width * height; i++) char_labels[i] = (short)(char_bc.objectLabels[i]); // first run // Log.WriteBitmap2Debug(Print(), "k1_"); k1(); // Log.WriteBitmap2Debug(Print(), "k1_" + 0); iteration_counter = 1; while (expendable_char_blob_idx_set.Count > 1 && iteration_counter < iteration_threshold) { k1(); iteration_counter++; // Log.WriteBitmap2Debug(Print(), "k1_" + iteration_counter); } Print(outImagePath); return outImagePath; }
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)); }
public Bitmap Apply(Bitmap srcimg, int char_size, double min_pixel_area_size) { 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>(); HashSet<int> noise_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); 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 (boarder_char_idx_set.Contains(idx)) char_labels[i] = 0; 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); }
// for removing small line segments public List<Bitmap> RemoveCCUsingSize(Bitmap srcimg, double upper_ratio, double lower_ratio) { srcimg= ImageUtils.ConvertGrayScaleToBinary(srcimg, 254); srcimg = ImageUtils.InvertColors(srcimg); MyConnectedComponentsAnalysisFast.MyBlobCounter bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> blobs = bc.GetBlobs(srcimg); List<int> remove = new List<int>(); //for (int i = 0; i < blobs.Count; i++) //{ // double r = (double)blobs[i].bbx.Width / (double)blobs[i].bbx.Height; // if ( (r>0.5 && r<2)&& // blobs[i].pixel_count > (double)(blobs[i].bbx.Width * blobs[i].bbx.Height) * area_ratio) // { // if (!remove.Contains(i + 1)) // remove.Add(i + 1); // the index+1 of the blobs is the actual index of the bc label // } //} for (int i = 0; i < blobs.Count; i++) { if ((Math.Max(blobs[i].bbx.Width, blobs[i].bbx.Height) < (double)Math.Max(mh, mw) / lower_ratio) || (Math.Max(blobs[i].bbx.Width, blobs[i].bbx.Height) > upper_ratio * (double)Math.Max(mh, mw))) { if (!remove.Contains(i + 1)) remove.Add(i + 1); // the index+1 of the blobs is the actual index of the bc label } } //List<int> nei_list = new List<int>(); //for (int i = 0; i < blobs.Count; i++) //{ // if (!remove.Contains(i + 1)) // { // bool find = false; // if (nei_list.Contains(i + 1)) // find = true; // else // { // for (int j = 0; j < blobs.Count; j++) // { // if (i == j) continue; // double r = (double)Math.Max(blobs[i].bbx.Width, blobs[i].bbx.Height) / (double)Math.Max(blobs[j].bbx.Width, blobs[j].bbx.Height); // if (r > 1.5 || r < 0.667) continue; // if (Distance(blobs[j].mass_center, blobs[i].mass_center) > // ((double)Math.Max(blobs[i].bbx.Width, blobs[i].bbx.Height) + // (double)Math.Max(blobs[j].bbx.Width, blobs[j].bbx.Height)) / 2 * 2.5) continue; // nei_list.Add(j + 1); // find = true; // break; // } // } // if (!find) remove.Add(i + 1); // } //} int width = srcimg.Width; int height = srcimg.Height; int label = 0; // create new grayscale srcimg Bitmap dstimg = ImageUtils.CreateBlankGrayScaleBmp(width, height); Bitmap removedimg = ImageUtils.CreateBlankGrayScaleBmp(width, height); BitmapData srcData = srcimg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); // lock destination bitmap data BitmapData dstData = dstimg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); BitmapData removedData = removedimg.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); int offset = srcData.Stride - width; // do the job unsafe { byte* src = (byte*)srcData.Scan0.ToPointer(); byte* dst = (byte*)dstData.Scan0.ToPointer(); byte* removed = (byte*)removedData.Scan0.ToPointer(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++, label++, src++, dst++, removed++) { int g = (int)(*src) == 0 ? 255 : 0; // src is ivt if (g == 255) // src is background { *dst = (byte)255; *removed = (byte)255; } else { bool r = remove.Contains(bc.objectLabels[label]); *dst = (byte)(r ? 255 : g); *removed = (byte)(r ? g : 255); } } src += offset; dst += offset; removed += offset; } } srcimg.UnlockBits(srcData); dstimg.UnlockBits(dstData); removedimg.UnlockBits(removedData); //List<Bitmap> retimgList = new List<Bitmap>(); //retimgList.Add(dstimg); //retimgList.Add(removedimg); //return retimgList; Log.WriteBitmap2Debug(dstimg, "dstimg"); Log.WriteBitmap2Debug(removedimg, "removedimg"); List<Bitmap> img_list = new List<Bitmap>(); img_list.Add(dstimg); //img_list.Add(removedimg); return img_list;// removedimg; }
public void IdentifyExpendableCharBlobs() { short_char_blob_idx_set.Clear(); Bitmap resultimg = Print(); resultimg = ImageUtils.InvertColors(resultimg); MyConnectedComponentsAnalysisFast.MyBlobCounter string_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> string_blobs = string_bc.GetBlobs(resultimg); ushort[] string_labels = string_bc.objectLabels; int string_count = string_blobs.Count; List<List<MyConnectedComponentsAnalysisFast.MyBlob>> string_list = new List<List<MyConnectedComponentsAnalysisFast.MyBlob>>(); for (int i = 0; i < string_count; i++) string_list.Add(new List<MyConnectedComponentsAnalysisFast.MyBlob>()); for (int i = 0; i < char_blobs.Count; i++) { char_blobs[i].string_id = string_labels[char_blobs[i].sample_y * width + char_blobs[i].sample_x] - 1; string_list[char_blobs[i].string_id].Add(char_blobs[i]); } for (int i = 0; i < string_list.Count; i++) { if (string_list[i].Count > 0) { int avg_size = 0; for (int j = 0; j < string_list[i].Count; j++) avg_size += Math.Max(string_list[i][j].bbx.Width, string_list[i][j].bbx.Height); avg_size /= string_list[i].Count; for (int j = 0; j < string_list[i].Count; j++) char_blob_idx_max_size_table[string_list[i][j].pixel_id - 1] = avg_size; } } // recomputing expendable char blob idx for (int i = 0; i < char_blobs.Count; i++) { if (connected_char_blob_idx_set_list[i].Count == 2) { expendable_char_blob_idx_set.Remove(i); } else // 0 or 1 connecting CC { int max_dist = (int)((double)((int)char_blob_idx_max_size_table[i]) / 3); // int max_dist = (int)((double)((int)char_blob_idx_max_size_table[i])/2 ); if (max_dist < minimum_distance_between_CCs_in_string * 2) max_dist = minimum_distance_between_CCs_in_string * 2; if (iteration_counter > max_dist) { expendable_char_blob_idx_set.Remove(i); } } } }
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)); }
public void NeighborhoodTextDetection(Bitmap Neighborhood) { MyConnectedComponentsAnalysisFast.MyBlobCounter ConnectedComponent = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); ConnectedComponent.GetBlobs(Neighborhood); }
public void IdentifyExpendableCharBlobs() { short_char_blob_idx_set.Clear(); Bitmap resultimg = Print(); //// Added Part /////// Bitmap IntermediateResult = new Bitmap(resultimg); string Output_dir = @"C:\Users\nhonarva\Desktop\ConditionalDilationIntermediateResult\"; Graphics g = Graphics.FromImage(IntermediateResult); Log.WriteBitmap2FolderExactFileName(Output_dir, IntermediateResult, "Number of Image : " + Counter); Counter++; //////Added Part /////// resultimg = ImageUtils.InvertColors(resultimg); MyConnectedComponentsAnalysisFast.MyBlobCounter string_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> string_blobs = string_bc.GetBlobs(resultimg); ushort[] string_labels = string_bc.objectLabels; int string_count = string_blobs.Count; List<List<MyConnectedComponentsAnalysisFast.MyBlob>> string_list = new List<List<MyConnectedComponentsAnalysisFast.MyBlob>>(); for (int i = 0; i < string_count; i++) string_list.Add(new List<MyConnectedComponentsAnalysisFast.MyBlob>()); for (int i = 0; i < char_blobs.Count; i++) { char_blobs[i].string_id = string_labels[char_blobs[i].sample_y * width + char_blobs[i].sample_x] - 1; string_list[char_blobs[i].string_id].Add(char_blobs[i]); } for (int i = 0; i < string_list.Count; i++) { if (string_list[i].Count > 0) { int avg_size = 0; for (int j = 0; j < string_list[i].Count; j++) avg_size += Math.Max(string_list[i][j].bbx.Width, string_list[i][j].bbx.Height); avg_size /= string_list[i].Count; for (int j = 0; j < string_list[i].Count; j++) char_blob_idx_max_size_table[string_list[i][j].pixel_id - 1] = avg_size; } } // recomputing expendable char blob idx for (int i = 0; i < char_blobs.Count; i++) { if (connected_char_blob_idx_set_list[i].Count == 2) { expendable_char_blob_idx_set.Remove(i); } else // 0 or 1 connecting CC { int max_dist = (int)((double)((int)char_blob_idx_max_size_table[i]) / 3); if (max_dist < minimum_distance_between_CCs_in_string * 2) max_dist = minimum_distance_between_CCs_in_string * 2; if (iteration_counter > max_dist) { expendable_char_blob_idx_set.Remove(i); } } } }
public List<TextString> Apply(Bitmap srcimg, Bitmap dilatedimg) { width = srcimg.Width; height = srcimg.Height; max_width = width / 2; max_height = height / 2; //ashish srcimg = ImageUtils.ConvertGrayScaleToBinary(srcimg, threshold: 128); srcimg = ImageUtils.InvertColors(srcimg); dilatedimg = ImageUtils.ConvertGrayScaleToBinary(dilatedimg, threshold: 128); dilatedimg = ImageUtils.InvertColors(dilatedimg); MyConnectedComponentsAnalysisFast.MyBlobCounter char_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> char_blobs = char_bc.GetBlobs(srcimg); // List<MyConnectedComponentsAnalysisFast.MyBlob> char_blobs2 = char_bc.GetBlobs(srcimg); ushort[] char_labels = char_bc.objectLabels; MyConnectedComponentsAnalysisFast.MyBlobCounter string_bc = new MyConnectedComponentsAnalysisFast.MyBlobCounter(); List<MyConnectedComponentsAnalysisFast.MyBlob> string_blobs = string_bc.GetBlobs(dilatedimg); ushort[] string_labels = string_bc.objectLabels; List<TextString> initial_string_list = new List<TextString>(); int string_count = string_blobs.Count; for (int i = 0; i < string_count; i++) { initial_string_list.Add(new TextString()); initial_string_list.Last().mass_center = string_blobs[i].mass_center; } for (int i = 0; i < char_blobs.Count; i++) { if (char_blobs[i].bbx.Width > 1 && char_blobs[i].bbx.Height > 1) { char_blobs[i].string_id = string_labels[char_blobs[i].sample_y * width + char_blobs[i].sample_x] - 1; initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[i]); } } /* String BlobInside = ""; ////Added Part by Narges Honarvar Nazari //////// String Output_dir = @"C:\Users\nhonarva\Desktop\strabohome\output\"; Bitmap srcimg1 = new Bitmap(@"C:\Users\nhonarva\Desktop\MySamples\T-crop.png"); //////////// Show Blobs /////////////////// for (int i = 0; i < char_blobs.Count; i++) { Graphics g = Graphics.FromImage(srcimg1); g.DrawString(i.ToString(), font2, Brushes.Red, char_blobs[i].bbx.X, char_blobs[i].bbx.Y); g.DrawRectangle(new Pen(Color.Black, 3), char_blobs[i].bbx); Log.WriteBitmap2FolderExactFileName(Output_dir, srcimg1, "debug22.png"); } //////////// Show Blobs /////////////////// //////(char_blobs[i].string_id != char_blobs[j].string_id) /////// Investigating which blobs can be dot //////// for (int i = 0; i < char_blobs.Count; i++) { BlobInside = BlobInside +"Bigger Blob is : "+ i+Environment.NewLine; for (int j = 0; j < char_blobs.Count; j++) { if (((i != j) && (char_blobs[j].bbx.X + char_blobs[j].bbx.Width >= char_blobs[i].bbx.X) && (char_blobs[j].bbx.Y + char_blobs[j].bbx.Height >= char_blobs[i].bbx.Y) && (char_blobs[j].bbx.X + char_blobs[j].bbx.Width <= char_blobs[i].bbx.X + char_blobs[i].bbx.Width) && (char_blobs[j].bbx.Y + char_blobs[j].bbx.Height <= char_blobs[i].bbx.Y + char_blobs[i].bbx.Height)) || ((i != j) && (char_blobs[j].bbx.X >= char_blobs[i].bbx.X) && (char_blobs[j].bbx.Y >= char_blobs[i].bbx.Y) && (char_blobs[j].bbx.X <= char_blobs[i].bbx.X + char_blobs[i].bbx.Width) && (char_blobs[j].bbx.Y <= char_blobs[i].bbx.Y + char_blobs[i].bbx.Height)) || ((i != j) && (char_blobs[j].bbx.X + char_blobs[j].bbx.Width >= char_blobs[i].bbx.X) && (char_blobs[j].bbx.Y >= char_blobs[i].bbx.Y) && (char_blobs[j].bbx.X + char_blobs[j].bbx.Width <= char_blobs[i].bbx.X + char_blobs[i].bbx.Width) && (char_blobs[j].bbx.Y <= char_blobs[i].bbx.Y + char_blobs[i].bbx.Height)) || ((i != j) && (char_blobs[j].bbx.X >= char_blobs[i].bbx.X) && (char_blobs[j].bbx.Y + char_blobs[j].bbx.Height >= char_blobs[i].bbx.Y) && (char_blobs[j].bbx.X <= char_blobs[i].bbx.X + char_blobs[i].bbx.Width) && (char_blobs[j].bbx.Y + char_blobs[j].bbx.Height <= char_blobs[i].bbx.Y + char_blobs[i].bbx.Height))) { BlobInside = BlobInside + j+ Environment.NewLine; /* Rectangle FirstRectangle = new Rectangle(); FirstRectangle.Location = new Point(char_blobs[i].bbx.X, char_blobs[i].bbx.Y); FirstRectangle.Size = new Size(char_blobs[i].bbx.Width, char_blobs[i].bbx.Height); Rectangle SecondRectangle = new Rectangle(); SecondRectangle.Location = new Point(char_blobs[j].bbx.X, char_blobs[j].bbx.Y); SecondRectangle.Size = new Size(char_blobs[j].bbx.Width, char_blobs[j].bbx.Height); // if (FirstRectangle.IntersectsWith(SecondRectangle)) // { int FirstBlobWidthSize = char_blobs[i].bbx.Width; int FirstBlobHeightSize = char_blobs[i].bbx.Height; int SecondBlobWidthSize = char_blobs[j].bbx.Width; int SecondBlobHeigthSize = char_blobs[j].bbx.Height; int FirstBlobSize= 0; int SecondBlobSize = 0; int SizeRatio = 0; if (FirstBlobHeightSize > FirstBlobWidthSize) FirstBlobSize = FirstBlobHeightSize; else FirstBlobSize = FirstBlobWidthSize; if (SecondBlobHeigthSize > SecondBlobWidthSize) SecondBlobSize = SecondBlobHeigthSize; else SecondBlobSize = SecondBlobWidthSize; SizeRatio=FirstBlobSize/SecondBlobWidthSize; if (SizeRatio<25) initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[j]); */ /* if ((char_blobs[j].bbx.Width < 10 || char_blobs[j].bbx.Height < min_height)) { initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[j]); char_blobs2[j].string_id = 33333; } // } // initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[j]); // initial_string_list[char_blobs[i].string_id].AddChar(char_blobs[j]); } } } System.IO.File.WriteAllText(@"C:\Users\nhonarva\Desktop\MySamples\WriteText.txt", BlobInside); BlobInside = ""; for (int i = 0; i < initial_string_list.Count; i++) { BlobInside = BlobInside + "Bigger Blob is : " + i + Environment.NewLine; for (int j = 0; j < char_blobs2.Count; j++) { if (( (char_blobs2[j].bbx.X + char_blobs2[j].bbx.Width >= initial_string_list[i].bbx.X) && (char_blobs2[j].bbx.Y + char_blobs2[j].bbx.Height >= initial_string_list[i].bbx.Y) && (char_blobs2[j].bbx.X + char_blobs2[j].bbx.Width <= initial_string_list[i].bbx.X + initial_string_list[i].bbx.Width) && (char_blobs2[j].bbx.Y + char_blobs2[j].bbx.Height <= initial_string_list[i].bbx.Y + initial_string_list[i].bbx.Height)) || ((char_blobs2[j].bbx.X >= initial_string_list[i].bbx.X) && (char_blobs2[j].bbx.Y >= initial_string_list[i].bbx.Y) && (char_blobs2[j].bbx.X <= initial_string_list[i].bbx.X + initial_string_list[i].bbx.Width) && (char_blobs2[j].bbx.Y <= initial_string_list[i].bbx.Y + initial_string_list[i].bbx.Height)) || ((char_blobs2[j].bbx.X + char_blobs2[j].bbx.Width >= initial_string_list[i].bbx.X) && (char_blobs2[j].bbx.Y >= initial_string_list[i].bbx.Y) && (char_blobs2[j].bbx.X + char_blobs2[j].bbx.Width <= initial_string_list[i].bbx.X + initial_string_list[i].bbx.Width) && (char_blobs2[j].bbx.Y <= initial_string_list[i].bbx.Y + initial_string_list[i].bbx.Height)) || ((char_blobs2[j].bbx.X >= initial_string_list[i].bbx.X) && (char_blobs2[j].bbx.Y + char_blobs2[j].bbx.Height >= initial_string_list[i].bbx.Y) && (char_blobs2[j].bbx.X <= initial_string_list[i].bbx.X + initial_string_list[i].bbx.Width) && (char_blobs2[j].bbx.Y + char_blobs2[j].bbx.Height <= initial_string_list[i].bbx.Y + initial_string_list[i].bbx.Height))) { BlobInside = BlobInside + j + Environment.NewLine; if ((char_blobs2[j].string_id != 33333) && (char_blobs2[j].bbx.Width < 13) && (char_blobs2[j].bbx.Height <13)) { initial_string_list[i].AddChar(char_blobs2[j]); } // initial_string_list[i].AddChar(char_blobs[j]); } } } System.IO.File.WriteAllText(@"C:\Users\nhonarva\Desktop\MySamples\WriteText1.txt", BlobInside); /////// Investigating which blobs can be dot //////// ////Added Part by Narges Honarvar Nazari //////// */ for (int i = 0; i < initial_string_list.Count; i++) { if ((initial_string_list[i].char_list.Count == 0) ) { initial_string_list.RemoveAt(i); i--; } } for (int i = 0; i < initial_string_list.Count; i++) { PrintSubStringsSmall(char_labels, initial_string_list[i], 0); } return initial_string_list; }