All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::ImageFind Class Reference

#include <imagefind.h>

Static Public Member Functions

static Pix * FindImages (Pix *pix)
 
static void ConnCompAndRectangularize (Pix *pix, Boxa **boxa, Pixa **pixa)
 
static bool pixNearlyRectangular (Pix *pix, double min_fraction, double max_fraction, double max_skew_gradient, int *x_start, int *y_start, int *x_end, int *y_end)
 
static bool BoundsWithinRect (Pix *pix, int *x_start, int *y_start, int *x_end, int *y_end)
 
static double ColorDistanceFromLine (const uinT8 *line1, const uinT8 *line2, const uinT8 *point)
 
static uinT32 ComposeRGB (uinT32 r, uinT32 g, uinT32 b)
 
static uinT8 ClipToByte (double pixel)
 
static void ComputeRectangleColors (const TBOX &rect, Pix *pix, int factor, Pix *color_map1, Pix *color_map2, Pix *rms_map, uinT8 *color1, uinT8 *color2)
 
static bool BlankImageInBetween (const TBOX &box1, const TBOX &box2, const TBOX &im_box, const FCOORD &rotation, Pix *pix)
 
static int CountPixelsInRotatedBox (TBOX box, const TBOX &im_box, const FCOORD &rotation, Pix *pix)
 
static void TransferImagePartsToImageMask (const FCOORD &rerotation, ColPartitionGrid *part_grid, Pix *image_mask)
 
static void FindImagePartitions (Pix *image_pix, const FCOORD &rotation, const FCOORD &rerotation, TO_BLOCK *block, TabFind *tab_grid, ColPartitionGrid *part_grid, ColPartition_LIST *big_parts)
 

Detailed Description

Definition at line 42 of file imagefind.h.

Member Function Documentation

bool tesseract::ImageFind::BlankImageInBetween ( const TBOX box1,
const TBOX box2,
const TBOX im_box,
const FCOORD rotation,
Pix *  pix 
)
static

Definition at line 552 of file imagefind.cpp.

554  {
555  TBOX search_box(box1);
556  search_box += box2;
557  if (box1.x_gap(box2) >= box1.y_gap(box2)) {
558  if (box1.x_gap(box2) <= 0)
559  return true;
560  search_box.set_left(MIN(box1.right(), box2.right()));
561  search_box.set_right(MAX(box1.left(), box2.left()));
562  } else {
563  if (box1.y_gap(box2) <= 0)
564  return true;
565  search_box.set_top(MAX(box1.bottom(), box2.bottom()));
566  search_box.set_bottom(MIN(box1.top(), box2.top()));
567  }
568  return CountPixelsInRotatedBox(search_box, im_box, rotation, pix) == 0;
569 }
#define MAX(x, y)
Definition: ndminx.h:24
static int CountPixelsInRotatedBox(TBOX box, const TBOX &im_box, const FCOORD &rotation, Pix *pix)
Definition: imagefind.cpp:573
#define MIN(x, y)
Definition: ndminx.h:28
inT16 right() const
Definition: rect.h:75
void set_left(int x)
Definition: rect.h:71
inT16 left() const
Definition: rect.h:68
int y_gap(const TBOX &box) const
Definition: rect.h:225
inT16 bottom() const
Definition: rect.h:61
int x_gap(const TBOX &box) const
Definition: rect.h:217
Definition: rect.h:30
inT16 top() const
Definition: rect.h:54
bool tesseract::ImageFind::BoundsWithinRect ( Pix *  pix,
int *  x_start,
int *  y_start,
int *  x_end,
int *  y_end 
)
static

Definition at line 308 of file imagefind.cpp.

309  {
310  Box* input_box = boxCreate(*x_start, *y_start, *x_end - *x_start,
311  *y_end - *y_start);
312  Box* output_box = NULL;
313  pixClipBoxToForeground(pix, input_box, NULL, &output_box);
314  bool result = output_box != NULL;
315  if (result) {
316  l_int32 x, y, width, height;
317  boxGetGeometry(output_box, &x, &y, &width, &height);
318  *x_start = x;
319  *y_start = y;
320  *x_end = x + width;
321  *y_end = y + height;
322  boxDestroy(&output_box);
323  }
324  boxDestroy(&input_box);
325  return result;
326 }
#define NULL
Definition: host.h:144
uinT8 tesseract::ImageFind::ClipToByte ( double  pixel)
static

