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) {
185 if (shift_stats.get_total() > top_stats.get_total()) {
188 tprintf(
"Applying bottom shift=%d\n", bottom_shift);
191 }
while (bottom_shift != 0 &&
192 top_stats.get_total() < shift_stats.get_total());
194 *baseline_shift = -bottom_shift / word_res->
denorm.
y_scale();
196 tprintf(
"baseline shift=%g\n", *baseline_shift);
198 if (top_stats.get_total() == 0)
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;