#include "mfcpch.h"
#include <stdio.h>
#include <stdlib.h>
#include "errcode.h"
Go to the source code of this file.
#define f | ( | xc, | |||
yc | ) | ((xc - factor*yc)*(xc - factor*yc)) |
* (C) Copyright 1992, Hewlett-Packard Ltd. ** 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 26 of file imgscale.cpp.
Referenced by AdaptiveClassifier(), assign_blobs_to_rows(), WERD::baseline_normalise_x(), block_occ(), ClassPruner(), compute_row_descdrop(), compute_row_xheight(), dyn_prog(), float_read(), float_write(), make_rows(), make_words(), mark_gap(), median_block_xheight(), old_first_xheight(), print_background(), ReadTrainingSamples(), recog_word(), resegment_box(), save_summary(), show_all_in(), show_all_tr_in(), WEIRD_BLOCK::show_attrs(), SCRIBBLE_BLOCK::show_attrs(), IMAGE_BLOCK::show_attrs(), GRAPHICS_BLOCK::show_attrs(), RULE_BLOCK::show_attrs(), TEXT_BLOCK::show_attrs(), Solve(), streamtofloat(), strtofloat(), vertical_outline_projection(), and word_bln_display().
#define g | ( | oldyc, | |||
yc, | |||||
oldxc, | |||||
xc | ) | (factor*factor*(oldyc - yc)*(oldyc - yc)/(abs(oldxc - xc) + 1)) |
void dyn_exit | ( | const char | s[] | ) |
Definition at line 31 of file imgscale.cpp.
References err_exit().
Referenced by dyn_prog().
00031 { 00032 fprintf (stderr, "%s", s); 00033 err_exit(); 00034 }
void dyn_prog | ( | int | n, | |
int * | x, | |||
int * | y, | |||
int | ymax, | |||
int * | oldx, | |||
int * | oldy, | |||
int | oldn, | |||
float | factor | |||
) |
The clever bit
Phil Cheatle: This is really Sheelagh's code that I've hacked into a more usable form. It is used by scaleimg.cpp
All I did to it was to change "factor" from int to float.
This version uses the result of the previous row to influence the current row's calculation.
Definition at line 48 of file imgscale.cpp.
References dyn_exit(), f, g, NULL, and ymin.
Referenced by scale_image().
00056 { 00057 int i, z, j, matchflag; 00058 int **ymin; 00059 float **F, fz; 00060 00061 /* F[i][z] gives minimum over y <= z */ 00062 00063 F = (float **) calloc (n, sizeof (float *)); 00064 ymin = (int **) calloc (n, sizeof (int *)); 00065 if ((F == NULL) || (ymin == NULL)) 00066 dyn_exit ("Error in calloc\n"); 00067 00068 for (i = 0; i < n; i++) { 00069 F[i] = (float *) calloc (ymax - n + i + 1, sizeof (float)); 00070 ymin[i] = (int *) calloc (ymax - n + i + 1, sizeof (int)); 00071 if ((F[i] == NULL) || (ymin[i] == NULL)) 00072 dyn_exit ("Error in calloc\n"); 00073 } 00074 00075 F[0][0] = f (x[0], 0); 00076 /* find nearest transition of same sign (white to black) */ 00077 j = 0; 00078 while ((j < oldn) && (oldx[j] < x[0])) 00079 j += 2; 00080 if (j >= oldn) 00081 j -= 2; 00082 else if ((j - 2 >= 0) && ((x[0] - oldx[j - 2]) < (oldx[j] - x[0]))) 00083 j -= 2; 00084 if (abs (oldx[j] - x[0]) < factor) { 00085 matchflag = 1; 00086 F[0][0] += g (oldy[j], 0, oldx[j], x[0]); 00087 } 00088 else 00089 matchflag = 0; 00090 ymin[0][0] = 0; 00091 00092 for (z = 1; z < ymax - n + 1; z++) { 00093 fz = f (x[0], z); 00094 /* add penalty for deviating from previous row if necessary */ 00095 if (matchflag) 00096 fz += g (oldy[j], z, oldx[j], x[0]); 00097 if (fz < F[0][z - 1]) { 00098 F[0][z] = fz; 00099 ymin[0][z] = z; 00100 } 00101 else { 00102 F[0][z] = F[0][z - 1]; 00103 ymin[0][z] = ymin[0][z - 1]; 00104 } 00105 } 00106 00107 for (i = 1; i < n; i++) { 00108 F[i][i] = f (x[i], i) + F[i - 1][i - 1]; 00109 /* add penalty for deviating from previous row if necessary */ 00110 if (j > 0) 00111 j--; 00112 else 00113 j++; 00114 while ((j < oldn) && (oldx[j] < x[i])) 00115 j += 2; 00116 if (j >= oldn) 00117 j -= 2; 00118 else if ((j - 2 >= 0) && ((x[i] - oldx[j - 2]) < (oldx[j] - x[i]))) 00119 j -= 2; 00120 if (abs (oldx[j] - x[i]) < factor) { 00121 matchflag = 1; 00122 F[i][i] += g (oldy[j], i, oldx[j], x[i]); 00123 } 00124 else 00125 matchflag = 0; 00126 ymin[i][i] = i; 00127 for (z = i + 1; z < ymax - n + i + 1; z++) { 00128 fz = f (x[i], z) + F[i - 1][z - 1]; 00129 /* add penalty for deviating from previous row if necessary */ 00130 if (matchflag) 00131 fz += g (oldy[j], z, oldx[j], x[i]); 00132 if (fz < F[i][z - 1]) { 00133 F[i][z] = fz; 00134 ymin[i][z] = z; 00135 } 00136 else { 00137 F[i][z] = F[i][z - 1]; 00138 ymin[i][z] = ymin[i][z - 1]; 00139 } 00140 } 00141 } 00142 00143 y[n - 1] = ymin[n - 1][ymax - 1]; 00144 for (i = n - 2; i >= 0; i--) 00145 y[i] = ymin[i][y[i + 1] - 1]; 00146 00147 for (i = 0; i < n; i++) { 00148 free (F[i]); 00149 free (ymin[i]); 00150 } 00151 free(F); 00152 free(ymin); 00153 00154 return; 00155 }