Definition at line 372 of file imagefind.cpp.

372  {
373  if (pixel < 0.0)
374  return 0;
375  else if (pixel >= 255.0)
376  return 255;
377  return static_cast<uinT8>(pixel);
378 }
unsigned char uinT8
Definition: host.h:99
double tesseract::ImageFind::ColorDistanceFromLine ( const uinT8 line1,
const uinT8 line2,
const uinT8 point 
)
static

Definition at line 331 of file imagefind.cpp.

333  {
334  int line_vector[kRGBRMSColors];
335  int point_vector[kRGBRMSColors];
336  for (int i = 0; i < kRGBRMSColors; ++i) {
337  line_vector[i] = static_cast<int>(line2[i]) - static_cast<int>(line1[i]);
338  point_vector[i] = static_cast<int>(point[i]) - static_cast<int>(line1[i]);
339  }
340  line_vector[L_ALPHA_CHANNEL] = 0;
341  // Now the cross product in 3d.
342  int cross[kRGBRMSColors];
343  cross[COLOR_RED] = line_vector[COLOR_GREEN] * point_vector[COLOR_BLUE]
344  - line_vector[COLOR_BLUE] * point_vector[COLOR_GREEN];
345  cross[COLOR_GREEN] = line_vector[COLOR_BLUE] * point_vector[COLOR_RED]
346  - line_vector[COLOR_RED] * point_vector[COLOR_BLUE];
347  cross[COLOR_BLUE] = line_vector[COLOR_RED] * point_vector[COLOR_GREEN]
348  - line_vector[COLOR_GREEN] * point_vector[COLOR_RED];
349  cross[L_ALPHA_CHANNEL] = 0;
350  // Now the sums of the squares.
351  double cross_sq = 0.0;
352  double line_sq = 0.0;
353  for (int j = 0; j < kRGBRMSColors; ++j) {
354  cross_sq += static_cast<double>(cross[j]) * cross[j];
355  line_sq += static_cast<double>(line_vector[j]) * line_vector[j];
356  }
357  if (line_sq == 0.0) {
358  return 0.0;
359  }
360  return cross_sq / line_sq; // This is the squared distance.
361 }
const int kRGBRMSColors
Definition: colpartition.h:36
uinT32 tesseract::ImageFind::ComposeRGB ( uinT32  r,
uinT32  g,
uinT32  b 
)
static

Definition at line 365 of file imagefind.cpp.

365  {
366  l_uint32 result;
367  composeRGBPixel(r, g, b, &result);
368  return result;
369 }
void tesseract::ImageFind::ComputeRectangleColors ( const TBOX rect,
Pix *  pix,
int  factor,
Pix *  color_map1,
Pix *  color_map2,
Pix *  rms_map,
uinT8 color1,
uinT8 color2 
)
static

Definition at line 390 of file imagefind.cpp.

