ccmain/charcut.h File Reference

#include "pgedit.h"
#include "notdll.h"

Go to the source code of this file.

Classes

Functions


Function Documentation

void char_clip_word ( WERD word,
IMAGE bin_image,
PIXROW_LIST *&  pixrow_list,
IMAGELINE *&  imlines,
BOX pix_box 
)

Generate a PIXROW_LIST with one element for each blob in the word, together with the image lines for the whole word.

Parameters:
word word to be processed
bin_image whole image
pixrow_list pixrows built
imlines lines cut from image
pix_box box defining imlines
Note:
Global: pix_word_margin
Returns:
none

Definition at line 468 of file charcut.cpp.

References ASSERT_HOST, WERD::blob_list(), BOX::bottom(), WERD::bounding_box(), BUG_OFFSET, PIXROW::extend(), FALSE, WERD::flag(), generate_imlines(), IMAGE::get_xsize(), IMAGE::get_ysize(), BOX::height(), BOX::left(), BOX::move_bottom_edge(), BOX::move_left_edge(), BOX::move_right_edge(), BOX::move_top_edge(), NULL, and W_INVERSE.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), collect_characters_for_adaption(), and collect_ems_for_adaption().

00474                      {
00475   BOX word_box = word->bounding_box ();
00476   PBLOB_LIST *blob_list;
00477   PBLOB_IT blob_it;
00478   PIXROW_IT pixrow_it;
00479   INT16 pix_offset;              //Y pos of pixrow[0]
00480   INT16 row_height;              //No of pix rows
00481   INT16 imlines_x_offset;
00482   PIXROW *prev;
00483   PIXROW *next;
00484   PIXROW *current;
00485   BOOL8 changed;                 //still improving
00486   BOOL8 just_changed;            //still improving
00487   INT16 iteration_count = 0;
00488   INT16 foreground_colour;
00489 
00490   if (word->flag (W_INVERSE))
00491     foreground_colour = 1;
00492   else
00493     foreground_colour = 0;
00494 
00495   /* Define region for max pixrow expansion */
00496   pix_box = word_box;
00497   pix_box.move_bottom_edge (-pix_word_margin);
00498   pix_box.move_top_edge (pix_word_margin);
00499   pix_box.move_left_edge (-pix_word_margin);
00500   pix_box.move_right_edge (pix_word_margin);
00501   pix_box -= BOX (ICOORD (0, 0 + BUG_OFFSET),
00502     ICOORD (bin_image.get_xsize (),
00503     bin_image.get_ysize () - BUG_OFFSET));
00504 
00505   /* Generate pixrows list */
00506 
00507   pix_offset = pix_box.bottom ();
00508   row_height = pix_box.height ();
00509   blob_list = word->blob_list ();
00510   blob_it.set_to_list (blob_list);
00511 
00512   pixrow_list = new PIXROW_LIST;
00513   pixrow_it.set_to_list (pixrow_list);
00514 
00515   for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
00516     PIXROW *row = new PIXROW (pix_offset, row_height, blob_it.data ());
00517     ASSERT_HOST (!row->
00518       bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
00519     pixrow_it.add_after_then_move (row);
00520   }
00521 
00522   imlines = generate_imlines (bin_image, pix_box);
00523 
00524   /* Contract pixrows - shrink min and max back to black pixels */
00525 
00526   imlines_x_offset = pix_box.left ();
00527 
00528   pixrow_it.move_to_first ();
00529   for (pixrow_it.mark_cycle_pt ();
00530   !pixrow_it.cycled_list (); pixrow_it.forward ()) {
00531     ASSERT_HOST (!pixrow_it.data ()->
00532       bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
00533     pixrow_it.data ()->contract (imlines, imlines_x_offset,
00534       foreground_colour);
00535     ASSERT_HOST (!pixrow_it.data ()->
00536       bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
00537   }
00538 
00539   /* Expand pixrows iteratively 1 pixel at a time */
00540   do {
00541     changed = FALSE;
00542     pixrow_it.move_to_first ();
00543     prev = NULL;
00544     current = NULL;
00545     next = pixrow_it.data ();
00546     for (pixrow_it.mark_cycle_pt ();
00547     !pixrow_it.cycled_list (); pixrow_it.forward ()) {
00548       prev = current;
00549       current = next;
00550       if (pixrow_it.at_last ())
00551         next = NULL;
00552       else
00553         next = pixrow_it.data_relative (1);
00554       just_changed = current->extend (imlines, pix_box, prev, next,
00555         foreground_colour);
00556       ASSERT_HOST (!current->
00557         bad_box (bin_image.get_xsize (),
00558         bin_image.get_ysize ()));
00559       changed = changed || just_changed;
00560     }
00561     iteration_count++;
00562   }
00563   while (changed);
00564 }

WINDOW display_clip_image ( WERD word,
IMAGE bin_image,
PIXROW_LIST *  pixrow_list,
BOX pix_box 
)

All the boring user interface bits to let you see what's going on.

Parameters:
word word to be processed
bin_image whole image
pixrow_list pixrows built
pix_box box defining imlines
Returns:
image to be displayed

Definition at line 604 of file charcut.cpp.

References BLUE, BOX::bottom(), WERD::bounding_box(), BUG_OFFSET, clear_view_surface, create_window, FALSE, IMAGE::get_xsize(), IMAGE::get_ysize(), BOX::height(), INT_HOLLOW, BOX::left(), BOX::move_bottom_edge(), BOX::move_left_edge(), BOX::move_right_edge(), BOX::move_top_edge(), overlap_picture_ops, pgeditor_msg(), BOX::plot(), WERD::plot(), plot_pixrows(), RED, BOX::right(), SCROLLINGWIN, show_sub_image, BOX::top(), TRUE, and BOX::width().

Referenced by adapt_to_good_ems(), and adapt_to_good_samples().

00608                            {
00609   WINDOW clip_window;            //window for debug
00610   BOX word_box = word->bounding_box ();
00611   int border = word_box.height () / 2;
00612   BOX display_box = word_box;
00613 
00614   display_box.move_bottom_edge (-border);
00615   display_box.move_top_edge (border);
00616   display_box.move_left_edge (-border);
00617   display_box.move_right_edge (border);
00618   display_box -= BOX (ICOORD (0, 0 - BUG_OFFSET),
00619     ICOORD (bin_image.get_xsize (),
00620     bin_image.get_ysize () - BUG_OFFSET));
00621 
00622   pgeditor_msg ("Creating Clip window...");
00623   clip_window =
00624     create_window ("Clipped Blobs",
00625     SCROLLINGWIN,
00626     editor_word_xpos, editor_word_ypos,
00627     3 * (word_box.width () + 2 * border),
00628     3 * (word_box.height () + 2 * border),
00629   //window width,height
00630                                  // xmin, xmax
00631     display_box.left (), display_box.right (),
00632     display_box.bottom () - BUG_OFFSET,
00633     display_box.top () - BUG_OFFSET,
00634   // ymin, ymax
00635     TRUE, FALSE, FALSE, TRUE);   // down event & key only
00636   pgeditor_msg ("Creating Clip window...Done");
00637 
00638   clear_view_surface(clip_window); 
00639   show_sub_image (&bin_image,
00640     display_box.left (),
00641     display_box.bottom (),
00642     display_box.width (),
00643     display_box.height (),
00644     clip_window,
00645     display_box.left (), display_box.bottom () - BUG_OFFSET);
00646 
00647   word->plot (clip_window, RED);
00648   word_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE);
00649   pix_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE);
00650   plot_pixrows(pixrow_list, clip_window); 
00651   overlap_picture_ops(TRUE); 
00652   return clip_window;
00653 }

