Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 553 of file imagefind.cpp.

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

Definition at line 309 of file imagefind.cpp.

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

Definition at line 373 of file imagefind.cpp.

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

Definition at line 332 of file imagefind.cpp.

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

Definition at line 366 of file imagefind.cpp.

366  {
367  l_uint32 result;
368  composeRGBPixel(r, g, b, &result);
369  return result;
370 }
#define g(oldyc, yc, oldxc, xc)
Definition: imgscale.cpp:41
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 391 of file imagefind.cpp.

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

Definition at line 134 of file imagefind.cpp.

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

Definition at line 574 of file imagefind.cpp.

575  {
576  // Intersect it with the image box.
577  box &= im_box; // This is in-place box intersection.
578  if (box.null_box())
579  return 0;
580  box.rotate(rotation);
581  TBOX rotated_im_box(im_box);
582  rotated_im_box.rotate(rotation);
583  Pix* rect_pix = pixCreate(box.width(), box.height(), 1);
584  pixRasterop(rect_pix, 0, 0, box.width(), box.height(),
585  PIX_SRC, pix, box.left() - rotated_im_box.left(),
586  rotated_im_box.top() - box.top());
587  l_int32 result;
588  pixCountPixels(rect_pix, &result, NULL);
589  pixDestroy(&rect_pix);
590  return result;
591 }
bool null_box() const
Definition: rect.h:45
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
inT16 width() const
Definition: rect.h:104
Definition: rect.h:29
inT16 top() const
Definition: rect.h:53
void rotate(const FCOORD &vec)
Definition: rect.h:182
inT16 height() const
Definition: rect.h:97
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 1275 of file imagefind.cpp.

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

Definition at line 66 of file imagefind.cpp.

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

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

Definition at line 1222 of file imagefind.cpp.

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

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