83 #include "allheaders.h" 86 l_float32 *pdel1, l_float32 *pdel2);
119 PROCNAME(
"boxaSelectRange");
122 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
124 return (
BOXA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
126 L_WARNING(
"boxas is empty\n", procName);
129 first = L_MAX(0, first);
130 if (last <= 0) last = n - 1;
132 return (
BOXA *)ERROR_PTR(
"invalid first", procName, NULL);
134 return (
BOXA *)ERROR_PTR(
"first > last", procName, NULL);
136 nbox = last - first + 1;
138 for (i = first; i <= last; i++) {
172 PROCNAME(
"boxaaSelectRange");
175 return (
BOXAA *)ERROR_PTR(
"baas not defined", procName, NULL);
177 return (
BOXAA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
179 return (
BOXAA *)ERROR_PTR(
"empty baas", procName, NULL);
180 first = L_MAX(0, first);
181 if (last <= 0) last = n - 1;
183 return (
BOXAA *)ERROR_PTR(
"invalid first", procName, NULL);
185 return (
BOXAA *)ERROR_PTR(
"first > last", procName, NULL);
187 nboxa = last - first + 1;
189 for (i = first; i <= last; i++) {
236 PROCNAME(
"boxaSelectBySize");
238 if (pchanged) *pchanged = FALSE;
240 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
242 L_WARNING(
"boxas is empty\n", procName);
247 return (
BOXA *)ERROR_PTR(
"invalid type", procName, NULL);
250 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
255 return (
BOXA *)ERROR_PTR(
"na not made", procName, NULL);
295 l_int32 i, n, w, h, ival;
298 PROCNAME(
"boxaMakeSizeIndicator");
301 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
303 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
306 return (
NUMA *)ERROR_PTR(
"invalid type", procName, NULL);
309 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
312 for (i = 0; i < n; i++) {
332 if (((relation ==
L_SELECT_IF_LT) && (w < width || h < height)) ||
339 if (((relation ==
L_SELECT_IF_LT) && (w < width && h < height)) ||
346 L_WARNING(
"can't get here!\n", procName);
384 PROCNAME(
"boxaSelectByArea");
386 if (pchanged) *pchanged = FALSE;
388 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
390 L_WARNING(
"boxas is empty\n", procName);
395 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
430 l_int32 i, n, w, h, ival;
433 PROCNAME(
"boxaMakeAreaIndicator");
436 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
438 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
441 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
444 for (i = 0; i < n; i++) {
488 PROCNAME(
"boxaSelectByWHRatio");
490 if (pchanged) *pchanged = FALSE;
492 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
494 L_WARNING(
"boxas is empty\n", procName);
499 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
534 l_int32 i, n, w, h, ival;
538 PROCNAME(
"boxaMakeWHRatioIndicator");
541 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
543 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
546 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
549 for (i = 0; i < n; i++) {
552 whratio = (l_float32)w / (l_float32)h;
586 l_int32 i, n, ival, nsave;
590 PROCNAME(
"boxaSelectWithIndicator");
592 if (pchanged) *pchanged = FALSE;
594 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
596 return (
BOXA *)ERROR_PTR(
"na not defined", procName, NULL);
600 for (i = 0; i < n; i++) {
602 if (ival == 1) nsave++;
606 if (pchanged) *pchanged = FALSE;
609 if (pchanged) *pchanged = TRUE;
611 for (i = 0; i < n; i++) {
613 if (ival == 0)
continue;
646 PROCNAME(
"boxaPermutePseudorandom");
649 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
686 PROCNAME(
"boxaPermuteRandom");
689 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
690 if (boxad && (boxad != boxas))
691 return (
BOXA *)ERROR_PTR(
"boxad defined but in-place", procName, NULL);
697 index = (l_uint32)rand() % n;
698 index = L_MAX(1, index);
700 for (i = 1; i < n; i++) {
701 index = (l_uint32)rand() % n;
702 if (index == i) index--;
725 PROCNAME(
"boxaSwapBoxes");
728 return ERROR_INT(
"boxa not defined", procName, 1);
731 return ERROR_INT(
"i invalid", procName, 1);
733 return ERROR_INT(
"j invalid", procName, 1);
735 return ERROR_INT(
"i == j", procName, 1);
738 boxa->
box[i] = boxa->
box[j];
769 PROCNAME(
"boxaConvertToPta");
772 return (
PTA *)ERROR_PTR(
"boxa not defined", procName, NULL);
773 if (ncorners != 2 && ncorners != 4)
774 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
778 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
779 for (i = 0; i < n; i++) {
810 l_int32 i, n, nbox, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
814 PROCNAME(
"ptaConvertToBoxa");
817 return (
BOXA *)ERROR_PTR(
"pta not defined", procName, NULL);
818 if (ncorners != 2 && ncorners != 4)
819 return (
BOXA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
821 if (n % ncorners != 0)
822 return (
BOXA *)ERROR_PTR(
"size % ncorners != 0", procName, NULL);
825 return (
BOXA *)ERROR_PTR(
"boxa not made", procName, NULL);
826 for (i = 0; i < n; i += ncorners) {
830 box =
boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
838 xmax = L_MAX(x2, x4);
839 ymax = L_MAX(y3, y4);
840 box =
boxCreate(x, y, xmax - x + 1, ymax - y + 1);
868 PROCNAME(
"boxConvertToPta");
871 return (
PTA *)ERROR_PTR(
"box not defined", procName, NULL);
872 if (ncorners != 2 && ncorners != 4)
873 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
876 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
880 ptaAddPt(pta, x + w - 1, y + h - 1);
884 ptaAddPt(pta, x + w - 1, y + h - 1);
906 l_int32 n, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
908 PROCNAME(
"ptaConvertToBox");
911 return (
BOX *)ERROR_PTR(
"pta not defined", procName, NULL);
916 return boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
923 xmax = L_MAX(x2, x4);
924 ymax = L_MAX(y3, y4);
925 return boxCreate(x, y, xmax - x + 1, ymax - y + 1);
974 BOXA *boxae, *boxao, *boxalfe, *boxalfo, *boxame, *boxamo, *boxad;
976 PROCNAME(
"boxaSmoothSequenceLS");
979 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
981 L_WARNING(
"factor must be > 0.0; returning copy\n", procName);
985 L_WARNING(
"maxdiff must be >= 0; returning copy\n", procName);
991 L_WARNING(
"invalid subflag; returning copy\n", procName);
995 L_WARNING(
"need at least 4 boxes; returning copy\n", procName);
1002 boxaWrite(
"/tmp/lept/smooth/boxae.ba", boxae);
1003 boxaWrite(
"/tmp/lept/smooth/boxao.ba", boxao);
1009 boxaWrite(
"/tmp/lept/smooth/boxalfe.ba", boxalfe);
1010 boxaWrite(
"/tmp/lept/smooth/boxalfo.ba", boxalfo);
1016 boxaWrite(
"/tmp/lept/smooth/boxame.ba", boxame);
1017 boxaWrite(
"/tmp/lept/smooth/boxamo.ba", boxamo);
1076 l_int32 extrapixels,
1080 BOXA *boxae, *boxao, *boxamede, *boxamedo, *boxame, *boxamo, *boxad;
1082 PROCNAME(
"boxaSmoothSequenceMedian");
1085 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1087 L_WARNING(
"halfwin must be > 0; returning copy\n", procName);
1091 L_WARNING(
"maxdiff must be >= 0; returning copy\n", procName);
1097 L_WARNING(
"invalid subflag; returning copy\n", procName);
1101 L_WARNING(
"need at least 6 boxes; returning copy\n", procName);
1108 boxaWrite(
"/tmp/lept/smooth/boxae.ba", boxae);
1109 boxaWrite(
"/tmp/lept/smooth/boxao.ba", boxao);
1115 boxaWrite(
"/tmp/lept/smooth/boxamede.ba", boxamede);
1116 boxaWrite(
"/tmp/lept/smooth/boxamedo.ba", boxamedo);
1122 boxaWrite(
"/tmp/lept/smooth/boxame.ba", boxame);
1123 boxaWrite(
"/tmp/lept/smooth/boxamo.ba", boxamo);
1182 l_int32 n, i, w, h, lval, tval, rval, bval, rejectlr, rejecttb;
1183 l_float32 al, bl, at, bt, ar, br, ab, bb;
1184 l_float32 medw, medh, medvarw, medvarh;
1185 BOX *box, *boxempty;
1186 BOXA *boxalr, *boxatb, *boxad;
1188 PTA *ptal, *ptat, *ptar, *ptab;
1190 PROCNAME(
"boxaLinearFit");
1193 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1195 return (
BOXA *)ERROR_PTR(
"need at least 2 boxes", procName, NULL);
1207 fprintf(stderr,
"medw = %7.3f, medvarw = %7.3f\n", medw, medvarw);
1208 fprintf(stderr,
"medh = %7.3f, medvarh = %7.3f\n", medh, medvarh);
1219 rejectlr = rejecttb = 0;
1220 for (i = 0; i < n; i++) {
1227 if (L_ABS(w - medw) <= factor * medvarw) {
1233 if (L_ABS(h - medh) <= factor * medvarh) {
1245 return (
BOXA *)ERROR_PTR(
"need at least 2 valid boxes", procName, NULL);
1249 L_INFO(
"# lr reject = %d, # tb reject = %d\n", procName,
1250 rejectlr, rejecttb);
1252 boxaWrite(
"/tmp/linfit/boxalr.ba", boxalr);
1253 boxaWrite(
"/tmp/linfit/boxatb.ba", boxatb);
1265 ptaWrite(
"/tmp/linfit/ptal.pta", ptal, 1);
1266 ptaWrite(
"/tmp/linfit/ptar.pta", ptar, 1);
1267 ptaWrite(
"/tmp/linfit/ptat.pta", ptat, 1);
1268 ptaWrite(
"/tmp/linfit/ptab.pta", ptab, 1);
1283 for (i = 0; i < n; i++) {
1284 lval = (l_int32)(al * i + bl + 0.5);
1285 tval = (l_int32)(at * i + bt + 0.5);
1286 rval = (l_int32)(ar * i + br + 0.5);
1287 bval = (l_int32)(ab * i + bb + 0.5);
1292 box =
boxCreate(lval, tval, rval - lval + 1, bval - tval + 1);
1334 l_int32 n, i, left, top, right, bot;
1336 BOXA *boxaf, *boxad;
1337 NUMA *nal, *nat, *nar, *nab, *naml, *namt, *namr, *namb;
1339 PROCNAME(
"boxaWindowedMedian");
1342 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1344 L_WARNING(
"less than 3 boxes; returning a copy\n", procName);
1348 L_WARNING(
"halfwin must be > 0; returning copy\n", procName);
1354 return (
BOXA *)ERROR_PTR(
"filled boxa not made", procName, NULL);
1365 for (i = 0; i < n; i++) {
1370 box =
boxCreate(left, top, right - left + 1, bot - top + 1);
1472 l_int32 extrapixels)
1474 l_int32 n, i, ls, ts, rs, bs, ws, hs, lm, tm, rm, bm, wm, hm, ld, td, rd, bd;
1475 BOX *boxs, *boxm, *boxd, *boxempty;
1478 PROCNAME(
"boxaModifyWithBoxa");
1481 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1483 L_WARNING(
"boxam not defined; returning copy", procName);
1489 L_WARNING(
"invalid subflag; returning copy", procName);
1494 L_WARNING(
"boxas and boxam sizes differ; returning copy", procName);
1500 for (i = 0; i < n; i++) {
1503 if (!boxs || !boxm) {
1523 ld = (L_ABS(lm - ls) <= maxdiff) ? ls : lm - extrapixels;
1524 td = (L_ABS(tm - ts) <= maxdiff) ? ts : tm - extrapixels;
1525 rd = (L_ABS(rm - rs) <= maxdiff) ? rs : rm + extrapixels;
1526 bd = (L_ABS(bm - bs) <= maxdiff) ? bs : bm + extrapixels;
1528 ld = (L_ABS(wm - ws) <= maxdiff) ? ls : lm - extrapixels;
1529 td = (L_ABS(hm - hs) <= maxdiff) ? ts : tm - extrapixels;
1530 rd = (L_ABS(wm - ws) <= maxdiff) ? rs : rm + extrapixels;
1531 bd = (L_ABS(hm - hs) <= maxdiff) ? bs : bm + extrapixels;
1533 ld = L_MAX(lm, L_MIN(ls, lm + maxdiff));
1534 td = L_MAX(tm, L_MIN(ts, tm + maxdiff));
1535 rd = L_MIN(rm, L_MAX(rs, rm - maxdiff));
1536 bd = L_MIN(bm, L_MAX(bs, bm - maxdiff));
1538 ld = L_MIN(lm, L_MAX(ls, lm - maxdiff));
1539 td = L_MIN(tm, L_MAX(ts, tm - maxdiff));
1540 rd = L_MAX(rm, L_MIN(rs, rm + maxdiff));
1541 bd = L_MAX(bm, L_MIN(bs, bm + maxdiff));
1543 boxd =
boxCreate(ld, td, rd - ld + 1, bd - td + 1);
1590 l_int32 n, i, x, y, w, h, invalid;
1591 l_int32 delw, delh, del_left, del_right, del_top, del_bot;
1592 BOX *medbox, *boxs, *boxd;
1595 PROCNAME(
"boxaConstrainSize");
1598 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1603 if (width == 0 || height == 0 || invalid > 0) {
1605 L_ERROR(
"median vals not returned", procName);
1609 if (width == 0) width = w;
1610 if (height == 0) height = h;
1615 for (i = 0; i < n; i++) {
1621 del_left = del_right = del_top = del_bot = 0;
1627 del_left = -delw / 2;
1628 del_right = delw / 2 + L_SIGN(delw) * (delw & 1);
1635 del_top = -delh / 2;
1636 del_bot = delh / 2 + L_SIGN(delh) * (delh & 1);
1700 l_int32 n, he, ho, hmed, doeven;
1701 l_float32 del1, del2;
1702 BOXA *boxae, *boxao, *boxa1e, *boxa1o, *boxad;
1704 PROCNAME(
"boxaReconcileEvenOddHeight");
1707 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1710 L_WARNING(
"no action requested; returning copy\n", procName);
1714 L_WARNING(
"need at least 6 valid boxes; returning copy\n", procName);
1717 if (factor <= 0.0) {
1718 L_WARNING(
"invalid factor; setting to 1.0\n", procName);
1733 L_INFO(
"median he = %d, median ho = %d\n", procName, he, ho);
1741 if (L_ABS(he - ho) > delh) {
1743 doeven = (ho < he) ? TRUE : FALSE;
1744 hmed = (l_int32)(factor * L_MIN(he, ho));
1745 hmed = L_MIN(hmed, L_MAX(he, ho));
1747 doeven = (ho > he) ? TRUE : FALSE;
1748 hmed = (l_int32)(factor * L_MAX(he, ho));
1749 hmed = L_MAX(hmed, L_MIN(he, ho));
1774 if (del2 < del1 + 10.)
1780 L_INFO(
"Got worse: del2 = %f > del1 = %f\n", procName, del2, del1);
1808 l_int32 i, n, npairs, y1a, y1b, y2a, y2b, h1a, h1b, h2a, h2b;
1809 l_float32 del1, del2;
1811 PROCNAME(
"boxaTestEvenOddHeight");
1813 if (pdel1) *pdel1 = 0.0;
1814 if (pdel2) *pdel2 = 0.0;
1815 if (!pdel1 || !pdel2)
1816 return ERROR_INT(
"&del1 and &del2 not both defined", procName, 1);
1817 if (!boxa1 || !boxa2)
1818 return ERROR_INT(
"boxa1 and boxa2 not both defined", procName, 1);
1826 npairs = (n - start) / 2;
1827 for (i = start; i < 2 * npairs; i += 2) {
1830 del1 += (l_float32)(y1a - y1b) * (y1a - y1b)
1831 + (h1a - h1b) * (h1a - h1b);
1834 del2 += (l_float32)(y2a - y2b) * (y2a - y2b)
1835 + (h2a - h2b) * (h2a - h2b);
1839 *pdel1 = (l_float32)sqrt((l_float64)del1 / (0.5 * n));
1840 *pdel2 = (l_float32)sqrt((l_float64)del2 / (0.5 * n));
1880 l_int32 i, ne, no, nmin, xe, we, xo, wo, inde, indo, x, w;
1882 BOXA *boxae, *boxao, *boxad;
1884 PROCNAME(
"boxaReconcilePairWidth");
1887 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
1888 if (factor <= 0.0) {
1889 L_WARNING(
"invalid factor; setting to 1.0\n", procName);
1899 nmin = L_MIN(ne, no);
1900 for (i = 0; i < nmin; i++) {
1908 if (inde == 0 && indo == 0)
continue;
1914 if (we == 0 || wo == 0) {
1918 }
else if (L_ABS(we - wo) > delw) {
1920 if (we > wo && inde == 1) {
1925 }
else if (we < wo && indo == 1) {
1931 if (we < wo && inde == 1) {
1934 x = L_MAX(0, xe + (we - w));
1937 }
else if (we > wo && indo == 1) {
1980 const char *plotname,
1987 char buf[128], titlebuf[128];
1988 static l_int32 plotid = 0;
1989 l_int32 n, i, w, h, left, top, right, bot;
1992 NUMA *nal, *nat, *nar, *nab;
1994 PROCNAME(
"boxaPlotSides");
1996 if (pnal) *pnal = NULL;
1997 if (pnat) *pnat = NULL;
1998 if (pnar) *pnar = NULL;
1999 if (pnab) *pnab = NULL;
2000 if (ppixd) *ppixd = NULL;
2002 return ERROR_INT(
"boxa not defined", procName, 1);
2004 return ERROR_INT(
"less than 2 boxes", procName, 1);
2014 for (i = 0; i < n; i++) {
2016 right = left + w - 1;
2027 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/sides.%s", plotname);
2028 snprintf(titlebuf,
sizeof(titlebuf),
"%s: Box sides vs. box index",
2031 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/sides.%d", plotid++);
2032 snprintf(titlebuf,
sizeof(titlebuf),
"Box sides vs. box index");
2035 "box index",
"side location");
2036 gplotAddPlot(gplot, NULL, nal, GPLOT_LINES,
"left side");
2037 gplotAddPlot(gplot, NULL, nat, GPLOT_LINES,
"top side");
2038 gplotAddPlot(gplot, NULL, nar, GPLOT_LINES,
"right side");
2039 gplotAddPlot(gplot, NULL, nab, GPLOT_LINES,
"bottom side");
2092 const char *plotname,
2097 char buf[128], titlebuf[128];
2098 static l_int32 plotid = 0;
2104 PROCNAME(
"boxaPlotSizes");
2106 if (pnaw) *pnaw = NULL;
2107 if (pnah) *pnah = NULL;
2108 if (ppixd) *ppixd = NULL;
2110 return ERROR_INT(
"boxa not defined", procName, 1);
2112 return ERROR_INT(
"less than 2 boxes", procName, 1);
2120 for (i = 0; i < n; i++) {
2129 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/size.%s", plotname);
2130 snprintf(titlebuf,
sizeof(titlebuf),
"%s: Box size vs. box index",
2133 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/size.%d", plotid++);
2134 snprintf(titlebuf,
sizeof(titlebuf),
"Box size vs. box index");
2137 "box index",
"box dimension");
2184 BOXA *boxae, *boxao, *boxad;
2186 PROCNAME(
"boxaFillSequence");
2189 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
2191 return (
BOXA *)ERROR_PTR(
"invalid useflag", procName, NULL);
2198 L_INFO(
"%d valid boxes, %d invalid boxes\n", procName, nv, n - nv);
2200 L_WARNING(
"n < 3; some invalid\n", procName);
2218 L_WARNING(
"there are still %d invalid boxes\n", procName, n - nv);
2240 l_int32 n, nv, i, j, spandown, spanup;
2244 PROCNAME(
"boxaFillAll");
2247 return ERROR_INT(
"boxa not defined", procName, 1);
2250 if (n == nv)
return 0;
2252 L_WARNING(
"no valid boxes out of %d boxes\n", procName, n);
2257 if ((indic = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32))) == NULL)
2258 return ERROR_INT(
"indic not made", procName, 1);
2259 for (i = 0; i < n; i++) {
2267 for (i = 0; i < n; i++) {
2270 spandown = spanup = 10000000;
2271 for (j = i - 1; j >= 0; j--) {
2272 if (indic[j] == 1) {
2277 for (j = i + 1; j < n; j++) {
2278 if (indic[j] == 1) {
2283 if (spandown < spanup)
2326 l_int32 i, n, x, y, w, h, xmax, ymax, xmin, ymin, found;
2328 PROCNAME(
"boxaGetExtent");
2330 if (!pw && !ph && !pbox)
2331 return ERROR_INT(
"no ptrs defined", procName, 1);
2334 if (pbox) *pbox = NULL;
2336 return ERROR_INT(
"boxa not defined", procName, 1);
2340 xmin = ymin = 100000000;
2342 for (i = 0; i < n; i++) {
2344 if (w <= 0 || h <= 0)
2347 xmin = L_MIN(xmin, x);
2348 ymin = L_MIN(ymin, y);
2349 xmax = L_MAX(xmax, x + w);
2350 ymax = L_MAX(ymax, y + h);
2357 *pbox =
boxCreate(xmin, ymin, xmax - xmin, ymax - ymin);
2393 l_int32 i, n, x, y, w, h, sum;
2397 PROCNAME(
"boxaGetCoverage");
2400 return ERROR_INT(
"&fract not defined", procName, 1);
2403 return ERROR_INT(
"boxa not defined", procName, 1);
2407 return ERROR_INT(
"no boxes in boxa", procName, 1);
2409 if (exactflag == 0) {
2411 for (i = 0; i < n; i++) {
2422 for (i = 0; i < n; i++) {
2432 *pfract = (l_float32)sum / (l_float32)(wc * hc);
2452 l_int32 minw, minh, maxw, maxh, minbw, minbh, maxbw, maxbh, i, n;
2455 PROCNAME(
"boxaaSizeRange");
2457 if (!pminw && !pmaxw && !pminh && !pmaxh)
2458 return ERROR_INT(
"no data can be returned", procName, 1);
2459 if (pminw) *pminw = 0;
2460 if (pminh) *pminh = 0;
2461 if (pmaxw) *pmaxw = 0;
2462 if (pmaxh) *pmaxh = 0;
2464 return ERROR_INT(
"baa not defined", procName, 1);
2466 minw = minh = 100000000;
2469 for (i = 0; i < n; i++) {
2483 if (pminw) *pminw = minw;
2484 if (pminh) *pminh = minh;
2485 if (pmaxw) *pmaxw = maxw;
2486 if (pmaxh) *pmaxh = maxh;
2506 l_int32 minw, minh, maxw, maxh, i, n, w, h;
2508 PROCNAME(
"boxaSizeRange");
2510 if (!pminw && !pmaxw && !pminh && !pmaxh)
2511 return ERROR_INT(
"no data can be returned", procName, 1);
2512 if (pminw) *pminw = 0;
2513 if (pminh) *pminh = 0;
2514 if (pmaxw) *pmaxw = 0;
2515 if (pmaxh) *pmaxh = 0;
2517 return ERROR_INT(
"boxa not defined", procName, 1);
2519 minw = minh = 100000000;
2522 for (i = 0; i < n; i++) {
2534 if (pminw) *pminw = minw;
2535 if (pminh) *pminh = minh;
2536 if (pmaxw) *pmaxw = maxw;
2537 if (pmaxh) *pmaxh = maxh;
2557 l_int32 minx, miny, maxx, maxy, i, n, x, y;
2559 PROCNAME(
"boxaLocationRange");
2561 if (!pminx && !pminy && !pmaxx && !pmaxy)
2562 return ERROR_INT(
"no data can be returned", procName, 1);
2563 if (pminx) *pminx = 0;
2564 if (pminy) *pminy = 0;
2565 if (pmaxx) *pmaxx = 0;
2566 if (pmaxy) *pmaxy = 0;
2568 return ERROR_INT(
"boxa not defined", procName, 1);
2570 minx = miny = 100000000;
2573 for (i = 0; i < n; i++) {
2585 if (pminx) *pminx = minx;
2586 if (pminy) *pminy = miny;
2587 if (pmaxx) *pmaxx = maxx;
2588 if (pmaxy) *pmaxy = maxy;
2609 PROCNAME(
"boxaGetSizes");
2611 if (pnaw) *pnaw = NULL;
2612 if (pnah) *pnah = NULL;
2614 return ERROR_INT(
"no output requested", procName, 1);
2616 return ERROR_INT(
"boxa not defined", procName, 1);
2621 for (i = 0; i < n; i++) {
2653 PROCNAME(
"boxaGetArea");
2656 return ERROR_INT(
"&area not defined", procName, 1);
2659 return ERROR_INT(
"boxa not defined", procName, 1);
2662 for (i = 0; i < n; i++) {
2700 l_float32 scalefactor,
2706 l_int32 i, n, npix, w, h, fontsize;
2710 PIX *pix1, *pix2, *pixd;
2713 PROCNAME(
"boxaDisplayTiled");
2716 return (
PIX *)ERROR_PTR(
"boxas not defined", procName, NULL);
2724 return (
PIX *)ERROR_PTR(
"boxa and pixa counts differ",
2731 if (scalefactor > 0.8)
2733 else if (scalefactor > 0.6)
2735 else if (scalefactor > 0.4)
2737 else if (scalefactor > 0.3)
2744 for (i = 0; i < n; i++) {
2753 snprintf(buf,
sizeof(buf),
"%d", i);
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
l_int32 gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle)
gplotAddPlot()
l_int32 boxaExtractAsPta(BOXA *boxa, PTA **pptal, PTA **pptat, PTA **pptar, PTA **pptab, PTA **pptaw, PTA **pptah, l_int32 keepinvalid)
boxaExtractAsPta()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
BOX * boxaGetValidBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetValidBox()
BOXA * boxaConstrainSize(BOXA *boxas, l_int32 width, l_int32 widthflag, l_int32 height, l_int32 heightflag)
boxaConstrainSize()
PIX * boxaDisplayTiled(BOXA *boxas, PIXA *pixa, l_int32 maxwidth, l_int32 linewidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
boxaDisplayTiled()
l_int32 numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
l_int32 boxaExtractAsNuma(BOXA *boxa, NUMA **pnal, NUMA **pnat, NUMA **pnar, NUMA **pnab, NUMA **pnaw, NUMA **pnah, l_int32 keepinvalid)
boxaExtractAsNuma()
PTA * boxaConvertToPta(BOXA *boxa, l_int32 ncorners)
boxaConvertToPta()
l_int32 boxaPlotSides(BOXA *boxa, const char *plotname, NUMA **pnal, NUMA **pnat, NUMA **pnar, NUMA **pnab, PIX **ppixd)
boxaPlotSides()
BOXA * boxaSelectRange(BOXA *boxas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaSelectRange()
BOXA * boxaMergeEvenOdd(BOXA *boxae, BOXA *boxao, l_int32 fillflag)
boxaMergeEvenOdd()
l_int32 boxaWrite(const char *filename, BOXA *boxa)
boxaWrite()
l_int32 ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 boxaaGetCount(BOXAA *baa)
boxaaGetCount()
l_int32 boxaGetSizes(BOXA *boxa, NUMA **pnaw, NUMA **pnah)
boxaGetSizes()
GPLOT * gplotCreate(const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel)
gplotCreate()
l_int32 boxaLocationRange(BOXA *boxa, l_int32 *pminx, l_int32 *pminy, l_int32 *pmaxx, l_int32 *pmaxy)
boxaLocationRange()
l_int32 ptaGetLinearLSF(PTA *pta, l_float32 *pa, l_float32 *pb, NUMA **pnafit)
ptaGetLinearLSF()
BOXA * boxaSelectBySize(BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
boxaSelectBySize()
PTA * ptaCreate(l_int32 n)
ptaCreate()
l_int32 boxSetGeometry(BOX *box, l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxSetGeometry()
l_int32 boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
NUMA * boxaMakeSizeIndicator(BOXA *boxa, l_int32 width, l_int32 height, l_int32 type, l_int32 relation)
boxaMakeSizeIndicator()
l_int32 boxaaSizeRange(BOXAA *baa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaaSizeRange()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
static l_int32 boxaFillAll(BOXA *boxa)
boxaFillAll()
BOXA * ptaConvertToBoxa(PTA *pta, l_int32 ncorners)
ptaConvertToBoxa()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
BOXA * boxaAdjustHeightToTarget(BOXA *boxad, BOXA *boxas, l_int32 sides, l_int32 target, l_int32 thresh)
boxaAdjustHeightToTarget()
NUMA * numaWindowedMedian(NUMA *nas, l_int32 halfwin)
numaWindowedMedian()
static l_int32 boxaTestEvenOddHeight(BOXA *boxa1, BOXA *boxa2, l_int32 start, l_float32 *pdel1, l_float32 *pdel2)
boxaTestEvenOddHeight()
l_int32 boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
l_int32 gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
l_int32 pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
l_int32 pixSetBorderVal(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixSetBorderVal()
l_int32 boxaSizeRange(BOXA *boxa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaSizeRange()
BOXAA * boxaaSelectRange(BOXAA *baas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaaSelectRange()
l_int32 stringCat(char *dest, size_t size, const char *src)
stringCat()
l_int32 pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
NUMA * numaPseudorandomSequence(l_int32 size, l_int32 seed)
numaPseudorandomSequence()
static const l_int32 L_INSERT
l_int32 ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_int32 boxaGetArea(BOXA *boxa, l_int32 *parea)
boxaGetArea()
l_int32 pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
BOXA * boxaReconcilePairWidth(BOXA *boxas, l_int32 delw, l_int32 op, l_float32 factor, NUMA *na)
boxaReconcilePairWidth()
BOXA * boxaSaveValid(BOXA *boxas, l_int32 copyflag)
boxaSaveValid()
PIX * pixaDisplayTiledInRows(PIXA *pixa, l_int32 outdepth, l_int32 maxwidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledInRows()
BOXA * boxaPermuteRandom(BOXA *boxad, BOXA *boxas)
boxaPermuteRandom()
BOXA * boxaSelectByWHRatio(BOXA *boxas, l_float32 ratio, l_int32 relation, l_int32 *pchanged)
boxaSelectByWHRatio()
l_int32 boxaGetCoverage(BOXA *boxa, l_int32 wc, l_int32 hc, l_int32 exactflag, l_float32 *pfract)
boxaGetCoverage()
l_int32 boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
BOX * boxAdjustSides(BOX *boxd, BOX *boxs, l_int32 delleft, l_int32 delright, l_int32 deltop, l_int32 delbot)
boxAdjustSides()
l_int32 numaGetMedianVariation(NUMA *na, l_float32 *pmedval, l_float32 *pmedvar)
numaGetMedianVariation()
BOXA * boxaWindowedMedian(BOXA *boxas, l_int32 halfwin, l_int32 debug)
boxaWindowedMedian()
l_int32 boxaSwapBoxes(BOXA *boxa, l_int32 i, l_int32 j)
boxaSwapBoxes()
BOXA * boxaSelectByArea(BOXA *boxas, l_int32 area, l_int32 relation, l_int32 *pchanged)
boxaSelectByArea()
void pixDestroy(PIX **ppix)
pixDestroy()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOXA * boxaModifyWithBoxa(BOXA *boxas, BOXA *boxam, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels)
boxaModifyWithBoxa()
void numaDestroy(NUMA **pna)
numaDestroy()
BOXA * boxaReconcileEvenOddHeight(BOXA *boxas, l_int32 sides, l_int32 delh, l_int32 op, l_float32 factor, l_int32 start)
boxaReconcileEvenOddHeight()
NUMA * boxaMakeAreaIndicator(BOXA *boxa, l_int32 area, l_int32 relation)
boxaMakeAreaIndicator()
BOXAA * boxaaCreate(l_int32 n)
boxaaCreate()
l_int32 ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_int32 boxaPlotSizes(BOXA *boxa, const char *plotname, NUMA **pnaw, NUMA **pnah, PIX **ppixd)
boxaPlotSizes()
BOXA * boxaSelectWithIndicator(BOXA *boxas, NUMA *na, l_int32 *pchanged)
boxaSelectWithIndicator()
PIX * pixRead(const char *filename)
pixRead()
l_int32 boxaGetValidCount(BOXA *boxa)
boxaGetValidCount()
PTA * boxConvertToPta(BOX *box, l_int32 ncorners)
boxConvertToPta()
l_int32 boxaGetMedianVals(BOXA *boxa, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetMedianVals()
l_int32 boxaaAddBoxa(BOXAA *baa, BOXA *ba, l_int32 copyflag)
boxaaAddBoxa()
BOXA * boxaPermutePseudorandom(BOXA *boxas)
boxaPermutePseudorandom()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
BOX * boxCopy(BOX *box)
boxCopy()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_int32 ptaWrite(const char *filename, PTA *pta, l_int32 type)
ptaWrite()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
void boxDestroy(BOX **pbox)
boxDestroy()
l_int32 boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
BOXA * boxaLinearFit(BOXA *boxas, l_float32 factor, l_int32 debug)
boxaLinearFit()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_int32 numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_int32 pixSetAll(PIX *pix)
pixSetAll()
l_int32 pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
BOXA * boxaSmoothSequenceLS(BOXA *boxas, l_float32 factor, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels, l_int32 debug)
boxaSmoothSequenceLS()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
NUMA * boxaMakeWHRatioIndicator(BOXA *boxa, l_float32 ratio, l_int32 relation)
boxaMakeWHRatioIndicator()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
BOXA * boxaFillSequence(BOXA *boxas, l_int32 useflag, l_int32 debug)
boxaFillSequence()
BOXA * boxaSmoothSequenceMedian(BOXA *boxas, l_int32 halfwin, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels, l_int32 debug)
boxaSmoothSequenceMedian()
BOX * ptaConvertToBox(PTA *pta)
ptaConvertToBox()
l_int32 boxaReplaceBox(BOXA *boxa, l_int32 index, BOX *box)
boxaReplaceBox()
BOXA * boxaaGetBoxa(BOXAA *baa, l_int32 index, l_int32 accessflag)
boxaaGetBoxa()
l_int32 boxaSplitEvenOdd(BOXA *boxa, l_int32 fillflag, BOXA **pboxae, BOXA **pboxao)
boxaSplitEvenOdd()
BOXA * boxaSortByIndex(BOXA *boxas, NUMA *naindex)
boxaSortByIndex()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()