void display_images ( IMAGE clip_image,
IMAGE scaled_image 
)

Show a pair of clip and scaled character images and wait for key before continuing.

Definition at line 660 of file charcut.cpp.

References ANY_EVENT, await_event, clear_view_surface, create_window, destroy_window, draw2d, FALSE, IMAGE::get_xsize(), IMAGE::get_ysize(), line_color_index, move2d, overlap_picture_ops, RED, SCROLLINGWIN, show_sub_image, and TRUE.

00660                                                             {
00661   WINDOW clip_im_window;         //window for debug
00662   WINDOW scale_im_window;        //window for debug
00663   INT16 i;
00664   GRAPHICS_EVENT event;          // c;
00665 
00666                                  // xmin xmax ymin ymax
00667   clip_im_window = create_window ("Clipped Blob", SCROLLINGWIN,
00668    editor_word_xpos - 20, editor_word_ypos - 100,
00669    5 * clip_image.get_xsize (), 5 * clip_image.get_ysize (),
00670    0, clip_image.get_xsize (), 0, clip_image.get_ysize (),
00671     TRUE, FALSE, FALSE, TRUE);   // down event & key only
00672 
00673   clear_view_surface(clip_im_window); 
00674   show_sub_image (&clip_image,
00675     0, 0,
00676     clip_image.get_xsize (), clip_image.get_ysize (),
00677     clip_im_window, 0, 0);
00678 
00679   line_color_index(clip_im_window, RED); 
00680   for (i = 1; i < clip_image.get_xsize (); i++) {
00681     move2d (clip_im_window, i, 0);
00682     draw2d (clip_im_window, i, clip_image.get_xsize ());
00683   }
00684   for (i = 1; i < clip_image.get_ysize (); i++) {
00685     move2d (clip_im_window, 0, i);
00686     draw2d (clip_im_window, clip_image.get_xsize (), i);
00687   }
00688 
00689                                  // xmin xmax ymin ymax
00690   scale_im_window = create_window ("Scaled Blob", SCROLLINGWIN,
00691    editor_word_xpos + 300, editor_word_ypos - 100,
00692    5 * scaled_image.get_xsize (), 5 * scaled_image.get_ysize (),
00693    0, scaled_image.get_xsize (), 0, scaled_image.get_ysize (),
00694     TRUE, FALSE, FALSE, TRUE);   // down event & key only
00695 
00696   clear_view_surface(scale_im_window); 
00697   show_sub_image (&scaled_image,
00698     0, 0,
00699     scaled_image.get_xsize (), scaled_image.get_ysize (),
00700     scale_im_window, 0, 0);
00701 
00702   line_color_index(scale_im_window, RED); 
00703   for (i = 1; i < scaled_image.get_xsize (); i++) {
00704     move2d (scale_im_window, i, 0);
00705     draw2d (scale_im_window, i, scaled_image.get_xsize ());
00706   }
00707   for (i = 1; i < scaled_image.get_ysize (); i++) {
00708     move2d (scale_im_window, 0, i);
00709     draw2d (scale_im_window, scaled_image.get_xsize (), i);
00710   }
00711 
00712   overlap_picture_ops(TRUE); 
00713   await_event(scale_im_window, TRUE, ANY_EVENT, &event); 
00714   destroy_window(clip_im_window); 
00715   destroy_window(scale_im_window); 
00716 }