393  {
394  ASSERT_HOST(pix != NULL && pixGetDepth(pix) == 32);
395  // Pad the rectangle outwards by 2 (scaled) pixels if possible to get more
396  // background.
397  int width = pixGetWidth(pix);
398  int height = pixGetHeight(pix);
399  int left_pad = MAX(rect.left() - 2 * factor, 0) / factor;
400  int top_pad = (rect.top() + 2 * factor + (factor - 1)) / factor;
401  top_pad = MIN(height, top_pad);
402  int right_pad = (rect.right() + 2 * factor + (factor - 1)) / factor;
403  right_pad = MIN(width, right_pad);
404  int bottom_pad = MAX(rect.bottom() - 2 * factor, 0) / factor;
405  int width_pad = right_pad - left_pad;
406  int height_pad = top_pad - bottom_pad;
407  if (width_pad < 1 || height_pad < 1 || width_pad + height_pad < 4)
408  return;
409  // Now crop the pix to the rectangle.
410  Box* scaled_box = boxCreate(left_pad, height - top_pad,
411  width_pad, height_pad);
412  Pix* scaled = pixClipRectangle(pix, scaled_box, NULL);
413 
414  // Compute stats over the whole image.
415  STATS red_stats(0, 256);
416  STATS green_stats(0, 256);
417  STATS blue_stats(0, 256);
418  uinT32* data = pixGetData(scaled);
419  ASSERT_HOST(pixGetWpl(scaled) == width_pad);
420  for (int y = 0; y < height_pad; ++y) {
421  for (int x = 0; x < width_pad; ++x, ++data) {
422  int r = GET_DATA_BYTE(data, COLOR_RED);
423  int g = GET_DATA_BYTE(data, COLOR_GREEN);
424  int b = GET_DATA_BYTE(data, COLOR_BLUE);
425  red_stats.add(r, 1);
426  green_stats.add(g, 1);
427  blue_stats.add(b, 1);
428  }
429  }
430  // Find the RGB component with the greatest 8th-ile-range.
431  // 8th-iles are used instead of quartiles to get closer to the true
432  // foreground color, which is going to be faint at best because of the
433  // pre-scaling of the input image.
434  int best_l8 = static_cast<int>(red_stats.ile(0.125f));
435  int best_u8 = static_cast<int>(ceil(red_stats.ile(0.875f)));
436  int best_i8r = best_u8 - best_l8;
437  int x_color = COLOR_RED;
438  int y1_color = COLOR_GREEN;
439  int y2_color = COLOR_BLUE;
440  int l8 = static_cast<int>(green_stats.ile(0.125f));
441  int u8 = static_cast<int>(ceil(green_stats.ile(0.875f)));
442  if (u8 - l8 > best_i8r) {
443  best_i8r = u8 - l8;
444  best_l8 = l8;
445  best_u8 = u8;
446  x_color = COLOR_GREEN;
447  y1_color = COLOR_RED;
448  }
449  l8 = static_cast<int>(blue_stats.ile(0.125f));
450  u8 = static_cast<int>(ceil(blue_stats.ile(0.875f)));
451  if (u8 - l8 > best_i8r) {
452  best_i8r = u8 - l8;
453  best_l8 = l8;
454  best_u8 = u8;
455  x_color = COLOR_BLUE;
456  y1_color = COLOR_GREEN;
457  y2_color = COLOR_RED;
458  }
459  if (best_i8r >= kMinColorDifference) {
460  LLSQ line1;
461  LLSQ line2;
462  uinT32* data = pixGetData(scaled);
463  for (int im_y = 0; im_y < height_pad; ++im_y) {
464  for (int im_x = 0; im_x < width_pad; ++im_x, ++data) {
465  int x = GET_DATA_BYTE(data, x_color);
466  int y1 = GET_DATA_BYTE(data, y1_color);
467  int y2 = GET_DATA_BYTE(data, y2_color);
468  line1.add(x, y1);
469  line2.add(x, y2);
470  }
471  }
472  double m1 = line1.m();
473  double c1 = line1.c(m1);
474  double m2 = line2.m();
475  double c2 = line2.c(m2);
476  double rms = line1.rms(m1, c1) + line2.rms(m2, c2);
477  rms *= kRMSFitScaling;
478  // Save the results.
479  color1[x_color] = ClipToByte(best_l8);
480  color1[y1_color] = ClipToByte(m1 * best_l8 + c1 + 0.5);
481  color1[y2_color] = ClipToByte(m2 * best_l8 + c2 + 0.5);
482  color1[L_ALPHA_CHANNEL] = ClipToByte(rms);
483  color2[x_color] = ClipToByte(best_u8);
484  color2[y1_color] = ClipToByte(m1 * best_u8 + c1 + 0.5);
485  color2[y2_color] = ClipToByte(m2 * best_u8 + c2 + 0.5);
486  color2[L_ALPHA_CHANNEL] = ClipToByte(rms);
487  } else {
488  // There is only one color.
489  color1[COLOR_RED] = ClipToByte(red_stats.median());
490  color1[COLOR_GREEN] = ClipToByte(green_stats.median());
491  color1[COLOR_BLUE] = ClipToByte(blue_stats.median());
492  color1[L_ALPHA_CHANNEL] = 0;
493  memcpy(color2, color1, 4);
494  }
495  if (color_map1 != NULL) {
496  pixSetInRectArbitrary(color_map1, scaled_box,
497  ComposeRGB(color1[COLOR_RED],
498  color1[COLOR_GREEN],
499  color1[COLOR_BLUE]));
500  pixSetInRectArbitrary(color_map2, scaled_box,
501  ComposeRGB(color2[COLOR_RED],
502  color2[COLOR_GREEN],
503  color2[COLOR_BLUE]));
504  pixSetInRectArbitrary(rms_map, scaled_box, color1[L_ALPHA_CHANNEL]);
505  }
506  pixDestroy(&scaled);
507  boxDestroy(&scaled_box);
508 }
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28
Definition: statistc.h:33
double rms(double m, double c) const
Definition: linlsq.cpp:131
inT16 right() const
Definition: rect.h:75
Definition: linlsq.h:26
#define ASSERT_HOST(x)
Definition: errcode.h:84
double m() const
Definition: linlsq.cpp:101
unsigned int uinT32
Definition: host.h:103
inT16 left() const
Definition: rect.h:68
double c(double m) const
Definition: linlsq.cpp:117
void add(double x, double y)
Definition: linlsq.cpp:49
inT16 bottom() const
Definition: rect.h:61
const double kRMSFitScaling
Definition: imagefind.cpp:53
const int kMinColorDifference
Definition: imagefind.cpp:55
static uinT32 ComposeRGB(uinT32 r, uinT32 g, uinT32 b)
Definition: imagefind.cpp:365
#define NULL
Definition: host.h:144
static uinT8 ClipToByte(double pixel)
Definition: imagefind.cpp:372
inT16 top() const
Definition: rect.h:54
void tesseract::ImageFind::ConnCompAndRectangularize ( Pix *  pix,
Boxa **  boxa,
Pixa **  pixa 
)
static

