tesseract  3.03
DENORM Class Reference

#include <normalis.h>

List of all members.

Public Member Functions

 DENORM ()
 DENORM (const DENORM &)
DENORMoperator= (const DENORM &)
 ~DENORM ()
void SetupNormalization (const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
void SetupNonLinear (const DENORM *predecessor, const TBOX &box, float target_width, float target_height, float final_xshift, float final_yshift, const GenericVector< GenericVector< int > > &x_coords, const GenericVector< GenericVector< int > > &y_coords)
void LocalNormTransform (const TPOINT &pt, TPOINT *transformed) const
void LocalNormTransform (const FCOORD &pt, FCOORD *transformed) const
void NormTransform (const DENORM *first_norm, const TPOINT &pt, TPOINT *transformed) const
void NormTransform (const DENORM *first_norm, const FCOORD &pt, FCOORD *transformed) const
void LocalDenormTransform (const TPOINT &pt, TPOINT *original) const
void LocalDenormTransform (const FCOORD &pt, FCOORD *original) const
void DenormTransform (const DENORM *last_denorm, const TPOINT &pt, TPOINT *original) const
void DenormTransform (const DENORM *last_denorm, const FCOORD &pt, FCOORD *original) const
void LocalNormBlob (TBLOB *blob) const
void XHeightRange (int unichar_id, const UNICHARSET &unicharset, const TBOX &bbox, float *min_xht, float *max_xht, float *yshift) const
void Print () const
Pix * pix () const
void set_pix (Pix *pix)
bool inverse () const
void set_inverse (bool value)
const DENORMRootDenorm () const
const DENORMpredecessor () const
float x_scale () const
float y_scale () const
const BLOCKblock () const
void set_block (const BLOCK *block)

Detailed Description

Definition at line 52 of file normalis.h.


Constructor & Destructor Documentation

Definition at line 37 of file normalis.cpp.

               {
  Init();
}
DENORM::DENORM ( const DENORM src)

Definition at line 41 of file normalis.cpp.

                                {
  rotation_ = NULL;
  *this = src;
}

Definition at line 66 of file normalis.cpp.

                {
  Clear();
}

Member Function Documentation

const BLOCK* DENORM::block ( ) const [inline]

Definition at line 275 of file normalis.h.

                             {
    return block_;
  }
void DENORM::DenormTransform ( const DENORM last_denorm,
const TPOINT pt,
TPOINT original 
) const

Definition at line 389 of file normalis.cpp.

                                                     {
  FCOORD src_pt(pt.x, pt.y);
  FCOORD float_result;
  DenormTransform(last_denorm, src_pt, &float_result);
  original->x = IntCastRounded(float_result.x());
  original->y = IntCastRounded(float_result.y());
}
void DENORM::DenormTransform ( const DENORM last_denorm,
const FCOORD pt,
FCOORD original 
) const

Definition at line 397 of file normalis.cpp.

                                                     {
  LocalDenormTransform(pt, original);
  if (last_denorm != this) {
    if (predecessor_ != NULL) {
      predecessor_->DenormTransform(last_denorm, *original, original);
    } else if (block_ != NULL) {
      original->rotate(block_->re_rotation());
    }
  }
}
bool DENORM::inverse ( ) const [inline]

Definition at line 254 of file normalis.h.

                       {
    return inverse_;
  }
void DENORM::LocalDenormTransform ( const TPOINT pt,
TPOINT original 
) const

Definition at line 359 of file normalis.cpp.

                                                                          {
  FCOORD src_pt(pt.x, pt.y);
  FCOORD float_result;
  LocalDenormTransform(src_pt, &float_result);
  original->x = IntCastRounded(float_result.x());
  original->y = IntCastRounded(float_result.y());
}
void DENORM::LocalDenormTransform ( const FCOORD pt,
FCOORD original 
) const

Definition at line 366 of file normalis.cpp.

                                                                          {
  FCOORD rotated(pt.x() - final_xshift_, pt.y() - final_yshift_);
  if (x_map_ != NULL && y_map_ != NULL) {
    int x = x_map_->binary_search(rotated.x());
    original->set_x(x + x_origin_);
    int y = y_map_->binary_search(rotated.y());
    original->set_y(y + y_origin_);
  } else {
    if (rotation_ != NULL) {
      FCOORD inverse_rotation(rotation_->x(), -rotation_->y());
      rotated.rotate(inverse_rotation);
    }
    original->set_x(rotated.x() / x_scale_ + x_origin_);
    float y_scale = y_scale_;
    original->set_y(rotated.y() / y_scale + y_origin_);
  }
}
void DENORM::LocalNormBlob ( TBLOB blob) const

Definition at line 411 of file normalis.cpp.

                                            {
  TBOX blob_box = blob->bounding_box();
  ICOORD translation(-IntCastRounded(x_origin_), -IntCastRounded(y_origin_));
  blob->Move(translation);
  if (y_scale_ != 1.0f)
    blob->Scale(y_scale_);
  if (rotation_ != NULL)
    blob->Rotate(*rotation_);
  translation.set_x(IntCastRounded(final_xshift_));
  translation.set_y(IntCastRounded(final_yshift_));
  blob->Move(translation);
}
void DENORM::LocalNormTransform ( const TPOINT pt,
TPOINT transformed 
) const

Definition at line 305 of file normalis.cpp.

                                                                           {
  FCOORD src_pt(pt.x, pt.y);
  FCOORD float_result;
  LocalNormTransform(src_pt, &float_result);
  transformed->x = IntCastRounded(float_result.x());
  transformed->y = IntCastRounded(float_result.y());
}
void DENORM::LocalNormTransform ( const FCOORD pt,
FCOORD transformed 
) const

Definition at line 312 of file normalis.cpp.

                                                                           {
  FCOORD translated(pt.x() - x_origin_, pt.y() - y_origin_);
  if (x_map_ != NULL && y_map_ != NULL) {
    int x = ClipToRange(IntCastRounded(translated.x()), 0, x_map_->size()-1);
    translated.set_x((*x_map_)[x]);
    int y = ClipToRange(IntCastRounded(translated.y()), 0, y_map_->size()-1);
    translated.set_y((*y_map_)[y]);
  } else {
    translated.set_x(translated.x() * x_scale_);
    translated.set_y(translated.y() * y_scale_);
    if (rotation_ != NULL)
      translated.rotate(*rotation_);
  }
  transformed->set_x(translated.x() + final_xshift_);
  transformed->set_y(translated.y() + final_yshift_);
}
void DENORM::NormTransform ( const DENORM first_norm,
const TPOINT pt,
TPOINT transformed 
) const

Definition at line 334 of file normalis.cpp.

                                                      {
  FCOORD src_pt(pt.x, pt.y);
  FCOORD float_result;
  NormTransform(first_norm, src_pt, &float_result);
  transformed->x = IntCastRounded(float_result.x());
  transformed->y = IntCastRounded(float_result.y());
}
void DENORM::NormTransform ( const DENORM first_norm,
const FCOORD pt,
FCOORD transformed 
) const

Definition at line 342 of file normalis.cpp.

                                                      {
  FCOORD src_pt(pt);
  if (first_norm != this) {
    if (predecessor_ != NULL) {
      predecessor_->NormTransform(first_norm, pt, &src_pt);
    } else if (block_ != NULL) {
      FCOORD fwd_rotation(block_->re_rotation().x(),
                          -block_->re_rotation().y());
      src_pt.rotate(fwd_rotation);
    }
  }
  LocalNormTransform(src_pt, transformed);
}
DENORM & DENORM::operator= ( const DENORM src)

Definition at line 47 of file normalis.cpp.

                                             {
  Clear();
  inverse_ = src.inverse_;
  predecessor_ = src.predecessor_;
  pix_ = src.pix_;
  block_ = src.block_;
  if (src.rotation_ == NULL)
    rotation_ = NULL;
  else
    rotation_ = new FCOORD(*src.rotation_);
  x_origin_ = src.x_origin_;
  y_origin_ = src.y_origin_;
  x_scale_ = src.x_scale_;
  y_scale_ = src.y_scale_;
  final_xshift_ = src.final_xshift_;
  final_yshift_ = src.final_yshift_;
  return *this;
}
Pix* DENORM::pix ( ) const [inline]

Definition at line 248 of file normalis.h.

                   {
    return pix_;
  }
const DENORM* DENORM::predecessor ( ) const [inline]

Definition at line 265 of file normalis.h.

                                    {
    return predecessor_;
  }
void DENORM::Print ( ) const

Definition at line 505 of file normalis.cpp.

                         {
  if (pix_ != NULL) {
    tprintf("Pix dimensions %d x %d x %d\n",
            pixGetWidth(pix_), pixGetHeight(pix_), pixGetDepth(pix_));
  }
  if (inverse_)
    tprintf("Inverse\n");
  if (block_ && block_->re_rotation().x() != 1.0f) {
    tprintf("Block rotation %g, %g\n",
            block_->re_rotation().x(), block_->re_rotation().y());
  }
  tprintf("Input Origin = (%g, %g)\n", x_origin_, y_origin_);
  if (x_map_ != NULL && y_map_ != NULL) {
    tprintf("x map:\n");
    for (int x = 0; x < x_map_->size(); ++x) {
      tprintf("%g ", (*x_map_)[x]);
    }
    tprintf("\ny map:\n");
    for (int y = 0; y < y_map_->size(); ++y) {
      tprintf("%g ", (*y_map_)[y]);
    }
    tprintf("\n");
  } else {
    tprintf("Scale = (%g, %g)\n", x_scale_, y_scale_);
    if (rotation_ != NULL)
      tprintf("Rotation = (%g, %g)\n", rotation_->x(), rotation_->y());
  }
  tprintf("Final Origin = (%g, %g)\n", final_xshift_, final_xshift_);
  if (predecessor_ != NULL) {
    tprintf("Predecessor:\n");
    predecessor_->Print();
  }
}
const DENORM* DENORM::RootDenorm ( ) const [inline]

Definition at line 260 of file normalis.h.

                                   {
    if (predecessor_ != NULL)
      return predecessor_->RootDenorm();
    return this;
  }
void DENORM::set_block ( const BLOCK block) [inline]

Definition at line 278 of file normalis.h.

                                     {
    block_ = block;
  }
void DENORM::set_inverse ( bool  value) [inline]

Definition at line 257 of file normalis.h.

                               {
    inverse_ = value;
  }
void DENORM::set_pix ( Pix *  pix) [inline]

Definition at line 251 of file normalis.h.

                         {
    pix_ = pix;
  }
void DENORM::SetupNonLinear ( const DENORM predecessor,
const TBOX box,
float  target_width,
float  target_height,
float  final_xshift,
float  final_yshift,
const GenericVector< GenericVector< int > > &  x_coords,
const GenericVector< GenericVector< int > > &  y_coords 
)

Definition at line 267 of file normalis.cpp.

                                                        {
  Clear();
  predecessor_ = predecessor;
  // x_map_ and y_map_ store a mapping from input x and y coordinate to output
  // x and y coordinate, based on scaling to the supplied target_width and
  // target_height.
  x_map_ = new GenericVector<float>;
  y_map_ = new GenericVector<float>;
  // Set a 2-d image array to the run lengths at each pixel.
  int width = box.width();
  int height = box.height();
  GENERIC_2D_ARRAY<int> minruns(width, height, 0);
  ComputeRunlengthImage(box, x_coords, y_coords, &minruns);
  // Edge density is the sum of the inverses of the run lengths. Compute
  // edge density projection profiles.
  ComputeEdgeDensityProfiles(box, minruns, x_map_, y_map_);
  // Convert the edge density profiles to the coordinates by multiplying by
  // the desired size and accumulating.
  (*x_map_)[width] = target_width;
  for (int x = width - 1; x >= 0; --x) {
    (*x_map_)[x] = (*x_map_)[x + 1] - (*x_map_)[x] * target_width;
  }
  (*y_map_)[height] = target_height;
  for (int y = height - 1; y >= 0; --y) {
    (*y_map_)[y] = (*y_map_)[y + 1] - (*y_map_)[y] * target_height;
  }
  x_origin_ = box.left();
  y_origin_ = box.bottom();
  final_xshift_ = final_xshift;
  final_yshift_ = final_yshift;
}
void DENORM::SetupNormalization ( const BLOCK block,
const FCOORD rotation,
const DENORM predecessor,
float  x_origin,
float  y_origin,
float  x_scale,
float  y_scale,
float  final_xshift,
float  final_yshift 
)

Definition at line 95 of file normalis.cpp.

                                                                        {
  Clear();
  block_ = block;
  if (rotation == NULL)
    rotation_ = NULL;
  else
    rotation_ = new FCOORD(*rotation);
  predecessor_ = predecessor;
  x_origin_ = x_origin;
  y_origin_ = y_origin;
  x_scale_ = x_scale;
  y_scale_ = y_scale;
  final_xshift_ = final_xshift;
  final_yshift_ = final_yshift;
}
float DENORM::x_scale ( ) const [inline]

Definition at line 269 of file normalis.h.

                        {
    return x_scale_;
  }
void DENORM::XHeightRange ( int  unichar_id,
const UNICHARSET unicharset,
const TBOX bbox,
float *  min_xht,
float *  max_xht,
float *  yshift 
) const

Definition at line 428 of file normalis.cpp.

                                                                               {
  // Default return -- accept anything.
  *yshift = 0.0f;
  *min_xht = 0.0f;
  *max_xht = MAX_FLOAT32;

  if (!unicharset.top_bottom_useful())
    return;

  // Clip the top and bottom to the limit of normalized feature space.
  int top = ClipToRange<int>(bbox.top(), 0, kBlnCellHeight - 1);
  int bottom = ClipToRange<int>(bbox.bottom(), 0, kBlnCellHeight - 1);
  // A tolerance of yscale corresponds to 1 pixel in the image.
  double tolerance = y_scale();
  // If the script doesn't have upper and lower-case characters, widen the
  // tolerance to allow sloppy baseline/x-height estimates.
  if (!unicharset.script_has_upper_lower())
    tolerance = y_scale() * kSloppyTolerance;

  int min_bottom, max_bottom, min_top, max_top;
  unicharset.get_top_bottom(unichar_id, &min_bottom, &max_bottom,
                            &min_top, &max_top);

  // Calculate the scale factor we'll use to get to image y-pixels
  double midx = (bbox.left() + bbox.right()) / 2;
  double ydiff = (bbox.top() - bbox.bottom()) + 2;
  FCOORD mid_bot(midx, bbox.bottom()), tmid_bot;
  FCOORD mid_high(midx, bbox.bottom() + ydiff), tmid_high;
  DenormTransform(NULL, mid_bot, &tmid_bot);
  DenormTransform(NULL, mid_high, &tmid_high);

  // bln_y_measure * yscale = image_y_measure
  double yscale = tmid_high.pt_to_pt_dist(tmid_bot) / ydiff;

  // Calculate y-shift
  int bln_yshift = 0, bottom_shift = 0, top_shift = 0;
  if (bottom < min_bottom - tolerance) {
    bottom_shift = bottom - min_bottom;
  } else if (bottom > max_bottom + tolerance) {
    bottom_shift = bottom - max_bottom;
  }
  if (top < min_top - tolerance) {
    top_shift = top - min_top;
  } else if (top > max_top + tolerance) {
    top_shift = top - max_top;
  }
  if ((top_shift >= 0 && bottom_shift > 0) ||
      (top_shift < 0 && bottom_shift < 0)) {
    bln_yshift = (top_shift + bottom_shift) / 2;
  }
  *yshift = bln_yshift * yscale;

  // To help very high cap/xheight ratio fonts accept the correct x-height,
  // and to allow the large caps in small caps to accept the xheight of the
  // small caps, add kBlnBaselineOffset to chars with a maximum max, and have
  // a top already at a significantly high position.
  if (max_top == kBlnCellHeight - 1 &&
      top > kBlnCellHeight - kBlnBaselineOffset / 2)
    max_top += kBlnBaselineOffset;
  top -= bln_yshift;
  int height = top - kBlnBaselineOffset - bottom_shift;
  double min_height = min_top - kBlnBaselineOffset - tolerance;
  double max_height = max_top - kBlnBaselineOffset + tolerance;

  // We shouldn't try calculations if the characters are very short (for example
  // for punctuation).
  if (min_height > kBlnXHeight / 8 && height > 0) {
    float result = height * kBlnXHeight * yscale / min_height;
    *max_xht = result + kFinalPixelTolerance;
    result = height * kBlnXHeight * yscale / max_height;
    *min_xht = result - kFinalPixelTolerance;
  }
}
float DENORM::y_scale ( ) const [inline]

Definition at line 272 of file normalis.h.

                        {
    return y_scale_;
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines