114BOXA *boxae, *boxao, *boxamede, *boxamedo, *boxame, *boxamo, *boxad;
118 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
120 L_WARNING(
"halfwin must be > 0; returning copy\n", __func__);
121 return boxaCopy(boxas,
L_COPY);
124 L_WARNING(
"maxdiff must be >= 0; returning copy\n", __func__);
125 return boxaCopy(boxas,
L_COPY);
130 L_WARNING(
"invalid subflag; returning copy\n", __func__);
131 return boxaCopy(boxas,
L_COPY);
133 if ((n = boxaGetCount(boxas)) < 6) {
134 L_WARNING(
"need at least 6 boxes; returning copy\n", __func__);
135 return boxaCopy(boxas,
L_COPY);
138 boxaSplitEvenOdd(boxas, 0, &boxae, &boxao);
140 lept_mkdir(
"lept/smooth");
141 boxaWriteDebug(
"/tmp/lept/smooth/boxae.ba", boxae);
142 boxaWriteDebug(
"/tmp/lept/smooth/boxao.ba", boxao);
148 boxaWriteDebug(
"/tmp/lept/smooth/boxamede.ba", boxamede);
149 boxaWriteDebug(
"/tmp/lept/smooth/boxamedo.ba", boxamedo);
155 boxaWriteDebug(
"/tmp/lept/smooth/boxame.ba", boxame);
156 boxaWriteDebug(
"/tmp/lept/smooth/boxamo.ba", boxamo);
159 boxad = boxaMergeEvenOdd(boxame, boxamo, 0);
162 pixWrite(
"/tmp/lept/smooth/plotsides1.png", pix1, IFF_PNG);
165 pixWrite(
"/tmp/lept/smooth/plotsides2.png", pix1, IFF_PNG);
168 pixWrite(
"/tmp/lept/smooth/plotsizes1.png", pix1, IFF_PNG);
171 pixWrite(
"/tmp/lept/smooth/plotsizes2.png", pix1, IFF_PNG);
177 boxaDestroy(&boxamede);
178 boxaDestroy(&boxamedo);
179 boxaDestroy(&boxame);
180 boxaDestroy(&boxamo);
208l_int32 n, i, left, top, right, bot;
211NUMA *nal, *nat, *nar, *nab, *naml, *namt, *namr, *namb;
215 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
216 if ((n = boxaGetCount(boxas)) < 3) {
217 L_WARNING(
"less than 3 boxes; returning a copy\n", __func__);
218 return boxaCopy(boxas,
L_COPY);
221 L_WARNING(
"halfwin must be > 0; returning copy\n", __func__);
222 return boxaCopy(boxas,
L_COPY);
227 return (
BOXA *)ERROR_PTR(
"filled boxa not made", __func__, NULL);
230 boxaExtractAsNuma(boxaf, &nal, &nat, &nar, &nab, NULL, NULL, 0);
231 naml = numaWindowedMedian(nal, halfwin);
232 namt = numaWindowedMedian(nat, halfwin);
233 namr = numaWindowedMedian(nar, halfwin);
234 namb = numaWindowedMedian(nab, halfwin);
236 n = boxaGetCount(boxaf);
237 boxad = boxaCreate(n);
238 for (i = 0; i < n; i++) {
239 numaGetIValue(naml, i, &left);
240 numaGetIValue(namt, i, &top);
241 numaGetIValue(namr, i, &right);
242 numaGetIValue(namb, i, &bot);
243 box = boxCreate(left, top, right - left + 1, bot - top + 1);
248 lept_mkdir(
"lept/windowed");
250 pixWrite(
"/tmp/lept/windowed/plotsides1.png", pix1, IFF_PNG);
253 pixWrite(
"/tmp/lept/windowed/plotsides2.png", pix1, IFF_PNG);
256 pixWrite(
"/tmp/lept/windowed/plotsizes1.png", pix1, IFF_PNG);
259 pixWrite(
"/tmp/lept/windowed/plotsizes2.png", pix1, IFF_PNG);
353l_int32 n, i, ls, ts, rs, bs, ws, hs, lm, tm, rm, bm, wm, hm, ld, td, rd, bd;
354BOX *boxs, *boxm, *boxd, *boxempty;
358 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
360 L_WARNING(
"boxam not defined; returning copy", __func__);
361 return boxaCopy(boxas,
L_COPY);
366 L_WARNING(
"invalid subflag; returning copy", __func__);
367 return boxaCopy(boxas,
L_COPY);
369 n = boxaGetCount(boxas);
370 if (n != boxaGetCount(boxam)) {
371 L_WARNING(
"boxas and boxam sizes differ; returning copy", __func__);
372 return boxaCopy(boxas,
L_COPY);
375 boxad = boxaCreate(n);
376 boxempty = boxCreate(0, 0, 0, 0);
377 for (i = 0; i < n; i++) {
378 boxs = boxaGetValidBox(boxas, i,
L_CLONE);
379 boxm = boxaGetValidBox(boxam, i,
L_CLONE);
380 if (!boxs || !boxm) {
381 boxaAddBox(boxad, boxempty,
L_COPY);
383 boxGetGeometry(boxs, &ls, &ts, &ws, &hs);
384 boxGetGeometry(boxm, &lm, &tm, &wm, &hm);
400 ld = (L_ABS(lm - ls) <= maxdiff) ? ls : lm - extrapixels;
401 td = (L_ABS(tm - ts) <= maxdiff) ? ts : tm - extrapixels;
402 rd = (L_ABS(rm - rs) <= maxdiff) ? rs : rm + extrapixels;
403 bd = (L_ABS(bm - bs) <= maxdiff) ? bs : bm + extrapixels;
405 ld = (L_ABS(wm - ws) <= maxdiff) ? ls : lm - extrapixels;
406 td = (L_ABS(hm - hs) <= maxdiff) ? ts : tm - extrapixels;
407 rd = (L_ABS(wm - ws) <= maxdiff) ? rs : rm + extrapixels;
408 bd = (L_ABS(hm - hs) <= maxdiff) ? bs : bm + extrapixels;
410 ld = L_MAX(lm, L_MIN(ls, lm + maxdiff));
411 td = L_MAX(tm, L_MIN(ts, tm + maxdiff));
412 rd = L_MIN(rm, L_MAX(rs, rm - maxdiff));
413 bd = L_MIN(bm, L_MAX(bs, bm - maxdiff));
415 ld = L_MIN(lm, L_MAX(ls, lm - maxdiff));
416 td = L_MIN(tm, L_MAX(ts, tm - maxdiff));
417 rd = L_MAX(rm, L_MIN(rs, rm + maxdiff));
418 bd = L_MAX(bm, L_MIN(bs, bm + maxdiff));
420 boxd = boxCreate(ld, td, rd - ld + 1, bd - td + 1);
426 boxDestroy(&boxempty);
467l_int32 i, ne, no, nmin, xe, we, xo, wo, inde, indo, x, w;
469BOXA *boxae, *boxao, *boxad;
472 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
474 L_WARNING(
"invalid factor; setting to 1.0\n", __func__);
481 boxaSplitEvenOdd(boxas, 0, &boxae, &boxao);
482 ne = boxaGetCount(boxae);
483 no = boxaGetCount(boxao);
484 nmin = L_MIN(ne, no);
485 for (i = 0; i < nmin; i++) {
488 numaGetIValue(na, 2 * i, &inde);
489 numaGetIValue(na, 2 * i + 1, &indo);
493 if (inde == 0 && indo == 0)
continue;
495 boxe = boxaGetBox(boxae, i,
L_CLONE);
496 boxo = boxaGetBox(boxao, i,
L_CLONE);
497 boxGetGeometry(boxe, &xe, NULL, &we, NULL);
498 boxGetGeometry(boxo, &xo, NULL, &wo, NULL);
499 if (we == 0 || wo == 0) {
503 }
else if (L_ABS(we - wo) > delw) {
505 if (we > wo && inde == 1) {
509 boxSetGeometry(boxe, x, -1, w, -1);
510 }
else if (we < wo && indo == 1) {
513 boxSetGeometry(boxo, -1, -1, w, -1);
516 if (we < wo && inde == 1) {
519 x = L_MAX(0, xe + (we - w));
521 boxSetGeometry(boxe, x, -1, w, -1);
522 }
else if (we > wo && indo == 1) {
525 boxSetGeometry(boxo, -1, -1, w, -1);
533 boxad = boxaMergeEvenOdd(boxae, boxao, 0);
590l_int32 i, n, bw1, bh1, bw2, bh2, npairs;
591l_float32 ave, fdiff, sumdiff, med, fvarp, fvarm;
594 if (pfvarp) *pfvarp = 0.0;
595 if (pfvarm) *pfvarm = 0.0;
597 return ERROR_INT(
"&same not defined", __func__, 1);
600 return ERROR_INT(
"boxas not defined", __func__, 1);
601 if (boxaGetValidCount(boxas) < 6)
602 return ERROR_INT(
"need a least 6 valid boxes", __func__, 1);
604 return ERROR_INT(
"invalid type", __func__, 1);
605 if (threshp < 0.0 || threshp >= 0.5)
606 return ERROR_INT(
"invalid threshp", __func__, 1);
607 if (threshm < 0.0 || threshm >= 0.5)
608 return ERROR_INT(
"invalid threshm", __func__, 1);
609 if (threshp == 0.0) threshp = 0.02f;
610 if (threshm == 0.0) threshm = 0.015f;
613 n = boxaGetCount(boxas);
615 for (i = 0, npairs = 0, sumdiff = 0; i < n - 1; i += 2) {
616 boxaGetBoxGeometry(boxas, i, NULL, NULL, &bw1, &bh1);
617 boxaGetBoxGeometry(boxas, i + 1, NULL, NULL, &bw2, &bh2);
618 if (bw1 == 0 || bh1 == 0 || bw2 == 0 || bh2 == 0)
622 ave = (bw1 + bw2) / 2.0;
623 fdiff = L_ABS(bw1 - bw2) / ave;
624 numaAddNumber(na1, bw1);
625 numaAddNumber(na1, bw2);
627 ave = (bh1 + bh2) / 2.0;
628 fdiff = L_ABS(bh1 - bh2) / ave;
629 numaAddNumber(na1, bh1);
630 numaAddNumber(na1, bh2);
634 fvarp = sumdiff / npairs;
635 if (pfvarp) *pfvarp = fvarp;
638 numaGetMedian(na1, &med);
640 L_WARNING(
"median value is 0\n", __func__);
642 numaGetMeanDevFromMedian(na1, med, &fvarm);
644 if (pfvarm) *pfvarm = fvarm;
649 if (fvarp < threshp && fvarm < threshm)
651 else if (fvarp < threshp && fvarm > threshm)
689BOXA *boxa1e, *boxa1o, *boxa2e, *boxa2o, *boxa3e, *boxa3o, *boxad;
693 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
695 L_WARNING(
"invalid select1; returning copy\n", __func__);
696 return boxaCopy(boxas,
L_COPY);
699 L_WARNING(
"invalid select2; returning copy\n", __func__);
700 return boxaCopy(boxas,
L_COPY);
703 L_WARNING(
"thresh must be >= 0; returning copy\n", __func__);
704 return boxaCopy(boxas,
L_COPY);
706 if (boxaGetValidCount(boxas) < 3) {
707 L_WARNING(
"need at least 3 valid boxes; returning copy\n", __func__);
708 return boxaCopy(boxas,
L_COPY);
712 boxaSplitEvenOdd(boxas, 0, &boxa1e, &boxa1o);
719 boxa2e = boxaCopy(boxa1e,
L_COPY);
726 boxa3e = boxaCopy(boxa2e,
L_COPY);
732 boxa2o = boxaCopy(boxa1o,
L_COPY);
737 boxa3o = boxaCopy(boxa2o,
L_COPY);
738 boxad = boxaMergeEvenOdd(boxa3e, boxa3o, 0);
744 lept_mkdir(
"lept/boxa");
745 pix1 = pixaDisplayTiledInColumns(pixadb, ncols, 1.0, 30, 2);
746 pixWrite(
"/tmp/lept/boxa/recon_sides.png", pix1, IFF_PNG);
750 boxaDestroy(&boxa1e);
751 boxaDestroy(&boxa1o);
752 boxaDestroy(&boxa2e);
753 boxaDestroy(&boxa2o);
754 boxaDestroy(&boxa3e);
755 boxaDestroy(&boxa3o);
800l_int32 left, right, top, bot, medleft, medright, medtop, medbot;
806 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
810 L_WARNING(
"invalid select; returning copy\n", __func__);
811 return boxaCopy(boxas,
L_COPY);
814 L_WARNING(
"thresh must be >= 0; returning copy\n", __func__);
815 return boxaCopy(boxas,
L_COPY);
817 if (boxaGetValidCount(boxas) < 3) {
818 L_WARNING(
"need at least 3 valid boxes; returning copy\n", __func__);
819 return boxaCopy(boxas,
L_COPY);
840 l_int32 ndb = pixaGetCount(pixadb);
841 if (ndb == 0 || ndb == 5) {
842 adjustSidePlotName(buf,
sizeof(buf),
"init", select);
848 n = boxaGetCount(boxas);
849 boxad = boxaCreate(n);
851 boxaGetMedianVals(boxas, &medleft, NULL, NULL, NULL, NULL, NULL);
852 for (i = 0; i < n; i++) {
853 box = boxaGetBox(boxas, i,
L_COPY);
854 boxGetSideLocations(box, &left, NULL, NULL, NULL);
855 diff = medleft - left;
856 if (L_ABS(diff) >= thresh)
857 boxAdjustSides(box, box, diff - extra, 0, 0, 0);
861 boxaGetMedianVals(boxas, NULL, NULL, &medright, NULL, NULL, NULL);
862 for (i = 0; i < n; i++) {
863 box = boxaGetBox(boxas, i,
L_COPY);
864 boxGetSideLocations(box, NULL, &right, NULL, NULL);
865 diff = medright - right;
866 if (L_ABS(diff) >= thresh)
867 boxAdjustSides(box, box, 0, diff + extra, 0, 0);
871 boxaGetMedianVals(boxas, NULL, &medtop, NULL, NULL, NULL, NULL);
872 for (i = 0; i < n; i++) {
873 box = boxaGetBox(boxas, i,
L_COPY);
874 boxGetSideLocations(box, NULL, NULL, &top, NULL);
876 if (L_ABS(diff) >= thresh)
877 boxAdjustSides(box, box, 0, 0, diff - extra, 0);
881 boxaGetMedianVals(boxas, NULL, NULL, NULL, &medbot, NULL, NULL);
882 for (i = 0; i < n; i++) {
883 box = boxaGetBox(boxas, i,
L_COPY);
884 boxGetSideLocations(box, NULL, NULL, NULL, &bot);
886 if (L_ABS(diff) >= thresh)
887 boxAdjustSides(box, box, 0, 0, 0, diff + extra);
893 adjustSidePlotName(buf,
sizeof(buf),
"final", select);
977l_int32 i, n, ne, no, outfound, isvalid, ind, del, maxdel;
978l_int32 medw, medh, bw, bh, left, right, top, bot;
979l_int32 medleft, medlefte, medlefto, medright, medrighte, medrighto;
980l_int32 medtop, medtope, medtopo, medbot, medbote, medboto;
983BOXA *boxa1, *boxae, *boxao, *boxad;
984NUMA *naind, *nadelw, *nadelh;
986 if (pnadelw) *pnadelw = NULL;
987 if (pnadelh) *pnadelh = NULL;
988 if (pratiowh) *pratiowh = 0.0;
990 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
993 L_WARNING(
"invalid type; returning copy\n", __func__);
994 return boxaCopy(boxas,
L_COPY);
996 if (dfract <= 0.0 || dfract >= 0.5) {
997 L_WARNING(
"invalid dimensional fract; returning copy\n", __func__);
998 return boxaCopy(boxas,
L_COPY);
1000 if (sfract <= 0.0 || sfract >= 0.5) {
1001 L_WARNING(
"invalid side fract; returning copy\n", __func__);
1002 return boxaCopy(boxas,
L_COPY);
1004 if (factor < 0.8 || factor > 1.25)
1005 L_WARNING(
"factor %5.3f is typ. closer to 1.0\n", __func__, factor);
1006 if (boxaGetValidCount(boxas) < 6) {
1007 L_WARNING(
"need at least 6 valid boxes; returning copy\n", __func__);
1008 return boxaCopy(boxas,
L_COPY);
1015 factor, pnadelw, NULL, pratiowh);
1017 factor, NULL, pnadelh, NULL);
1018 boxaDestroy(&boxa1);
1022 n = boxaGetCount(boxas);
1023 naind = numaCreate(n);
1024 boxae = boxaCreate(0);
1025 boxao = boxaCreate(0);
1031 *pratiowh = (l_float32)medw / (l_float32)medh;
1032 L_INFO(
"median ratio w/h = %5.3f\n", __func__, *pratiowh);
1037 numaDestroy(&nadelw);
1040 for (i = 0; i < n; i++) {
1041 if ((box = boxaGetValidBox(boxas, i,
L_COPY)) == NULL) {
1042 numaAddNumber(naind, 0);
1045 boxGetGeometry(box, NULL, NULL, &bw, NULL);
1046 brat = (l_float32)bw / (l_float32)medw;
1047 if (brat < 1.0 - dfract || brat > 1.0 + dfract) {
1049 numaAddNumber(naind, 1);
1052 numaAddNumber(naind, 0);
1060 numaDestroy(&naind);
1061 boxaDestroy(&boxae);
1062 boxaDestroy(&boxao);
1063 L_INFO(
"no width outlier boxes found\n", __func__);
1064 return boxaCopy(boxas,
L_COPY);
1074 L_INFO(
"fixing width of outlier boxes\n", __func__);
1075 medlefte = medrighte = medlefto = medrighto = 0;
1076 if ((ne = boxaGetValidCount(boxae)) > 0)
1077 boxaGetMedianVals(boxae, &medlefte, NULL, &medrighte, NULL,
1079 if ((no = boxaGetValidCount(boxao)) > 0)
1080 boxaGetMedianVals(boxao, &medlefto, NULL, &medrighto, NULL,
1083 medlefte = medlefto;
1084 medrighte = medrighto;
1085 }
else if (no == 0) {
1086 medlefto = medlefte;
1087 medrighto = medrighte;
1096 boxad = boxaCreate(n);
1097 maxdel = (l_int32)(sfract * medw + 0.5);
1098 for (i = 0; i < n; i++) {
1099 box = boxaGetBox(boxas, i,
L_COPY);
1100 boxIsValid(box, &isvalid);
1101 numaGetIValue(naind, i, &ind);
1102 medleft = (i % 2 == 0) ? medlefte : medlefto;
1103 medright = (i % 2 == 0) ? medrighte : medrighto;
1104 if (ind == 1 && isvalid) {
1105 boxGetSideLocations(box, &left, &right, NULL, NULL);
1106 if (L_ABS(left - medleft) > maxdel) left = medleft;
1107 if (L_ABS(right - medright) > maxdel) right = medright;
1108 del = (l_int32)(factor * medw - (right - left)) / 2;
1118 *pratiowh = (l_float32)medw / (l_float32)medh;
1119 L_INFO(
"median ratio w/h = %5.3f\n", __func__, *pratiowh);
1124 numaDestroy(&nadelh);
1127 for (i = 0; i < n; i++) {
1128 if ((box = boxaGetValidBox(boxas, i,
L_COPY)) == NULL) {
1129 numaAddNumber(naind, 0);
1132 boxGetGeometry(box, NULL, NULL, NULL, &bh);
1133 brat = (l_float32)bh / (l_float32)medh;
1134 if (brat < 1.0 - dfract || brat > 1.0 + dfract) {
1136 numaAddNumber(naind, 1);
1139 numaAddNumber(naind, 0);
1147 numaDestroy(&naind);
1148 boxaDestroy(&boxae);
1149 boxaDestroy(&boxao);
1150 L_INFO(
"no height outlier boxes found\n", __func__);
1151 return boxaCopy(boxas,
L_COPY);
1161 L_INFO(
"fixing height of outlier boxes\n", __func__);
1162 medlefte = medtope = medbote = medtopo = medboto = 0;
1163 if ((ne = boxaGetValidCount(boxae)) > 0)
1164 boxaGetMedianVals(boxae, NULL, &medtope, NULL, &medbote,
1166 if ((no = boxaGetValidCount(boxao)) > 0)
1167 boxaGetMedianVals(boxao, NULL, &medtopo, NULL, &medboto,
1172 }
else if (no == 0) {
1184 boxad = boxaCreate(n);
1185 maxdel = (l_int32)(sfract * medh + 0.5);
1186 for (i = 0; i < n; i++) {
1187 box = boxaGetBox(boxas, i,
L_COPY);
1188 boxIsValid(box, &isvalid);
1189 numaGetIValue(naind, i, &ind);
1190 medtop = (i % 2 == 0) ? medtope : medtopo;
1191 medbot = (i % 2 == 0) ? medbote : medboto;
1192 if (ind == 1 && isvalid) {
1193 boxGetSideLocations(box, NULL, NULL, &top, &bot);
1194 if (L_ABS(top - medtop) > maxdel) top = medtop;
1195 if (L_ABS(bot - medbot) > maxdel) bot = medbot;
1196 del = (l_int32)(factor * medh - (bot - top)) / 2;
1197 boxSetSide(box,
L_SET_TOP, L_MAX(0, top - del), 0);
1198 boxSetSide(box,
L_SET_BOT, bot + del, 0);
1203 numaDestroy(&naind);
1204 boxaDestroy(&boxae);
1205 boxaDestroy(&boxao);
1236 const char *plotname,
1243char buf[128], titlebuf[128];
1245static l_int32 plotid = 0;
1246l_int32 n, i, w, h, left, top, right, bot;
1247l_int32 debugprint = FALSE;
1251NUMA *nal, *nat, *nar, *nab;
1253 if (pnal) *pnal = NULL;
1254 if (pnat) *pnat = NULL;
1255 if (pnar) *pnar = NULL;
1256 if (pnab) *pnab = NULL;
1257 if (ppixd) *ppixd = NULL;
1259 return ERROR_INT(
"boxa not defined", __func__, 1);
1260 if ((n = boxaGetCount(boxa)) < 2)
1261 return ERROR_INT(
"less than 2 boxes", __func__, 1);
1263 return ERROR_INT(
"&pixd not defined", __func__, 1);
1268 nal = numaCreate(n);
1269 nat = numaCreate(n);
1270 nar = numaCreate(n);
1271 nab = numaCreate(n);
1273 for (i = 0; i < n; i++) {
1274 boxaGetBoxGeometry(boxat, i, &left, &top, &w, &h);
1275 right = left + w - 1;
1277 numaAddNumber(nal, left);
1278 numaAddNumber(nat, top);
1279 numaAddNumber(nar, right);
1280 numaAddNumber(nab, bot);
1282 boxaDestroy(&boxat);
1284 lept_mkdir(
"lept/plots");
1286 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/sides.%s", plotname);
1287 snprintf(titlebuf,
sizeof(titlebuf),
"%s: Box sides vs. box index",
1290 snprintf(buf,
sizeof(buf),
"/tmp/lept/plots/sides.%d", plotid++);
1291 snprintf(titlebuf,
sizeof(titlebuf),
"Box sides vs. box index");
1293 gplot = gplotCreate(buf, GPLOT_PNG, titlebuf,
1294 "box index",
"side location");
1295 gplotAddPlot(gplot, NULL, nal, GPLOT_LINES,
"left side");
1296 gplotAddPlot(gplot, NULL, nat, GPLOT_LINES,
"top side");
1297 gplotAddPlot(gplot, NULL, nar, GPLOT_LINES,
"right side");
1298 gplotAddPlot(gplot, NULL, nab, GPLOT_LINES,
"bottom side");
1299 *ppixd = gplotMakeOutputPix(gplot);
1300 gplotDestroy(&gplot);
1303 dataname = (plotname) ? stringNew(plotname) : stringNew(
"no_name");
1304 numaGetMedian(nal, &med);
1305 numaGetMeanDevFromMedian(nal, med, &dev);
1306 lept_stderr(
"%s left: med = %7.3f, meandev = %7.3f\n",
1307 dataname, med, dev);
1308 numaGetMedian(nat, &med);
1309 numaGetMeanDevFromMedian(nat, med, &dev);
1310 lept_stderr(
"%s top: med = %7.3f, meandev = %7.3f\n",
1311 dataname, med, dev);
1312 numaGetMedian(nar, &med);
1313 numaGetMeanDevFromMedian(nar, med, &dev);
1314 lept_stderr(
"%s right: med = %7.3f, meandev = %7.3f\n",
1315 dataname, med, dev);
1316 numaGetMedian(nab, &med);
1317 numaGetMeanDevFromMedian(nab, med, &dev);
1318 lept_stderr(
"%s bot: med = %7.3f, meandev = %7.3f\n",
1319 dataname, med, dev);
1320 LEPT_FREE(dataname);
1507l_int32 n, nv, i, j, spandown, spanup;
1512 return ERROR_INT(
"boxa not defined", __func__, 1);
1513 n = boxaGetCount(boxa);
1514 nv = boxaGetValidCount(boxa);
1515 if (n == nv)
return 0;
1517 L_WARNING(
"no valid boxes out of %d boxes\n", __func__, n);
1522 if ((indic = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32))) == NULL)
1523 return ERROR_INT(
"indic not made", __func__, 1);
1524 for (i = 0; i < n; i++) {
1525 box = boxaGetValidBox(boxa, i,
L_CLONE);
1532 for (i = 0; i < n; i++) {
1533 box = boxaGetValidBox(boxa, i,
L_CLONE);
1535 spandown = spanup = 10000000;
1536 for (j = i - 1; j >= 0; j--) {
1537 if (indic[j] == 1) {
1542 for (j = i + 1; j < n; j++) {
1543 if (indic[j] == 1) {
1548 if (spandown < spanup)
1549 boxt = boxaGetBox(boxa, i - spandown,
L_COPY);
1551 boxt = boxaGetBox(boxa, i + spanup,
L_COPY);
1552 boxaReplaceBox(boxa, i, boxt);
1589 l_float32 *pdel_evenodd,
1590 l_float32 *prms_even,
1591 l_float32 *prms_odd,
1592 l_float32 *prms_all)
1594l_int32 n, ne, no, nmin, vale, valo, i;
1597NUMA *nae, *nao, *na_all;
1599 if (pdel_evenodd) *pdel_evenodd = 0.0;
1600 if (prms_even) *prms_even = 0.0;
1601 if (prms_odd) *prms_odd = 0.0;
1602 if (prms_all) *prms_all = 0.0;
1604 return ERROR_INT(
"boxa not defined", __func__, 1);
1606 return ERROR_INT(
"invalid type", __func__, 1);
1607 if (!pdel_evenodd && !prms_even && !prms_odd && !prms_all)
1608 return ERROR_INT(
"nothing to do", __func__, 1);
1609 n = boxaGetCount(boxa);
1611 return ERROR_INT(
"too few boxes", __func__, 1);
1613 boxaSplitEvenOdd(boxa, 0, &boxae, &boxao);
1614 ne = boxaGetCount(boxae);
1615 no = boxaGetCount(boxao);
1616 nmin = L_MIN(ne, no);
1618 boxaDestroy(&boxae);
1619 boxaDestroy(&boxao);
1620 return ERROR_INT(
"either no even or no odd boxes", __func__, 1);
1624 boxaGetSizes(boxae, &nae, NULL);
1625 boxaGetSizes(boxao, &nao, NULL);
1626 boxaGetSizes(boxa, &na_all, NULL);
1628 boxaGetSizes(boxae, NULL, &nae);
1629 boxaGetSizes(boxao, NULL, &nao);
1630 boxaGetSizes(boxa, NULL, &na_all);
1635 for (i = 0; i < nmin; i++) {
1636 numaGetIValue(nae, i, &vale);
1637 numaGetIValue(nao, i, &valo);
1638 sum += L_ABS(vale - valo);
1640 *pdel_evenodd = sum / nmin;
1643 numaSimpleStats(nae, 0, -1, NULL, NULL, prms_even);
1645 numaSimpleStats(nao, 0, -1, NULL, NULL, prms_odd);
1647 numaSimpleStats(na_all, 0, -1, NULL, NULL, prms_all);
1649 boxaDestroy(&boxae);
1650 boxaDestroy(&boxao);
1653 numaDestroy(&na_all);
1698l_int32 i, n, bw, bh, medw, medh, medwe, medwo, medhe, medho;
1700NUMA *nadelw, *nadelh;
1702 if (pmedw) *pmedw = 0;
1703 if (pmedh) *pmedh = 0;
1704 if (pmedwe) *pmedwe= 0;
1705 if (pmedwo) *pmedwo= 0;
1706 if (pmedhe) *pmedhe= 0;
1707 if (pmedho) *pmedho= 0;
1708 if (pnadelw) *pnadelw = NULL;
1709 if (pnadelh) *pnadelh = NULL;
1711 return ERROR_INT(
"boxas not defined", __func__, 1);
1712 if (boxaGetValidCount(boxas) < 6)
1713 return ERROR_INT(
"need at least 6 valid boxes", __func__, 1);
1716 boxaSplitEvenOdd(boxas, 0, &boxae, &boxao);
1717 if (boxaGetValidCount(boxae) < 3 || boxaGetValidCount(boxao) < 3) {
1718 boxaDestroy(&boxae);
1719 boxaDestroy(&boxao);
1720 return ERROR_INT(
"don't have 3+ valid boxes of each type", __func__, 1);
1724 boxaGetMedianVals(boxas, NULL, NULL, NULL, NULL, &medw, &medh);
1725 boxaGetMedianVals(boxae, NULL, NULL, NULL, NULL, &medwe, &medhe);
1726 boxaGetMedianVals(boxao, NULL, NULL, NULL, NULL, &medwo, &medho);
1727 if (pmedw) *pmedw = medw;
1728 if (pmedh) *pmedh = medh;
1729 if (pmedwe) *pmedwe = medwe;
1730 if (pmedwo) *pmedwo = medwo;
1731 if (pmedhe) *pmedhe = medhe;
1732 if (pmedho) *pmedho = medho;
1735 n = boxaGetCount(boxas);
1736 nadelw = numaCreate(n);
1737 nadelh = numaCreate(n);
1738 for (i = 0; i < n; i++) {
1739 boxaGetBoxGeometry(boxas, i, NULL, NULL, &bw, &bh);
1740 if (bw == 0 || bh == 0) {
1741 numaAddNumber(nadelw, 0);
1742 numaAddNumber(nadelh, 0);
1744 numaAddNumber(nadelw, bw - medw);
1745 numaAddNumber(nadelh, bh - medh);
1751 numaDestroy(&nadelw);
1755 numaDestroy(&nadelh);
1757 boxaDestroy(&boxae);
1758 boxaDestroy(&boxao);