Definition at line 133 of file imagefind.cpp.

133  {
134  *boxa = NULL;
135  *pixa = NULL;
136 
138  pixWrite("junkconncompimage.png", pix, IFF_PNG);
139  // Find the individual image regions in the mask image.
140  *boxa = pixConnComp(pix, pixa, 8);
141  // Rectangularize the individual images. If a sharp edge in vertical and/or
142  // horizontal occupancy can be found, it indicates a probably rectangular
143  // image with unwanted bits merged on, so clip to the approximate rectangle.
144  int npixes = pixaGetCount(*pixa);
145  for (int i = 0; i < npixes; ++i) {
146  int x_start, x_end, y_start, y_end;
147  Pix* img_pix = pixaGetPix(*pixa, i, L_CLONE);
148  pixDisplayWrite(img_pix, textord_tabfind_show_images);
152  &x_start, &y_start, &x_end, &y_end)) {
153  Pix* simple_pix = pixCreate(x_end - x_start, y_end - y_start, 1);
154  pixSetAll(simple_pix);
155  pixDestroy(&img_pix);
156  // pixaReplacePix takes ownership of the simple_pix.
157  pixaReplacePix(*pixa, i, simple_pix, NULL);
158  img_pix = pixaGetPix(*pixa, i, L_CLONE);
159  // Fix the box to match the new pix.
160  l_int32 x, y, width, height;
161  boxaGetBoxGeometry(*boxa, i, &x, &y, &width, &height);
162  Box* simple_box = boxCreate(x + x_start, y + y_start,
163  x_end - x_start, y_end - y_start);
164  boxaReplaceBox(*boxa, i, simple_box);
165  }
166  pixDestroy(&img_pix);
167  }
168 }
const double kMaxRectangularFraction
Definition: imagefind.cpp:46
int textord_tabfind_show_images
Definition: imagefind.cpp:38
const double kMinRectangularFraction
Definition: imagefind.cpp:44
const double kMaxRectangularGradient
Definition: imagefind.cpp:49
static bool pixNearlyRectangular(Pix *pix, double min_fraction, double max_fraction, double max_skew_gradient, int *x_start, int *y_start, int *x_end, int *y_end)
Definition: imagefind.cpp:242
#define NULL
Definition: host.h:144
int tesseract::ImageFind::CountPixelsInRotatedBox ( TBOX  box,
const TBOX im_box,
const FCOORD rotation,
Pix *  pix 
)
static

