73 for (
int blob_id = 0; blob_id < num_blobs; ++blob_id) {
80 int min_bottom, max_bottom, min_top, max_top;
90 tprintf(
"Class %s is %s with top %d vs limits of %d->%d, +/-%d\n",
92 bad ?
"Misfit" :
"OK", top, min_top, max_top,
103 float* baseline_shift) {
104 STATS top_stats(0, UINT8_MAX);
105 STATS shift_stats(-UINT8_MAX, UINT8_MAX);
106 int bottom_shift = 0;
111 for (
int blob_id = 0; blob_id < num_blobs; ++blob_id) {
121 int min_bottom, max_bottom, min_top, max_top;
131 tprintf(
"Class %s: height=%d, bottom=%d,%d top=%d,%d, actual=%d,%d: ",
133 height, min_bottom, max_bottom, min_top, max_top,
150 tprintf(
" xht range min=%d, max=%d\n", min_xht, max_xht);
154 for (
int y = min_xht; y <= max_xht; ++y)
155 top_stats.
add(y, misfit_dist);
160 int min_shift = min_bottom - bottom;
161 int max_shift = max_bottom - bottom;
163 tprintf(
" bottom shift min=%d, max=%d\n", min_shift, max_shift);
168 int misfit_weight = abs(min_shift);
169 if (max_shift > min_shift)
170 misfit_weight /= max_shift - min_shift;
171 for (
int y = min_shift; y <= max_shift; ++y)
172 shift_stats.
add(y, misfit_weight);
174 if (bottom_shift == 0) {
188 tprintf(
"Applying bottom shift=%d\n", bottom_shift);
191 }
while (bottom_shift != 0 &&
194 *baseline_shift = -bottom_shift / word_res->
denorm.
y_scale();
196 tprintf(
"baseline shift=%g\n", *baseline_shift);
199 return bottom_shift != 0 ? word_res->
x_height : 0.0f;
202 float new_xht = top_stats.
median();
204 tprintf(
"Median xht=%f\n", new_xht);
205 tprintf(
"Mode20:A: New x-height = %f (norm), %f (orig)\n",
212 return bottom_shift != 0 ? word_res->
x_height : 0.0f;
float ComputeCompatibleXheight(WERD_RES *word_res, float *baseline_shift)
const int kBlnBaselineOffset
bool get_isalpha(UNICHAR_ID unichar_id) const
bool get_isdigit(UNICHAR_ID unichar_id) const
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
int IntCastRounded(double x)
UNICHAR_ID unichar_id(int index) const
DLLSYM void tprintf(const char *format,...)
TBOX bounding_box() const
void add(int32_t value, int32_t count)
GenericVector< TBLOB * > blobs
int CountMisfitTops(WERD_RES *word_res)
const char * id_to_unichar(UNICHAR_ID id) const
int DivRounded(int a, int b)
const int kMaxCharTopRange
WERD_CHOICE * best_choice
int32_t get_total() const
int x_ht_acceptance_tolerance