wordrec/gradechop.cpp File Reference

#include "gradechop.h"
#include "debug.h"
#include "olutil.h"
#include "chop.h"
#include <math.h>

Go to the source code of this file.

Defines

Functions


Define Documentation

#define CENTER_GRADE_CAP   25.0

Note:
File: gradechop.cpp (Formerly gradechop.c)
Chopping outlines: seams
Author:
Mark Seaman, OCR Technology
Date:
Fri Oct 16 14:37:00 1987 Tue Jul 30 16:06:27 1991 (Mark Seaman) marks
 * (c) Copyright 1987, Hewlett-Packard Company.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 32 of file gradechop.cpp.

Referenced by grade_center_of_blob().

#define find_bounds_loop ( point1,
point2,
x_min,
x_max   ) 

Value:

x_min = point2->pos.x;                               \
   x_max = point2->pos.x;                               \
                                          \
   this_point = point1;                                 \
   do {                                                 \
      x_min = min (this_point->pos.x, x_min);           \
      x_max = max (this_point->pos.x, x_max);           \
      this_point = this_point->next;                    \
   }                                                    \
   while (this_point != point2 && this_point != point1) \
Macro to be used by set_outline_bounds.

Definition at line 40 of file gradechop.cpp.

Referenced by set_outline_bounds().


Function Documentation

PRIORITY full_split_priority ( SPLIT split,
INT16  xmin,
INT16  xmax 
)

Assign a priority to this split based on the features that it has.

Part of the priority has already been calculated so just return the additional amount for the bounding box type information.

Definition at line 63 of file gradechop.cpp.

References grade_center_of_blob(), grade_overlap(), grade_width_change(), max, min, split_record::point1, split_record::point2, and set_outline_bounds().

Referenced by seam_priority().

00063                                                                    { 
00064   BOUNDS_RECT rect;
00065 
00066   set_outline_bounds (split->point1, split->point2, rect);
00067 
00068   if (xmin < min (rect[0], rect[2]) && xmax > max (rect[1], rect[3]))
00069     return (999.0);
00070 
00071   return (grade_overlap (rect) +
00072     grade_center_of_blob (rect) + grade_width_change (rect));
00073 }

PRIORITY grade_center_of_blob ( register BOUNDS_RECT  rect  ) 

Return a grade for the a split.

Rank it on closeness to the center of the original blob

Definition at line 84 of file gradechop.cpp.

References CENTER_GRADE_CAP, center_knob, max, and min.

Referenced by full_split_priority().

00084                                                          { 
00085   register PRIORITY grade;
00086 
00087   grade = (rect[1] - rect[0]) - (rect[3] - rect[2]);
00088   if (grade < 0)
00089     grade = -grade;
00090 
00091   grade *= center_knob;
00092   grade = min (CENTER_GRADE_CAP, grade);
00093   return (max (0.0, grade));
00094 }

PRIORITY grade_overlap ( register BOUNDS_RECT  rect  ) 

Return a grade for this split for the overlap of the resultant blobs.

Definition at line 104 of file gradechop.cpp.

References max, min, and overlap_knob.

Referenced by full_split_priority().

00104                                                   { 
00105   register PRIORITY grade;
00106   register INT16 width1;
00107   register INT16 width2;
00108   register INT16 overlap;
00109 
00110   width1 = rect[3] - rect[2];
00111   width2 = rect[1] - rect[0];
00112 
00113   overlap = min (rect[1], rect[3]) - max (rect[0], rect[2]);
00114   width1 = min (width1, width2);
00115   if (overlap == width1)
00116     return (100.0);              /* Total overlap */
00117 
00118   width1 = 2 * overlap - width1; /* Extra penalty for too */
00119   overlap += max (0, width1);    /* much overlap */
00120 
00121   grade = overlap * overlap_knob;
00122 
00123   return (max (0.0, grade));
00124 }

PRIORITY grade_sharpness ( register SPLIT split  ) 

Return a grade for the sharpness of this split.

Definition at line 157 of file gradechop.cpp.

References point_priority(), and sharpness_knob.

00157                                                 { 
00158   register PRIORITY grade;
00159 
00160   grade = point_priority (split->point1) + point_priority (split->point2);
00161 
00162   if (grade < -360.0)
00163     grade = 0;
00164   else
00165     grade += 360.0;
00166 
00167   grade *= sharpness_knob;       /* Values 0 to -360 */
00168 
00169   return (grade);
00170 }

PRIORITY grade_split_length ( register SPLIT split  ) 

Return a grade for the length of this split.

Definition at line 134 of file gradechop.cpp.

References max, split_dist_knob, split_length, weighted_edgept_dist, and x_y_weight.

00134                                                    { 
00135   register PRIORITY grade;
00136   register float split_length;
00137 
00138   split_length = weighted_edgept_dist (split->point1, split->point2,
00139     x_y_weight);
00140 
00141   if (split_length <= 0)
00142     grade = 0;
00143   else
00144     grade = sqrt (split_length) * split_dist_knob;
00145 
00146   return (max (0.0, grade));
00147 }

PRIORITY grade_width_change ( register BOUNDS_RECT  rect  ) 

Return a grade for the change in width of the resultant blobs.

Definition at line 180 of file gradechop.cpp.

References max, min, and width_change_knob.

Referenced by full_split_priority().

00180                                                        { 
00181   register PRIORITY grade;
00182   register INT32 width1;
00183   register INT32 width2;
00184 
00185   width1 = rect[3] - rect[2];
00186   width2 = rect[1] - rect[0];
00187 
00188   grade = 20 - (max (rect[1], rect[3])
00189     - min (rect[0], rect[2]) - max (width1, width2));
00190 
00191   grade *= width_change_knob;
00192 
00193   return (max (0.0, grade));
00194 }

void set_outline_bounds ( register EDGEPT point1,
register EDGEPT point2,
BOUNDS_RECT  rect 
)

Set up the limits for the x coordinate of the outline.

Definition at line 201 of file gradechop.cpp.

References find_bounds_loop.

Referenced by full_split_priority().

00203                                           {
00204   register EDGEPT *this_point;
00205   register INT16 x_min;
00206   register INT16 x_max;
00207 
00208   find_bounds_loop(point1, point2, x_min, x_max); 
00209 
00210   rect[0] = x_min;
00211   rect[1] = x_max;
00212 
00213   find_bounds_loop(point2, point1, x_min, x_max); 
00214 
00215   rect[2] = x_min;
00216   rect[3] = x_max;
00217 }


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