IMAGELINE* generate_imlines ( IMAGE bin_image,
BOX pix_box 
)

Get an array of IMAGELINES holding a portion of an image.

Parameters:
bin_image whole image (where we get some imagelines from)
pix_box box defining imlines
Returns:
imagelines within pix_box

Definition at line 574 of file charcut.cpp.

References BOX::bottom(), BUG_OFFSET, IMAGE::fast_get_line(), BOX::height(), BOX::left(), and BOX::width().

Referenced by char_clip_word().

00576                                           {
00577   IMAGELINE *imlines;            //array of lines
00578   int i;
00579 
00580   imlines = new IMAGELINE[pix_box.height ()];
00581   for (i = 0; i < pix_box.height (); i++) {
00582     imlines[i].init (pix_box.width ());
00583                                  //coord to start at
00584     bin_image.fast_get_line (pix_box.left (),
00585       pix_box.bottom () + i + BUG_OFFSET,
00586     //line to get
00587       pix_box.width (),          //width to get
00588       imlines + i);              //dest imline
00589   }
00590   return imlines;
00591 }

void plot_pixrows ( PIXROW_LIST *  pixrow_list,
WINDOW  win 
)

Display a list of pixrows [for all blobs].

Definition at line 722 of file charcut.cpp.

References INT_HOLLOW, interior_style, perimeter_color_index, RED, and TRUE.

Referenced by display_clip_image().

00724                               {
00725   PIXROW_IT pixrow_it(pixrow_list); 
00726   INT16 colour = RED;
00727 
00728   for (pixrow_it.mark_cycle_pt ();
00729   !pixrow_it.cycled_list (); pixrow_it.forward ()) {
00730     if (colour > RED + 7)
00731       colour = RED;
00732 
00733     perimeter_color_index (win, (COLOUR) colour);
00734     interior_style(win, INT_HOLLOW, TRUE); 
00735     pixrow_it.data ()->plot (win);
00736     colour++;
00737   }
00738 }


Generated on Wed Feb 28 19:49:14 2007 for Tesseract by  doxygen 1.5.1