Definition at line 573 of file imagefind.cpp.

574  {
575  // Intersect it with the image box.
576  box &= im_box; // This is in-place box intersection.
577  if (box.null_box())
578  return 0;
579  box.rotate(rotation);
580  TBOX rotated_im_box(im_box);
581  rotated_im_box.rotate(rotation);
582  Pix* rect_pix = pixCreate(box.width(), box.height(), 1);
583  pixRasterop(rect_pix, 0, 0, box.width(), box.height(),
584  PIX_SRC, pix, box.left() - rotated_im_box.left(),
585  rotated_im_box.top() - box.top());
586  l_int32 result;
587  pixCountPixels(rect_pix, &result, NULL);
588  pixDestroy(&rect_pix);
589  return result;
590 }
bool null_box() const
Definition: rect.h:46
inT16 left() const
Definition: rect.h:68
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111
Definition: rect.h:30
#define NULL
Definition: host.h:144
inT16 top() const
Definition: rect.h:54
void rotate(const FCOORD &vec)
Definition: rect.h:189
void tesseract::ImageFind::FindImagePartitions ( Pix *  image_pix,
const FCOORD rotation,
const FCOORD rerotation,
TO_BLOCK block,
TabFind tab_grid,
ColPartitionGrid part_grid,
ColPartition_LIST *  big_parts 
)
static

Definition at line 1274 of file imagefind.cpp.

1280  {
1281  int imageheight = pixGetHeight(image_pix);
1282  Boxa* boxa;
1283  Pixa* pixa;
1284  ConnCompAndRectangularize(image_pix, &boxa, &pixa);
1285  // Iterate the connected components in the image regions mask.
1286  int nboxes = boxaGetCount(boxa);
1287  for (int i = 0; i < nboxes; ++i) {
1288  l_int32 x, y, width, height;
1289  boxaGetBoxGeometry(boxa, i, &x, &y, &width, &height);
1290  Pix* pix = pixaGetPix(pixa, i, L_CLONE);
1291  TBOX im_box(x, imageheight -y - height, x + width, imageheight - y);
1292  im_box.rotate(rotation); // Now matches all partitions and blobs.
1293  ColPartitionGridSearch rectsearch(part_grid);
1294  rectsearch.SetUniqueMode(true);
1295  ColPartition_LIST part_list;
1296  DivideImageIntoParts(im_box, rotation, rerotation, pix,
1297  &rectsearch, &part_list);
1299  pixWrite("junkimagecomponent.png", pix, IFF_PNG);
1300  tprintf("Component has %d parts\n", part_list.length());
1301  }
1302  pixDestroy(&pix);
1303  if (!part_list.empty()) {
1304  ColPartition_IT part_it(&part_list);
1305  if (part_list.singleton()) {
1306  // We didn't have to chop it into a polygon to fit around text, so
1307  // try expanding it to merge fragmented image parts, as long as it
1308  // doesn't touch strong text.
1309  ColPartition* part = part_it.extract();
1310  TBOX text_box(im_box);
1311  MaximalImageBoundingBox(part_grid, &text_box);
1312  while (ExpandImageIntoParts(text_box, &rectsearch, part_grid, &part));
1313  part_it.set_to_list(&part_list);
1314  part_it.add_after_then_move(part);
1315  im_box = part->bounding_box();
1316  }
1317  EliminateWeakParts(im_box, part_grid, big_parts, &part_list);
1318  // Iterate the part_list and put the parts into the grid.
1319  for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
1320  ColPartition* image_part = part_it.extract();
1321  im_box = image_part->bounding_box();
1322  part_grid->InsertBBox(true, true, image_part);
1323  if (!part_it.at_last()) {
1324  ColPartition* neighbour = part_it.data_relative(1);
1325  image_part->AddPartner(false, neighbour);
1326  neighbour->AddPartner(true, image_part);
1327  }
1328  }
1329  }
1330  }
1331  boxaDestroy(&boxa);
1332  pixaDestroy(&pixa);
1333  DeleteSmallImages(part_grid);
1335  ScrollView* images_win_ = part_grid->MakeWindow(1000, 400, "With Images");
1336  part_grid->DisplayBoxes(images_win_);
1337  }
1338 }
#define tprintf(...)
Definition: tprintf.h:31
int textord_tabfind_show_images
Definition: imagefind.cpp:38
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
Definition: colpartition.h:913
Definition: rect.h:30
static void ConnCompAndRectangularize(Pix *pix, Boxa **boxa, Pixa **pixa)
Definition: imagefind.cpp:133
Pix * tesseract::ImageFind::FindImages ( Pix *  pix)
static

