106 #include <config_auto.h>
111 #include "allheaders.h"
113 static const l_uint32 rmask32[] = {0x0,
114 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
115 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
116 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
117 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
118 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
119 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
120 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
121 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
123 #ifndef NO_CONSOLE_IO
124 #define DEBUG_EDGES 0
147 if (pnaw) *pnaw = NULL;
148 if (pnah) *pnah = NULL;
150 return ERROR_INT(
"no output requested", __func__, 1);
152 return ERROR_INT(
"pixa not defined", __func__, 1);
157 for (i = 0; i < n; i++) {
197 return ERROR_INT(
"&fract not defined", __func__, 1);
199 if (!pixs || pixGetDepth(pixs) != 1)
200 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
211 if (!tab) LEPT_FREE(tab8);
216 *pfract = (l_float32)nfg / (l_float32)nbound;
219 if (!tab) LEPT_FREE(tab8);
246 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
251 for (i = 0; i < n; i++) {
294 return ERROR_INT(
"&fract not defined", __func__, 1);
296 if (!pixs || pixGetDepth(pixs) != 1)
297 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
306 if (!tab) LEPT_FREE(tab8);
312 *pfract = (l_float32)nbound / (l_float32)nfg;
315 if (!tab) LEPT_FREE(tab8);
346 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
351 for (i = 0; i < n; i++) {
390 l_int32 w, h, nbound;
394 return ERROR_INT(
"&ratio not defined", __func__, 1);
396 if (!pixs || pixGetDepth(pixs) != 1)
397 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
408 *pratio = (0.5 * nbound) / (l_float32)(w + h);
411 if (!tab) LEPT_FREE(tab8);
438 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
443 for (i = 0; i < n; i++) {
478 return ERROR_INT(
"&fract not defined", __func__, 1);
480 if (!pixs || pixGetDepth(pixs) != 1)
481 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
489 *pfract = (l_float32)sum / (l_float32)(w * h);
491 if (!tab) LEPT_FREE(tab8);
528 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
529 if (!pixm || pixGetDepth(pixm) != 1)
530 return (
NUMA *)ERROR_PTR(
"pixm undefined or not 1 bpp", __func__, NULL);
537 for (i = 0; i < n; i++) {
559 pixDisplay(pix2, 100, 100);
599 l_int32 x, y, w, h, sum, masksum;
604 return ERROR_INT(
"&fract not defined", __func__, 1);
606 if (!pixs || pixGetDepth(pixs) != 1)
607 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
608 if (!pixm || pixGetDepth(pixm) != 1)
609 return ERROR_INT(
"pixm not defined or not 1 bpp", __func__, 1);
625 if (!tab) LEPT_FREE(tab8);
629 *pfract = (l_float32)masksum / (l_float32)sum;
631 if (!tab) LEPT_FREE(tab8);
657 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
661 for (i = 0; i < n; i++) {
691 return (
NUMA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
695 for (i = 0; i < n; i++) {
731 l_int32 w, h, nintersect, nunion;
734 if (pnoverlap) *pnoverlap = 0;
736 return ERROR_INT(
"&ratio not defined", __func__, 1);
738 if (!pixs1 || pixGetDepth(pixs1) != 1)
739 return ERROR_INT(
"pixs1 not defined or not 1 bpp", __func__, 1);
740 if (!pixs2 || pixGetDepth(pixs2) != 1)
741 return ERROR_INT(
"pixs2 not defined or not 1 bpp", __func__, 1);
753 *pnoverlap = nintersect;
757 if (!tab) LEPT_FREE(tab8);
761 *pratio = (l_float32)nintersect / (l_float32)nunion;
792 l_int32 w, h, i, n, conforms;
798 if (!pixs || pixGetDepth(pixs) != 1)
799 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
801 return (
BOXA *)ERROR_PTR(
"dist must be >= 0", __func__, NULL);
802 if (minw <= 2 * dist && minh <= 2 * dist)
803 return (
BOXA *)ERROR_PTR(
"invalid parameters", __func__, NULL);
808 for (i = 0; i < n; i++) {
811 if (w < minw || h < minh) {
874 return ERROR_INT(
"&conforms not defined", __func__, 1);
876 if (!pixs || pixGetDepth(pixs) != 1)
877 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
879 return ERROR_INT(
"dist must be >= 0", __func__, 1);
881 if (w <= 2 * dist || h <= 2 * dist) {
882 L_WARNING(
"automatic conformation: distance too large\n", __func__);
908 *pconforms = (empty) ? 1 : 0;
939 return (
PIXA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
941 return (
PIXA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
945 for (i = 0; i < n; i++) {
998 l_int32 w, h, d, bx, by, bw, bh;
1002 if (pboxc) *pboxc = NULL;
1004 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1006 return (
PIX *)ERROR_PTR(
"box not defined", __func__, NULL);
1011 L_WARNING(
"box doesn't overlap pix\n", __func__);
1017 if ((pixd =
pixCreate(bw, bh, d)) == NULL) {
1019 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1021 pixCopyResolution(pixd, pixs);
1023 pixCopyText(pixd, pixs);
1060 l_int32 w, h, bx, by, bw, bh, bord;
1065 return (
PIX *)ERROR_PTR(
"&boxn not defined", __func__, NULL);
1068 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1070 return (
PIX *)ERROR_PTR(
"box not defined", __func__, NULL);
1075 bord = L_MIN(bx, by);
1076 bord = L_MIN(bord, w - bx - bw);
1077 bord = L_MIN(bord, h - by - bh);
1078 bord = L_MIN(bord, maxbord);
1132 l_int32 wm, hm, index, rval, gval, bval;
1139 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1140 if (!pixm || pixGetDepth(pixm) != 1)
1141 return (
PIX *)ERROR_PTR(
"pixm undefined or not 1 bpp", __func__, NULL);
1150 cmap = pixGetColormap(pixd);
1191 l_int32 w1, h1, w2, h2, w, h;
1193 if (!ppixd1 || !ppixd2)
1194 return ERROR_INT(
"&pixd1 and &pixd2 not both defined", __func__, 1);
1195 *ppixd1 = *ppixd2 = NULL;
1196 if (!pixs1 || !pixs2)
1197 return ERROR_INT(
"pixs1 and pixs2 not defined", __func__, 1);
1206 if (*ppixd1 == NULL || *ppixd2 == NULL)
1207 return ERROR_INT(
"cropped image failure", __func__, 1);
1231 l_int32 ws, hs, wd, hd, d;
1235 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1238 if (ws <= w && hs <= h)
1243 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
1244 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1245 pixCopyResolution(pixd, pixs);
1247 pixCopyText(pixd, pixs);
1248 pixCopyInputFormat(pixd, pixs);
1284 l_int32 i, j, ws, hs, d;
1288 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1289 if (!pixt && (w <= 0 || h <= 0))
1290 return (
PIX *)ERROR_PTR(
"both w and h not > 0", __func__, NULL);
1295 if (ws == w && hs == h)
1298 if ((pixd =
pixCreate(w, h, d)) == NULL)
1299 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1300 pixCopyResolution(pixd, pixs);
1302 pixCopyText(pixd, pixs);
1303 pixCopyInputFormat(pixd, pixs);
1305 if (ws >= w && hs >= h)
1310 for (j = ws; j < w; j++)
1314 for (i = hs; i < h; i++)
1346 pixSelectComponentBySize(
PIX *pixs,
1349 l_int32 connectivity,
1352 l_int32 n, empty, sorttype, index;
1356 PIXA *pixa1, *pixa2;
1358 if (pbox) *pbox = NULL;
1359 if (!pixs || pixGetDepth(pixs) != 1)
1360 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
1372 return (
PIX *)ERROR_PTR(
"invalid selection type", __func__, NULL);
1373 if (connectivity != 4 && connectivity != 8)
1374 return (
PIX *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
1377 return (
PIX *)ERROR_PTR(
"no foreground pixels", __func__, NULL);
1381 if (rankorder < 0 || rankorder >= n)
1417 pixFilterComponentBySize(
PIX *pixs,
1420 l_int32 connectivity,
1427 if (!pixs || pixGetDepth(pixs) != 1)
1428 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
1430 pix1 = pixSelectComponentBySize(pixs, rankorder, type, connectivity, &box);
1433 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
1490 if (w <= 0 || h <= 0)
1491 return (
PIX *)ERROR_PTR(
"mask size 0", __func__, NULL);
1492 if (hf < 0.0 || hf > 1.0)
1493 return (
PIX *)ERROR_PTR(
"invalid horiz fractions", __func__, NULL);
1494 if (vf < 0.0 || vf > 1.0)
1495 return (
PIX *)ERROR_PTR(
"invalid vert fractions", __func__, NULL);
1502 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1546 l_int32 h1, h2, v1, v2;
1549 if (w <= 0 || h <= 0)
1550 return (
PIX *)ERROR_PTR(
"mask size 0", __func__, NULL);
1551 if (hf1 < 0.0 || hf1 > 1.0 || hf2 < 0.0 || hf2 > 1.0)
1552 return (
PIX *)ERROR_PTR(
"invalid horiz fractions", __func__, NULL);
1553 if (vf1 < 0.0 || vf1 > 1.0 || vf2 < 0.0 || vf2 > 1.0)
1554 return (
PIX *)ERROR_PTR(
"invalid vert fractions", __func__, NULL);
1555 if (hf1 > hf2 || vf1 > vf2)
1556 return (
PIX *)ERROR_PTR(
"invalid relative sizes", __func__, NULL);
1561 if (hf1 == 0.0 && vf1 == 0.0 && hf2 == 1.0 && vf2 == 1.0) {
1565 if (hf1 == hf2 && vf1 == vf2) {
1575 if (hf2 < 1.0 && vf2 < 1.0)
1606 l_int32 empty, same, niters;
1610 if (!pixs || pixGetDepth(pixs) != 1)
1611 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
1613 return (
PIX *)ERROR_PTR(
"maxiters must be >= 0", __func__, NULL);
1614 if (maxiters == 0) maxiters = 50;
1618 if (empty)
return pix1;
1624 if (maxiters == 1)
return pix1;
1627 while (niters < maxiters) {
1636 L_INFO(
"%d iterations\n", __func__, niters - 1);
1640 L_INFO(
"maxiters = %d reached\n", __func__, niters);
1678 l_int32 w1, h1, w2, h2, empty, count1, count3;
1682 return ERROR_INT(
"&fract not defined", __func__, 1);
1684 if (!pix1 || pixGetDepth(pix1) != 1)
1685 return ERROR_INT(
"pix1 not defined or not 1 bpp", __func__, 1);
1686 if (!pix2 || pixGetDepth(pix2) != 1)
1687 return ERROR_INT(
"pix2 not defined or not 1 bpp", __func__, 1);
1691 if (w1 != w2 || h1 != h2) {
1692 L_INFO(
"sizes unequal: (w1,w2) = (%d,%d), (h1,h2) = (%d,%d)\n",
1693 __func__, w1, w2, h1, h2);
1696 if (empty)
return 0;
1698 if (empty)
return 0;
1701 pixAnd(pix3, pix3, pix2);
1704 *pfract = (l_float32)count3 / (l_float32)count1;
1732 l_int32 w, h, wpl, nfullwords, extra, i, j;
1733 l_int32 minx, miny, maxx, maxy;
1734 l_uint32 result, mask;
1735 l_uint32 *data, *line;
1738 if (ppixd) *ppixd = NULL;
1739 if (pbox) *pbox = NULL;
1740 if (!ppixd && !pbox)
1741 return ERROR_INT(
"no output requested", __func__, 1);
1742 if (!pixs || (pixGetDepth(pixs) != 1))
1743 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
1746 nfullwords = w / 32;
1748 mask = ~rmask32[32 - extra];
1749 wpl = pixGetWpl(pixs);
1753 for (i = 0, miny = 0; i < h; i++, miny++) {
1754 line = data + i * wpl;
1755 for (j = 0; j < nfullwords; j++)
1758 result |= (line[j] & mask);
1766 for (i = h - 1, maxy = h - 1; i >= 0; i--, maxy--) {
1767 line = data + i * wpl;
1768 for (j = 0; j < nfullwords; j++)
1771 result |= (line[j] & mask);
1777 for (j = 0, minx = 0; j < w; j++, minx++) {
1778 for (i = 0; i < h; i++) {
1779 line = data + i * wpl;
1786 for (j = w - 1, maxx = w - 1; j >= 0; j--, maxx--) {
1787 for (i = 0; i < h; i++) {
1788 line = data + i * wpl;
1795 box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1);
1829 l_int32 i, j, w, h, wpl, found;
1830 l_uint32 *data, *line;
1833 return ERROR_INT(
"&canclip not defined", __func__, 1);
1835 if (!pixs || (pixGetDepth(pixs) != 1))
1836 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
1841 wpl = pixGetWpl(pixs);
1843 for (j = 0; found == FALSE && j < w; j++)
1850 line = data + (h - 1) * wpl;
1852 for (j = 0; found == FALSE && j < w; j++)
1861 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1869 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1901 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
1904 if (ppixd) *ppixd = NULL;
1905 if (pboxd) *pboxd = NULL;
1906 if (!ppixd && !pboxd)
1907 return ERROR_INT(
"no output requested", __func__, 1);
1908 if (!pixs || (pixGetDepth(pixs) != 1))
1909 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
1916 cbw = L_MIN(bw, w - bx);
1917 cbh = L_MIN(bh, h - by);
1918 if (cbw < 0 || cbh < 0)
1919 return ERROR_INT(
"box not within image", __func__, 1);
1930 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
1965 l_int32 bx, by, bw, bh, x, xstart, xend, y, ystart, yend, wpl;
1966 l_uint32 *data, *line;
1970 return ERROR_INT(
"&loc not defined", __func__, 1);
1972 if (!pixs || (pixGetDepth(pixs) != 1))
1973 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
1979 return ERROR_INT(
"invalid box", __func__, 1);
1991 wpl = pixGetWpl(pixs);
1993 for (x = xstart; x <= xend; x++) {
1994 for (y = ystart; y <= yend; y++) {
1995 line = data + y * wpl;
2003 for (x = xend; x >= xstart; x--) {
2004 for (y = ystart; y <= yend; y++) {
2005 line = data + y * wpl;
2013 for (y = ystart; y <= yend; y++) {
2014 line = data + y * wpl;
2015 for (x = xstart; x <= xend; x++) {
2023 for (y = yend; y >= ystart; y--) {
2024 line = data + y * wpl;
2025 for (x = xstart; x <= xend; x++) {
2033 return ERROR_INT(
"invalid scanflag", __func__, 1);
2083 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
2084 l_int32 lfound, rfound, tfound, bfound, change;
2087 if (ppixd) *ppixd = NULL;
2088 if (pboxd) *pboxd = NULL;
2089 if (!ppixd && !pboxd)
2090 return ERROR_INT(
"no output requested", __func__, 1);
2091 if (!pixs || (pixGetDepth(pixs) != 1))
2092 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
2093 if (lowthresh < 1 || highthresh < 1 ||
2094 lowthresh > highthresh || maxwidth < 1)
2095 return ERROR_INT(
"invalid thresholds", __func__, 1);
2096 factor = L_MIN(1, factor);
2098 if (lowthresh == 1 && highthresh == 1)
2104 cbw = L_MIN(bw, w - bx);
2105 cbh = L_MIN(bh, h - by);
2106 if (cbw < 0 || cbh < 0)
2107 return ERROR_INT(
"box not within image", __func__, 1);
2113 lfound = rfound = tfound = bfound = 0;
2114 while (!lfound || !rfound || !tfound || !bfound) {
2150 lept_stderr(
"iter: %d %d %d %d\n", lfound, rfound, tfound, bfound);
2153 if (change == 0)
break;
2158 return ERROR_INT(
"not all edges found", __func__, 1);
2160 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
2211 l_int32 bx, by, bw, bh, foundmin, loc, sum, wpl;
2212 l_int32 x, xstart, xend, y, ystart, yend;
2213 l_uint32 *data, *line;
2217 return ERROR_INT(
"&ploc not defined", __func__, 1);
2219 if (!pixs || (pixGetDepth(pixs) != 1))
2220 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
2221 if (lowthresh < 1 || highthresh < 1 ||
2222 lowthresh > highthresh || maxwidth < 1)
2223 return ERROR_INT(
"invalid thresholds", __func__, 1);
2224 factor = L_MIN(1, factor);
2230 return ERROR_INT(
"invalid box", __func__, 1);
2242 wpl = pixGetWpl(pixs);
2245 for (x = xstart; x <= xend; x++) {
2247 for (y = ystart; y <= yend; y += factor) {
2248 line = data + y * wpl;
2252 if (!foundmin && sum < lowthresh)
2258 if (sum >= highthresh) {
2262 if (x - loc < maxwidth) {
2271 for (x = xend; x >= xstart; x--) {
2273 for (y = ystart; y <= yend; y += factor) {
2274 line = data + y * wpl;
2278 if (!foundmin && sum < lowthresh)
2284 if (sum >= highthresh) {
2288 if (loc - x < maxwidth) {
2297 for (y = ystart; y <= yend; y++) {
2299 line = data + y * wpl;
2300 for (x = xstart; x <= xend; x += factor) {
2304 if (!foundmin && sum < lowthresh)
2310 if (sum >= highthresh) {
2314 if (y - loc < maxwidth) {
2323 for (y = yend; y >= ystart; y--) {
2325 line = data + y * wpl;
2326 for (x = xstart; x <= xend; x += factor) {
2330 if (!foundmin && sum < lowthresh)
2336 if (sum >= highthresh) {
2338 lept_stderr(
"Bottom: y = %d, loc = %d\n", y, loc);
2340 if (loc - y < maxwidth) {
2349 return ERROR_INT(
"invalid scanflag", __func__, 1);
2388 l_int32 i, w, h, d, xmin, ymin, xmax, ymax, npts, direction;
2396 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2398 if (d != 1 && d != 8)
2399 return (
NUMA *)ERROR_PTR(
"d not 1 or 8 bpp", __func__, NULL);
2400 if (pixGetColormap(pixs))
2401 return (
NUMA *)ERROR_PTR(
"pixs has a colormap", __func__, NULL);
2403 L_WARNING(
"factor must be >= 1; setting to 1\n", __func__);
2408 x1 = L_MAX(0, L_MIN(x1, w - 1));
2409 x2 = L_MAX(0, L_MIN(x2, w - 1));
2410 y1 = L_MAX(0, L_MIN(y1, h - 1));
2411 y2 = L_MAX(0, L_MIN(y2, h - 1));
2413 if (x1 == x2 && y1 == y2) {
2429 xmin = L_MIN(x1, x2);
2430 xmax = L_MAX(x1, x2);
2432 for (i = xmin; i <= xmax; i += factor) {
2437 ymin = L_MIN(y1, y2);
2438 ymax = L_MAX(y1, y2);
2440 for (i = ymin; i <= ymax; i += factor) {
2445 slope = (l_float64)((y2 - y1) / (x2 - x1));
2446 if (L_ABS(slope) < 1.0) {
2447 xmin = L_MIN(x1, x2);
2448 xmax = L_MAX(x1, x2);
2449 ymin = (xmin == x1) ? y1 : y2;
2450 ymax = (ymin == y1) ? y2 : y1;
2454 ymin = L_MIN(y1, y2);
2455 ymax = L_MAX(y1, y2);
2456 xmin = (ymin == y1) ? x1 : x2;
2457 xmax = (xmin == x1) ? x2 : x1;
2462 for (i = 0; i < npts; i += factor) {
2506 l_int32 i, j, w, h, d, direction, count, wpl;
2507 l_uint32 *data, *line;
2511 return ERROR_INT(
"pixs not defined", __func__, 1);
2513 if (d != 1 && d != 8)
2514 return ERROR_INT(
"d not 1 or 8 bpp", __func__, 1);
2515 if (pixGetColormap(pixs))
2516 return ERROR_INT(
"pixs has a colormap", __func__, 1);
2517 if (x1 > x2 || y1 > y2)
2518 return ERROR_INT(
"x1 > x2 or y1 > y2", __func__, 1);
2522 x2 = L_MIN(w - 1, x2);
2523 y1 = L_MAX(0, L_MIN(y1, h - 1));
2525 }
else if (x1 == x2) {
2527 y2 = L_MIN(h - 1, y2);
2528 x1 = L_MAX(0, L_MIN(x1, w - 1));
2531 return ERROR_INT(
"line neither horiz nor vert", __func__, 1);
2535 L_WARNING(
"factor must be >= 1; setting to 1\n", __func__);
2540 wpl = pixGetWpl(pixs);
2544 line = data + y1 * wpl;
2545 for (j = x1, count = 0; j <= x2; count++, j += factor) {
2552 for (i = y1, count = 0; i <= y2; count++, i += factor) {
2553 line = data + i * wpl;
2561 return sum / (l_float32)count;
2604 l_int32 i, j, w, h, d, start, end;
2610 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2611 if (fract < 0.0 || fract > 1.0)
2612 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", __func__, NULL);
2614 return (
NUMA *)ERROR_PTR(
"invalid direction", __func__, NULL);
2615 if (first < 0) first = 0;
2617 return (
NUMA *)ERROR_PTR(
"last must be >= first", __func__, NULL);
2619 L_WARNING(
"factor1 must be >= 1; setting to 1\n", __func__);
2623 L_WARNING(
"factor2 must be >= 1; setting to 1\n", __func__);
2628 if (pixGetColormap(pixs))
2641 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2644 L_WARNING(
"last > h - 1; clipping\n", __func__);
2647 for (i = first; i <= last; i += factor2) {
2652 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2655 L_WARNING(
"last > w - 1; clipping\n", __func__);
2658 for (j = first; j <= last; j += factor2) {
2714 l_int32 minreversal,
2718 l_int32 i, j, w, h, d, start, end, nr;
2723 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2724 if (fract < 0.0 || fract > 1.0)
2725 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", __func__, NULL);
2727 return (
NUMA *)ERROR_PTR(
"invalid direction", __func__, NULL);
2728 if (first < 0) first = 0;
2730 return (
NUMA *)ERROR_PTR(
"last must be >= first", __func__, NULL);
2732 L_WARNING(
"factor1 must be >= 1; setting to 1\n", __func__);
2736 L_WARNING(
"factor2 must be >= 1; setting to 1\n", __func__);
2741 if (pixGetColormap(pixs))
2756 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2759 L_WARNING(
"last > h - 1; clipping\n", __func__);
2762 for (i = first; i <= last; i += factor2) {
2769 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2772 L_WARNING(
"last > w - 1; clipping\n", __func__);
2775 for (j = first; j <= last; j += factor2) {
2824 l_int32 i, j, w, h, cmin, cmax, maxloc, n, x, y;
2826 l_float32 norm, rootvar;
2828 l_float64 sum1, sum2, ave, var;
2833 return ERROR_INT(
"&nad not defined", __func__, 1);
2835 if (!pixs || pixGetDepth(pixs) != 8)
2836 return ERROR_INT(
"pixs not defined or not 8bpp", __func__, 1);
2838 return ERROR_INT(
"window size must be > 1", __func__, 1);
2840 return ERROR_INT(
"invalid direction", __func__, 1);
2843 if (loc < 0 || loc > maxloc)
2844 return ERROR_INT(
"invalid line position", __func__, 1);
2847 cmin = L_MIN(c1, c2);
2848 cmax = L_MAX(c1, c2);
2850 cmin = L_MAX(0, L_MIN(cmin, maxloc));
2851 cmax = L_MAX(0, L_MIN(cmax, maxloc));
2852 n = cmax - cmin + 1;
2857 for (i = cmin; i <= cmax; i++)
2860 for (i = cmin; i <= cmax; i++)
2867 for (i = 0; i < n; i++) {
2879 norm = 1.0 / (l_float32)size;
2880 for (i = 0; i < n - size; i++) {
2882 for (j = 0; j < size; j++) {
2885 sum2 += (l_float64)(val) * val;
2888 var = norm * sum2 - ave * ave;
2891 rootvar = (l_float32)sqrt(var);
2946 l_int32 i, j, w, h, d, x, y, n, dir, found, minval, maxval, negloc, posloc;
2949 NUMA *namin, *namax;
2952 if (pnamin) *pnamin = NULL;
2953 if (pnamax) *pnamax = NULL;
2954 if (pminave) *pminave = UNDEF;
2955 if (pmaxave) *pmaxave = UNDEF;
2956 if (!pnamin && !pnamax && !pminave && !pmaxave)
2957 return ERROR_INT(
"no output requested", __func__, 1);
2959 return ERROR_INT(
"pixs not defined", __func__, 1);
2961 if (d != 8 || pixGetColormap(pixs))
2962 return ERROR_INT(
"pixs not 8 bpp or has colormap", __func__, 1);
2966 return ERROR_INT(
"invalid direction", __func__, 1);
2970 dir = (L_ABS(x1 - x2) == n - 1) ? L_HORIZ : L_VERT;
2979 for (i = 0; i < n; i++) {
2984 if (dir == L_HORIZ) {
2985 if (x < 0 || x >= w)
continue;
2986 for (j = negloc; j <= posloc; j++) {
2987 if (y + j < 0 || y + j >= h)
continue;
2990 if (val < minval) minval = val;
2991 if (val > maxval) maxval = val;
2994 if (y < 0 || y >= h)
continue;
2995 for (j = negloc; j <= posloc; j++) {
2996 if (x + j < 0 || x + j >= w)
continue;
2999 if (val < minval) minval = val;
3000 if (val > maxval) maxval = val;
3014 return ERROR_INT(
"no output from this line", __func__, 1);
3057 l_int32 i, j, k, m, w, h, wpl, val;
3059 l_uint32 *datas, *datad, *lines, *lined;
3063 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3064 if (pixGetDepth(pixs) != 8)
3065 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
3066 if (pixGetColormap(pixs))
3067 return (
PIX *)ERROR_PTR(
"pixs has a colormap", __func__, NULL);
3073 wpl = pixGetWpl(pixs);
3074 for (i = 0; i < h; i++) {
3075 memset(histo, 0, 1024);
3076 lines = datas + i * wpl;
3077 lined = datad + i * wpl;
3078 for (j = 0; j < w; j++) {
3082 for (m = 0, j = 0; m < 256; m++) {
3083 for (k = 0; k < histo[m]; k++, j++)
3108 l_int32 i, j, k, m, w, h, val;
3110 void **lines8, **lined8;
3114 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3115 if (pixGetDepth(pixs) != 8)
3116 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
3117 if (pixGetColormap(pixs))
3118 return (
PIX *)ERROR_PTR(
"pixs has a colormap", __func__, NULL);
3124 for (j = 0; j < w; j++) {
3125 memset(histo, 0, 1024);
3126 for (i = 0; i < h; i++) {
3130 for (m = 0, i = 0; m < 256; m++) {
3131 for (k = 0; k < histo[m]; k++, i++)
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void boxDestroy(BOX **pbox)
boxDestroy()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_int32 boxaGetCount(const BOXA *boxa)
boxaGetCount()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
BOX * boxRelocateOneSide(BOX *boxd, BOX *boxs, l_int32 loc, l_int32 sideflag)
boxRelocateOneSide()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
BOX * boxAdjustSides(BOX *boxd, BOX *boxs, l_int32 delleft, l_int32 delright, l_int32 deltop, l_int32 delbot)
boxAdjustSides()
PIX * pixMaskBoxa(PIX *pixd, PIX *pixs, BOXA *boxa, l_int32 op)
pixMaskBoxa()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapGetNearestIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetNearestIndex()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixEqual(PIX *pix1, PIX *pix2, l_int32 *psame)
pixEqual()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
PTA * generatePtaLine(l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2)
generatePtaLine()
PIX * pixErodeBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeBrick()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaCreate(l_int32 n)
numaCreate()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok numaSetParameters(NUMA *na, l_float32 startx, l_float32 delx)
numaSetParameters()
l_float32 * numaGetFArray(NUMA *na, l_int32 copyflag)
numaGetFArray()
l_ok numaGetSum(NUMA *na, l_float32 *psum)
numaGetSum()
l_ok numaCountReversals(NUMA *nas, l_float32 minreversal, l_int32 *pnr, l_float32 *prd)
numaCountReversals()
l_ok pixSetMaskedCmap(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetMaskedCmap()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok pixSetAll(PIX *pix)
pixSetAll()
l_ok pixSetOrClearBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
pixSetOrClearBorder()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
l_ok pixPaintThroughMask(PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
pixPaintThroughMask()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
PIX * pixAnd(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixAnd()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
l_ok pixWindowedVarianceOnLine(PIX *pixs, l_int32 dir, l_int32 loc, l_int32 c1, l_int32 c2, l_int32 size, NUMA **pnad)
pixWindowedVarianceOnLine()
l_ok pixFractionFgInMask(PIX *pix1, PIX *pix2, l_float32 *pfract)
pixFractionFgInMask()
l_ok pixFindAreaPerimRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaPerimRatio()
NUMA * pixAverageIntensityProfile(PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 factor1, l_int32 factor2)
pixAverageIntensityProfile()
l_ok pixFindPerimToAreaRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindPerimToAreaRatio()
NUMA * pixaFindAreaFraction(PIXA *pixa)
pixaFindAreaFraction()
PIX * pixCropToSize(PIX *pixs, l_int32 w, l_int32 h)
pixCropToSize()
NUMA * pixaFindPerimSizeRatio(PIXA *pixa)
pixaFindPerimSizeRatio()
PIX * pixMakeSymmetricMask(l_int32 w, l_int32 h, l_float32 hf, l_float32 vf, l_int32 type)
pixSelectComponentBySize()
NUMA * pixaFindPerimToAreaRatio(PIXA *pixa)
pixaFindPerimToAreaRatio()
PIX * pixRankRowTransform(PIX *pixs)
pixRankRowTransform()
l_ok pixFindPerimSizeRatio(PIX *pixs, l_int32 *tab, l_float32 *pratio)
pixFindPerimSizeRatio()
NUMA * pixaFindWidthHeightProduct(PIXA *pixa)
pixaFindWidthHeightProduct()
l_ok pixFindAreaFraction(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaFraction()
l_ok pixScanForForeground(PIX *pixs, BOX *box, l_int32 scanflag, l_int32 *ploc)
pixScanForForeground()
BOXA * pixFindRectangleComps(PIX *pixs, l_int32 dist, l_int32 minw, l_int32 minh)
pixFindRectangleComps()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
l_ok pixClipBoxToEdges(PIX *pixs, BOX *boxs, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, PIX **ppixd, BOX **pboxd)
pixClipBoxToEdges()
l_float32 pixAverageOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor)
pixAverageOnLine()
PIX * pixClipRectangleWithBorder(PIX *pixs, BOX *box, l_int32 maxbord, BOX **pboxn)
pixClipRectangleWithBorder()
l_ok pixTestClipToForeground(PIX *pixs, l_int32 *pcanclip)
pixTestClipToForeground()
PIX * pixRankColumnTransform(PIX *pixs)
pixRankColumnTransform()
l_ok pixClipBoxToForeground(PIX *pixs, BOX *boxs, PIX **ppixd, BOX **pboxd)
pixClipBoxToForeground()
l_ok pixFindAreaFractionMasked(PIX *pixs, BOX *box, PIX *pixm, l_int32 *tab, l_float32 *pfract)
pixFindAreaFractionMasked()
NUMA * pixExtractOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor)
pixExtractOnLine()
l_ok pixScanForEdge(PIX *pixs, BOX *box, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, l_int32 scanflag, l_int32 *ploc)
pixScanForEdge()
l_ok pixMinMaxNearLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 dist, l_int32 direction, NUMA **pnamin, NUMA **pnamax, l_float32 *pminave, l_float32 *pmaxave)
pixMinMaxNearLine()
PIX * pixMakeCoveringOfRectangles(PIX *pixs, l_int32 maxiters)
pixMakeCoveringOfRectangles()
NUMA * pixaFindWidthHeightRatio(PIXA *pixa)
pixaFindWidthHeightRatio()
l_ok pixClipToForeground(PIX *pixs, PIX **ppixd, BOX **pbox)
pixClipToForeground()
l_ok pixaFindDimensions(PIXA *pixa, NUMA **pnaw, NUMA **pnah)
pixaFindDimensions()
l_ok pixConformsToRectangle(PIX *pixs, BOX *box, l_int32 dist, l_int32 *pconforms)
pixConformsToRectangle()
NUMA * pixaFindAreaFractionMasked(PIXA *pixa, PIX *pixm, l_int32 debug)
pixaFindAreaFractionMasked()
PIX * pixClipMasked(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_uint32 outval)
pixClipMasked()
l_ok pixFindOverlapFraction(PIX *pixs1, PIX *pixs2, l_int32 x2, l_int32 y2, l_int32 *tab, l_float32 *pratio, l_int32 *pnoverlap)
pixFindOverlapFraction()
l_ok pixCropToMatch(PIX *pixs1, PIX *pixs2, PIX **ppixd1, PIX **ppixd2)
pixCropToMatch()
NUMA * pixReversalProfile(PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 minreversal, l_int32 factor1, l_int32 factor2)
pixReversalProfile()
PIXA * pixClipRectangles(PIX *pixs, BOXA *boxa)
pixClipRectangles()
PIX * pixMakeFrameMask(l_int32 w, l_int32 h, l_float32 hf1, l_float32 hf2, l_float32 vf1, l_float32 vf2)
pixMakeFrameMask()
@ L_SORT_BY_MAX_DIMENSION
@ REMOVE_CMAP_TO_GRAYSCALE
@ L_SELECT_BY_MAX_DIMENSION
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
BOX * pixaGetBox(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetBox()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
l_ok pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
l_ok pixaIsFull(PIXA *pixa, l_int32 *pfullpa, l_int32 *pfullba)
pixaIsFull()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIXA * pixaSort(PIXA *pixas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex, l_int32 copyflag)
pixaSort()
PIX * pixaDisplay(PIXA *pixa, l_int32 w, l_int32 h)
pixaDisplay()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_ok pixPlotAlongPta(PIX *pixs, PTA *pta, l_int32 outformat, const char *title)
pixPlotAlongPta()
l_ok 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()
PIX * pixExtractBorderConnComps(PIX *pixs, l_int32 connectivity)
pixExtractBorderConnComps()
void lept_stderr(const char *fmt,...)
lept_stderr()