Definition at line 65 of file imagefind.cpp.

65  {
66  // Not worth looking at small images.
67  if (pixGetWidth(pix) < kMinImageFindSize ||
68  pixGetHeight(pix) < kMinImageFindSize)
69  return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
70  // Reduce by factor 2.
71  Pix *pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
72  pixDisplayWrite(pixr, textord_tabfind_show_images);
73 
74  // Get the halftone mask directly from Leptonica.
75  l_int32 ht_found = 0;
76  Pix *pixht2 = pixGenHalftoneMask(pixr, NULL, &ht_found,
78  pixDestroy(&pixr);
79  if (!ht_found && pixht2 != NULL)
80  pixDestroy(&pixht2);
81  if (pixht2 == NULL)
82  return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
83 
84  // Expand back up again.
85  Pix *pixht = pixExpandReplicate(pixht2, 2);
86  pixDisplayWrite(pixht, textord_tabfind_show_images);
87  pixDestroy(&pixht2);
88 
89  // Fill to capture pixels near the mask edges that were missed
90  Pix *pixt = pixSeedfillBinary(NULL, pixht, pix, 8);
91  pixOr(pixht, pixht, pixt);
92  pixDestroy(&pixt);
93 
94  // Eliminate lines and bars that may be joined to images.
95  Pix* pixfinemask = pixReduceRankBinaryCascade(pixht, 1, 1, 3, 3);
96  pixDilateBrick(pixfinemask, pixfinemask, 5, 5);
97  pixDisplayWrite(pixfinemask, textord_tabfind_show_images);
98  Pix* pixreduced = pixReduceRankBinaryCascade(pixht, 1, 1, 1, 1);
99  Pix* pixreduced2 = pixReduceRankBinaryCascade(pixreduced, 3, 3, 3, 0);
100  pixDestroy(&pixreduced);
101  pixDilateBrick(pixreduced2, pixreduced2, 5, 5);
102  Pix* pixcoarsemask = pixExpandReplicate(pixreduced2, 8);
103  pixDestroy(&pixreduced2);
104  pixDisplayWrite(pixcoarsemask, textord_tabfind_show_images);
105  // Combine the coarse and fine image masks.
106  pixAnd(pixcoarsemask, pixcoarsemask, pixfinemask);
107  pixDestroy(&pixfinemask);
108  // Dilate a bit to make sure we get everything.
109  pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
110  Pix* pixmask = pixExpandReplicate(pixcoarsemask, 16);
111  pixDestroy(&pixcoarsemask);
113  pixWrite("junkexpandedcoarsemask.png", pixmask, IFF_PNG);
114  // And the image mask with the line and bar remover.
115  pixAnd(pixht, pixht, pixmask);
116  pixDestroy(&pixmask);
118  pixWrite("junkfinalimagemask.png", pixht, IFF_PNG);
119  // Make the result image the same size as the input.
120  Pix* result = pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
121  pixOr(result, result, pixht);
122  pixDestroy(&pixht);
123  return result;
124 }
int textord_tabfind_show_images
Definition: imagefind.cpp:38
const int kMinImageFindSize
Definition: imagefind.cpp:51
#define NULL
Definition: host.h:144
bool tesseract::ImageFind::pixNearlyRectangular ( Pix *  pix,
double  min_fraction,
double  max_fraction,
double  max_skew_gradient,
int *  x_start,
int *  y_start,
int *  x_end,
int *  y_end 
)
static

Definition at line 242 of file imagefind.cpp.

246  {
247  ASSERT_HOST(pix != NULL);
248  *x_start = 0;
249  *x_end = pixGetWidth(pix);
250  *y_start = 0;
251  *y_end = pixGetHeight(pix);
252 
253  uinT32* data = pixGetData(pix);
254  int wpl = pixGetWpl(pix);
255  bool any_cut = false;
256  bool left_done = false;
257  bool right_done = false;
258  bool top_done = false;
259  bool bottom_done = false;
260  do {
261  any_cut = false;
262  // Find the top/bottom edges.
263  int width = *x_end - *x_start;
264  int min_count = static_cast<int>(width * min_fraction);
265  int max_count = static_cast<int>(width * max_fraction);
266  int edge_width = static_cast<int>(width * max_skew_gradient);
267  if (HScanForEdge(data, wpl, *x_start, *x_end, min_count, edge_width,
268  max_count, *y_end, 1, y_start) && !top_done) {
269  top_done = true;
270  any_cut = true;
271  }
272  --(*y_end);
273  if (HScanForEdge(data, wpl, *x_start, *x_end, min_count, edge_width,
274  max_count, *y_start, -1, y_end) && !bottom_done) {
275  bottom_done = true;
276  any_cut = true;
277  }
278  ++(*y_end);
279 
280  // Find the left/right edges.
281  int height = *y_end - *y_start;
282  min_count = static_cast<int>(height * min_fraction);
283  max_count = static_cast<int>(height * max_fraction);
284  edge_width = static_cast<int>(height * max_skew_gradient);
285  if (VScanForEdge(data, wpl, *y_start, *y_end, min_count, edge_width,
286  max_count, *x_end, 1, x_start) && !left_done) {
287  left_done = true;
288  any_cut = true;
289  }
290  --(*x_end);
291  if (VScanForEdge(data, wpl, *y_start, *y_end, min_count, edge_width,
292  max_count, *x_start, -1, x_end) && !right_done) {
293  right_done = true;
294  any_cut = true;
295  }
296  ++(*x_end);
297  } while (any_cut);
298 
299  // All edges must satisfy the condition of sharp gradient in pixel density
300  // in order for the full rectangle to be present.
301  return left_done && right_done && top_done && bottom_done;
302 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
unsigned int uinT32
Definition: host.h:103
#define NULL
Definition: host.h:144
void tesseract::ImageFind::TransferImagePartsToImageMask ( const FCOORD rerotation,
ColPartitionGrid part_grid,
Pix *  image_mask 
)
static

Definition at line 1221 of file imagefind.cpp.

1223  {
1224  // Extract the noise parts from the grid and put them on a temporary list.
1225  ColPartition_LIST parts_list;
1226  ColPartition_IT part_it(&parts_list);
1227  ColPartitionGridSearch gsearch(part_grid);
1228  gsearch.StartFullSearch();
1229  ColPartition* part;
1230  while ((part = gsearch.NextFullSearch()) != NULL) {
1231  BlobRegionType type = part->blob_type();
1232  if (type == BRT_NOISE || type == BRT_RECTIMAGE || type == BRT_POLYIMAGE) {
1233  part_it.add_after_then_move(part);
1234  gsearch.RemoveBBox();
1235  }
1236  }
1237  // Render listed noise partitions to the image mask.
1238  MarkAndDeleteImageParts(rerotation, part_grid, &parts_list, image_mask);
1239 }
BlobRegionType
Definition: blobbox.h:57
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
Definition: colpartition.h:913
#define NULL
Definition: host.h:144

The documentation for this class was generated from the following files: