98 #include "allheaders.h" 100 static const l_uint32 rmask32[] = {0x0,
101 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
102 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
103 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
104 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
105 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
106 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
107 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
108 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
110 #ifndef NO_CONSOLE_IO 111 #define DEBUG_EDGES 0 134 PROCNAME(
"pixaFindDimensions");
136 if (pnaw) *pnaw = NULL;
137 if (pnah) *pnah = NULL;
139 return ERROR_INT(
"no output requested", procName, 1);
141 return ERROR_INT(
"pixa not defined", procName, 1);
146 for (i = 0; i < n; i++) {
185 PROCNAME(
"pixFindAreaPerimRatio");
188 return ERROR_INT(
"&fract not defined", procName, 1);
190 if (!pixs || pixGetDepth(pixs) != 1)
191 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
202 if (!tab) LEPT_FREE(tab8);
207 *pfract = (l_float32)nfg / (l_float32)nbound;
210 if (!tab) LEPT_FREE(tab8);
236 PROCNAME(
"pixaFindPerimToAreaRatio");
239 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
244 for (i = 0; i < n; i++) {
286 PROCNAME(
"pixFindPerimToAreaRatio");
289 return ERROR_INT(
"&fract not defined", procName, 1);
291 if (!pixs || pixGetDepth(pixs) != 1)
292 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
301 if (!tab) LEPT_FREE(tab8);
307 *pfract = (l_float32)nbound / (l_float32)nfg;
310 if (!tab) LEPT_FREE(tab8);
340 PROCNAME(
"pixaFindPerimSizeRatio");
343 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
348 for (i = 0; i < n; i++) {
387 l_int32 w, h, nbound;
390 PROCNAME(
"pixFindPerimSizeRatio");
393 return ERROR_INT(
"&ratio not defined", procName, 1);
395 if (!pixs || pixGetDepth(pixs) != 1)
396 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
407 *pratio = (0.5 * nbound) / (l_float32)(w + h);
410 if (!tab) LEPT_FREE(tab8);
436 PROCNAME(
"pixaFindAreaFraction");
439 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
444 for (i = 0; i < n; i++) {
478 PROCNAME(
"pixFindAreaFraction");
481 return ERROR_INT(
"&fract not defined", procName, 1);
483 if (!pixs || pixGetDepth(pixs) != 1)
484 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
492 *pfract = (l_float32)sum / (l_float32)(w * h);
494 if (!tab) LEPT_FREE(tab8);
530 PROCNAME(
"pixaFindAreaFractionMasked");
533 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
534 if (!pixm || pixGetDepth(pixm) != 1)
535 return (
NUMA *)ERROR_PTR(
"pixm undefined or not 1 bpp", procName, NULL);
542 for (i = 0; i < n; i++) {
564 pixDisplay(pix2, 100, 100);
604 l_int32 x, y, w, h, sum, masksum;
608 PROCNAME(
"pixFindAreaFractionMasked");
611 return ERROR_INT(
"&fract not defined", procName, 1);
613 if (!pixs || pixGetDepth(pixs) != 1)
614 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
615 if (!pixm || pixGetDepth(pixm) != 1)
616 return ERROR_INT(
"pixm not defined or not 1 bpp", procName, 1);
632 if (!tab) LEPT_FREE(tab8);
636 *pfract = (l_float32)masksum / (l_float32)sum;
638 if (!tab) LEPT_FREE(tab8);
663 PROCNAME(
"pixaFindWidthHeightRatio");
666 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
670 for (i = 0; i < n; i++) {
699 PROCNAME(
"pixaFindWidthHeightProduct");
702 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
706 for (i = 0; i < n; i++) {
742 l_int32 w, h, nintersect, nunion;
745 PROCNAME(
"pixFindOverlapFraction");
747 if (pnoverlap) *pnoverlap = 0;
749 return ERROR_INT(
"&ratio not defined", procName, 1);
751 if (!pixs1 || pixGetDepth(pixs1) != 1)
752 return ERROR_INT(
"pixs1 not defined or not 1 bpp", procName, 1);
753 if (!pixs2 || pixGetDepth(pixs2) != 1)
754 return ERROR_INT(
"pixs2 not defined or not 1 bpp", procName, 1);
766 *pnoverlap = nintersect;
770 if (!tab) LEPT_FREE(tab8);
774 *pratio = (l_float32)nintersect / (l_float32)nunion;
805 l_int32 w, h, i, n, conforms;
811 PROCNAME(
"pixFindRectangleComps");
813 if (!pixs || pixGetDepth(pixs) != 1)
814 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
816 return (
BOXA *)ERROR_PTR(
"dist must be >= 0", procName, NULL);
817 if (minw <= 2 * dist && minh <= 2 * dist)
818 return (
BOXA *)ERROR_PTR(
"invalid parameters", procName, NULL);
823 for (i = 0; i < n; i++) {
826 if (w < minw || h < minh) {
888 PROCNAME(
"pixConformsToRectangle");
891 return ERROR_INT(
"&conforms not defined", procName, 1);
893 if (!pixs || pixGetDepth(pixs) != 1)
894 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
896 return ERROR_INT(
"dist must be >= 0", procName, 1);
898 if (w <= 2 * dist || h <= 2 * dist) {
899 L_WARNING(
"automatic conformation: distance too large\n", procName);
925 *pconforms = (empty) ? 1 : 0;
955 PROCNAME(
"pixClipRectangles");
958 return (
PIXA *)ERROR_PTR(
"pixs not defined", procName, NULL);
960 return (
PIXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
964 for (i = 0; i < n; i++) {
1017 l_int32 w, h, d, bx, by, bw, bh;
1021 PROCNAME(
"pixClipRectangle");
1023 if (pboxc) *pboxc = NULL;
1025 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1027 return (
PIX *)ERROR_PTR(
"box not defined", procName, NULL);
1032 L_WARNING(
"box doesn't overlap pix\n", procName);
1038 if ((pixd =
pixCreate(bw, bh, d)) == NULL) {
1040 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1042 pixCopyResolution(pixd, pixs);
1044 pixCopyText(pixd, pixs);
1092 l_int32 wm, hm, index, rval, gval, bval;
1098 PROCNAME(
"pixClipMasked");
1101 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1102 if (!pixm || pixGetDepth(pixm) != 1)
1103 return (
PIX *)ERROR_PTR(
"pixm undefined or not 1 bpp", procName, NULL);
1112 cmap = pixGetColormap(pixd);
1153 l_int32 w1, h1, w2, h2, w, h;
1155 PROCNAME(
"pixCropToMatch");
1157 if (!ppixd1 || !ppixd2)
1158 return ERROR_INT(
"&pixd1 and &pixd2 not both defined", procName, 1);
1159 *ppixd1 = *ppixd2 = NULL;
1160 if (!pixs1 || !pixs2)
1161 return ERROR_INT(
"pixs1 and pixs2 not defined", procName, 1);
1170 if (*ppixd1 == NULL || *ppixd2 == NULL)
1171 return ERROR_INT(
"cropped image failure", procName, 1);
1195 l_int32 ws, hs, wd, hd, d;
1198 PROCNAME(
"pixCropToSize");
1201 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1204 if (ws <= w && hs <= h)
1209 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
1210 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1211 pixCopyResolution(pixd, pixs);
1213 pixCopyText(pixd, pixs);
1214 pixCopyInputFormat(pixd, pixs);
1250 l_int32 i, j, ws, hs, d;
1253 PROCNAME(
"pixResizeToMatch");
1256 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1257 if (!pixt && (w <= 0 || h <= 0))
1258 return (
PIX *)ERROR_PTR(
"both w and h not > 0", procName, NULL);
1263 if (ws == w && hs == h)
1266 if ((pixd =
pixCreate(w, h, d)) == NULL)
1267 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1268 pixCopyResolution(pixd, pixs);
1270 pixCopyText(pixd, pixs);
1271 pixCopyInputFormat(pixd, pixs);
1273 if (ws >= w && hs >= h)
1278 for (j = ws; j < w; j++)
1282 for (i = hs; i < h; i++)
1333 l_int32 h1, h2, v1, v2;
1336 PROCNAME(
"pixMakeFrameMask");
1338 if (w <= 0 || h <= 0)
1339 return (
PIX *)ERROR_PTR(
"mask size 0", procName, NULL);
1340 if (hf1 < 0.0 || hf1 > 1.0 || hf2 < 0.0 || hf2 > 1.0)
1341 return (
PIX *)ERROR_PTR(
"invalid horiz fractions", procName, NULL);
1342 if (vf1 < 0.0 || vf1 > 1.0 || vf2 < 0.0 || vf2 > 1.0)
1343 return (
PIX *)ERROR_PTR(
"invalid vert fractions", procName, NULL);
1344 if (hf1 > hf2 || vf1 > vf2)
1345 return (
PIX *)ERROR_PTR(
"invalid relative sizes", procName, NULL);
1350 if (hf1 == 0.0 && vf1 == 0.0 && hf2 == 1.0 && vf2 == 1.0) {
1354 if (hf1 == hf2 && vf1 == vf2) {
1364 if (hf2 < 1.0 && vf2 < 1.0)
1403 l_int32 w1, h1, w2, h2, empty, count1, count3;
1406 PROCNAME(
"pixFractionFgInMask");
1409 return ERROR_INT(
"&fract not defined", procName, 1);
1411 if (!pix1 || pixGetDepth(pix1) != 1)
1412 return ERROR_INT(
"pix1 not defined or not 1 bpp", procName, 1);
1413 if (!pix2 || pixGetDepth(pix2) != 1)
1414 return ERROR_INT(
"pix2 not defined or not 1 bpp", procName, 1);
1418 if (w1 != w2 || h1 != h2) {
1419 L_INFO(
"sizes unequal: (w1,w2) = (%d,%d), (h1,h2) = (%d,%d)\n",
1420 procName, w1, w2, h1, h2);
1423 if (empty)
return 0;
1425 if (empty)
return 0;
1428 pixAnd(pix3, pix3, pix2);
1431 *pfract = (l_float32)count3 / (l_float32)count1;
1459 l_int32 w, h, wpl, nfullwords, extra, i, j;
1460 l_int32 minx, miny, maxx, maxy;
1461 l_uint32 result, mask;
1462 l_uint32 *data, *line;
1465 PROCNAME(
"pixClipToForeground");
1467 if (ppixd) *ppixd = NULL;
1468 if (pbox) *pbox = NULL;
1469 if (!ppixd && !pbox)
1470 return ERROR_INT(
"no output requested", procName, 1);
1471 if (!pixs || (pixGetDepth(pixs) != 1))
1472 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1475 nfullwords = w / 32;
1477 mask = ~rmask32[32 - extra];
1478 wpl = pixGetWpl(pixs);
1482 for (i = 0, miny = 0; i < h; i++, miny++) {
1483 line = data + i * wpl;
1484 for (j = 0; j < nfullwords; j++)
1487 result |= (line[j] & mask);
1495 for (i = h - 1, maxy = h - 1; i >= 0; i--, maxy--) {
1496 line = data + i * wpl;
1497 for (j = 0; j < nfullwords; j++)
1500 result |= (line[j] & mask);
1506 for (j = 0, minx = 0; j < w; j++, minx++) {
1507 for (i = 0; i < h; i++) {
1508 line = data + i * wpl;
1515 for (j = w - 1, maxx = w - 1; j >= 0; j--, maxx--) {
1516 for (i = 0; i < h; i++) {
1517 line = data + i * wpl;
1524 box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1);
1558 l_int32 i, j, w, h, wpl, found;
1559 l_uint32 *data, *line;
1561 PROCNAME(
"pixTestClipToForeground");
1564 return ERROR_INT(
"&canclip not defined", procName, 1);
1566 if (!pixs || (pixGetDepth(pixs) != 1))
1567 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1572 wpl = pixGetWpl(pixs);
1574 for (j = 0; found == FALSE && j < w; j++)
1581 line = data + (h - 1) * wpl;
1583 for (j = 0; found == FALSE && j < w; j++)
1592 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1600 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1632 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
1635 PROCNAME(
"pixClipBoxToForeground");
1637 if (ppixd) *ppixd = NULL;
1638 if (pboxd) *pboxd = NULL;
1639 if (!ppixd && !pboxd)
1640 return ERROR_INT(
"no output requested", procName, 1);
1641 if (!pixs || (pixGetDepth(pixs) != 1))
1642 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1649 cbw = L_MIN(bw, w - bx);
1650 cbh = L_MIN(bh, h - by);
1651 if (cbw < 0 || cbh < 0)
1652 return ERROR_INT(
"box not within image", procName, 1);
1663 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
1698 l_int32 bx, by, bw, bh, x, xstart, xend, y, ystart, yend, wpl;
1699 l_uint32 *data, *line;
1702 PROCNAME(
"pixScanForForeground");
1705 return ERROR_INT(
"&loc not defined", procName, 1);
1707 if (!pixs || (pixGetDepth(pixs) != 1))
1708 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1714 return ERROR_INT(
"invalid box", procName, 1);
1726 wpl = pixGetWpl(pixs);
1728 for (x = xstart; x <= xend; x++) {
1729 for (y = ystart; y <= yend; y++) {
1730 line = data + y * wpl;
1738 for (x = xend; x >= xstart; x--) {
1739 for (y = ystart; y <= yend; y++) {
1740 line = data + y * wpl;
1748 for (y = ystart; y <= yend; y++) {
1749 line = data + y * wpl;
1750 for (x = xstart; x <= xend; x++) {
1758 for (y = yend; y >= ystart; y--) {
1759 line = data + y * wpl;
1760 for (x = xstart; x <= xend; x++) {
1768 return ERROR_INT(
"invalid scanflag", procName, 1);
1818 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
1819 l_int32 lfound, rfound, tfound, bfound, change;
1822 PROCNAME(
"pixClipBoxToEdges");
1824 if (ppixd) *ppixd = NULL;
1825 if (pboxd) *pboxd = NULL;
1826 if (!ppixd && !pboxd)
1827 return ERROR_INT(
"no output requested", procName, 1);
1828 if (!pixs || (pixGetDepth(pixs) != 1))
1829 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1830 if (lowthresh < 1 || highthresh < 1 ||
1831 lowthresh > highthresh || maxwidth < 1)
1832 return ERROR_INT(
"invalid thresholds", procName, 1);
1833 factor = L_MIN(1, factor);
1835 if (lowthresh == 1 && highthresh == 1)
1841 cbw = L_MIN(bw, w - bx);
1842 cbh = L_MIN(bh, h - by);
1843 if (cbw < 0 || cbh < 0)
1844 return ERROR_INT(
"box not within image", procName, 1);
1850 lfound = rfound = tfound = bfound = 0;
1851 while (!lfound || !rfound || !tfound || !bfound) {
1887 fprintf(stderr,
"iter: %d %d %d %d\n", lfound, rfound, tfound, bfound);
1890 if (change == 0)
break;
1895 return ERROR_INT(
"not all edges found", procName, 1);
1897 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
1948 l_int32 bx, by, bw, bh, foundmin, loc, sum, wpl;
1949 l_int32 x, xstart, xend, y, ystart, yend;
1950 l_uint32 *data, *line;
1953 PROCNAME(
"pixScanForEdge");
1956 return ERROR_INT(
"&ploc not defined", procName, 1);
1958 if (!pixs || (pixGetDepth(pixs) != 1))
1959 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1960 if (lowthresh < 1 || highthresh < 1 ||
1961 lowthresh > highthresh || maxwidth < 1)
1962 return ERROR_INT(
"invalid thresholds", procName, 1);
1963 factor = L_MIN(1, factor);
1969 return ERROR_INT(
"invalid box", procName, 1);
1981 wpl = pixGetWpl(pixs);
1984 for (x = xstart; x <= xend; x++) {
1986 for (y = ystart; y <= yend; y += factor) {
1987 line = data + y * wpl;
1991 if (!foundmin && sum < lowthresh)
1997 if (sum >= highthresh) {
1999 fprintf(stderr,
"Left: x = %d, loc = %d\n", x, loc);
2001 if (x - loc < maxwidth) {
2010 for (x = xend; x >= xstart; x--) {
2012 for (y = ystart; y <= yend; y += factor) {
2013 line = data + y * wpl;
2017 if (!foundmin && sum < lowthresh)
2023 if (sum >= highthresh) {
2025 fprintf(stderr,
"Right: x = %d, loc = %d\n", x, loc);
2027 if (loc - x < maxwidth) {
2036 for (y = ystart; y <= yend; y++) {
2038 line = data + y * wpl;
2039 for (x = xstart; x <= xend; x += factor) {
2043 if (!foundmin && sum < lowthresh)
2049 if (sum >= highthresh) {
2051 fprintf(stderr,
"Top: y = %d, loc = %d\n", y, loc);
2053 if (y - loc < maxwidth) {
2062 for (y = yend; y >= ystart; y--) {
2064 line = data + y * wpl;
2065 for (x = xstart; x <= xend; x += factor) {
2069 if (!foundmin && sum < lowthresh)
2075 if (sum >= highthresh) {
2077 fprintf(stderr,
"Bottom: y = %d, loc = %d\n", y, loc);
2079 if (loc - y < maxwidth) {
2088 return ERROR_INT(
"invalid scanflag", procName, 1);
2127 l_int32 i, w, h, d, xmin, ymin, xmax, ymax, npts, direction;
2134 PROCNAME(
"pixExtractOnLine");
2137 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2139 if (d != 1 && d != 8)
2140 return (
NUMA *)ERROR_PTR(
"d not 1 or 8 bpp", procName, NULL);
2141 if (pixGetColormap(pixs))
2142 return (
NUMA *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
2144 L_WARNING(
"factor must be >= 1; setting to 1\n", procName);
2149 x1 = L_MAX(0, L_MIN(x1, w - 1));
2150 x2 = L_MAX(0, L_MIN(x2, w - 1));
2151 y1 = L_MAX(0, L_MIN(y1, h - 1));
2152 y2 = L_MAX(0, L_MIN(y2, h - 1));
2154 if (x1 == x2 && y1 == y2) {
2170 xmin = L_MIN(x1, x2);
2171 xmax = L_MAX(x1, x2);
2173 for (i = xmin; i <= xmax; i += factor) {
2178 ymin = L_MIN(y1, y2);
2179 ymax = L_MAX(y1, y2);
2181 for (i = ymin; i <= ymax; i += factor) {
2186 slope = (l_float64)((y2 - y1) / (x2 - x1));
2187 if (L_ABS(slope) < 1.0) {
2188 xmin = L_MIN(x1, x2);
2189 xmax = L_MAX(x1, x2);
2190 ymin = (xmin == x1) ? y1 : y2;
2191 ymax = (ymin == y1) ? y2 : y1;
2195 ymin = L_MIN(y1, y2);
2196 ymax = L_MAX(y1, y2);
2197 xmin = (ymin == y1) ? x1 : x2;
2198 xmax = (xmin == x1) ? x2 : x1;
2203 for (i = 0; i < npts; i += factor) {
2247 l_int32 i, j, w, h, d, direction, count, wpl;
2248 l_uint32 *data, *line;
2251 PROCNAME(
"pixAverageOnLine");
2254 return ERROR_INT(
"pixs not defined", procName, 1);
2256 if (d != 1 && d != 8)
2257 return ERROR_INT(
"d not 1 or 8 bpp", procName, 1);
2258 if (pixGetColormap(pixs))
2259 return ERROR_INT(
"pixs has a colormap", procName, 1);
2260 if (x1 > x2 || y1 > y2)
2261 return ERROR_INT(
"x1 > x2 or y1 > y2", procName, 1);
2265 x2 = L_MIN(w - 1, x2);
2266 y1 = L_MAX(0, L_MIN(y1, h - 1));
2268 }
else if (x1 == x2) {
2270 y2 = L_MIN(h - 1, y2);
2271 x1 = L_MAX(0, L_MIN(x1, w - 1));
2274 return ERROR_INT(
"line neither horiz nor vert", procName, 1);
2278 L_WARNING(
"factor must be >= 1; setting to 1\n", procName);
2283 wpl = pixGetWpl(pixs);
2287 line = data + y1 * wpl;
2288 for (j = x1, count = 0; j <= x2; count++, j += factor) {
2295 for (i = y1, count = 0; i <= y2; count++, i += factor) {
2296 line = data + i * wpl;
2304 return sum / (l_float32)count;
2346 l_int32 i, j, w, h, d, start, end;
2351 PROCNAME(
"pixAverageIntensityProfile");
2354 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2355 if (fract < 0.0 || fract > 1.0)
2356 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", procName, NULL);
2358 return (
NUMA *)ERROR_PTR(
"invalid direction", procName, NULL);
2359 if (first < 0) first = 0;
2361 return (
NUMA *)ERROR_PTR(
"last must be >= first", procName, NULL);
2363 L_WARNING(
"factor1 must be >= 1; setting to 1\n", procName);
2367 L_WARNING(
"factor2 must be >= 1; setting to 1\n", procName);
2372 if (pixGetColormap(pixs))
2385 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2388 L_WARNING(
"last > h - 1; clipping\n", procName);
2391 for (i = first; i <= last; i += factor2) {
2396 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2399 L_WARNING(
"last > w - 1; clipping\n", procName);
2402 for (j = first; j <= last; j += factor2) {
2457 l_int32 minreversal,
2461 l_int32 i, j, w, h, d, start, end, nr;
2465 PROCNAME(
"pixReversalProfile");
2468 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2469 if (fract < 0.0 || fract > 1.0)
2470 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", procName, NULL);
2472 return (
NUMA *)ERROR_PTR(
"invalid direction", procName, NULL);
2473 if (first < 0) first = 0;
2475 return (
NUMA *)ERROR_PTR(
"last must be >= first", procName, NULL);
2477 L_WARNING(
"factor1 must be >= 1; setting to 1\n", procName);
2481 L_WARNING(
"factor2 must be >= 1; setting to 1\n", procName);
2486 if (pixGetColormap(pixs))
2501 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2504 L_WARNING(
"last > h - 1; clipping\n", procName);
2507 for (i = first; i <= last; i += factor2) {
2514 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2517 L_WARNING(
"last > w - 1; clipping\n", procName);
2520 for (j = first; j <= last; j += factor2) {
2569 l_int32 i, j, w, h, cmin, cmax, maxloc, n, x, y;
2571 l_float32 norm, rootvar;
2573 l_float64 sum1, sum2, ave, var;
2577 PROCNAME(
"pixWindowedVarianceOnLine");
2580 return ERROR_INT(
"&nad not defined", procName, 1);
2582 if (!pixs || pixGetDepth(pixs) != 8)
2583 return ERROR_INT(
"pixs not defined or not 8bpp", procName, 1);
2585 return ERROR_INT(
"window size must be > 1", procName, 1);
2587 return ERROR_INT(
"invalid direction", procName, 1);
2590 if (loc < 0 || loc > maxloc)
2591 return ERROR_INT(
"invalid line position", procName, 1);
2594 cmin = L_MIN(c1, c2);
2595 cmax = L_MAX(c1, c2);
2597 cmin = L_MAX(0, L_MIN(cmin, maxloc));
2598 cmax = L_MAX(0, L_MIN(cmax, maxloc));
2599 n = cmax - cmin + 1;
2604 for (i = cmin; i <= cmax; i++)
2607 for (i = cmin; i <= cmax; i++)
2614 for (i = 0; i < n; i++) {
2626 norm = 1.0 / (l_float32)size;
2627 for (i = 0; i < n - size; i++) {
2629 for (j = 0; j < size; j++) {
2632 sum2 += (l_float64)(val) * val;
2635 var = norm * sum2 - ave * ave;
2636 rootvar = (l_float32)sqrt(var);
2691 l_int32 i, j, w, h, d, x, y, n, dir, found, minval, maxval, negloc, posloc;
2694 NUMA *namin, *namax;
2697 PROCNAME(
"pixMinMaxNearLine");
2699 if (pnamin) *pnamin = NULL;
2700 if (pnamax) *pnamax = NULL;
2701 if (pminave) *pminave = UNDEF;
2702 if (pmaxave) *pmaxave = UNDEF;
2703 if (!pnamin && !pnamax && !pminave && !pmaxave)
2704 return ERROR_INT(
"no output requested", procName, 1);
2706 return ERROR_INT(
"pixs not defined", procName, 1);
2708 if (d != 8 || pixGetColormap(pixs))
2709 return ERROR_INT(
"pixs not 8 bpp or has colormap", procName, 1);
2713 return ERROR_INT(
"invalid direction", procName, 1);
2717 dir = (L_ABS(x1 - x2) == n - 1) ? L_HORIZ : L_VERT;
2726 for (i = 0; i < n; i++) {
2731 if (dir == L_HORIZ) {
2732 if (x < 0 || x >= w)
continue;
2733 for (j = negloc; j <= posloc; j++) {
2734 if (y + j < 0 || y + j >= h)
continue;
2737 if (val < minval) minval = val;
2738 if (val > maxval) maxval = val;
2741 if (y < 0 || y >= h)
continue;
2742 for (j = negloc; j <= posloc; j++) {
2743 if (x + j < 0 || x + j >= w)
continue;
2746 if (val < minval) minval = val;
2747 if (val > maxval) maxval = val;
2761 return ERROR_INT(
"no output from this line", procName, 1);
2804 l_int32 i, j, k, m, w, h, wpl, val;
2806 l_uint32 *datas, *datad, *lines, *lined;
2809 PROCNAME(
"pixRankRowTransform");
2812 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
2813 if (pixGetDepth(pixs) != 8)
2814 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
2815 if (pixGetColormap(pixs))
2816 return (
PIX *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
2822 wpl = pixGetWpl(pixs);
2823 for (i = 0; i < h; i++) {
2824 memset(histo, 0, 1024);
2825 lines = datas + i * wpl;
2826 lined = datad + i * wpl;
2827 for (j = 0; j < w; j++) {
2831 for (m = 0, j = 0; m < 256; m++) {
2832 for (k = 0; k < histo[m]; k++, j++)
2857 l_int32 i, j, k, m, w, h, val;
2859 void **lines8, **lined8;
2862 PROCNAME(
"pixRankColumnTransform");
2865 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
2866 if (pixGetDepth(pixs) != 8)
2867 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
2868 if (pixGetColormap(pixs))
2869 return (
PIX *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
2875 for (j = 0; j < w; j++) {
2876 memset(histo, 0, 1024);
2877 for (i = 0; i < h; i++) {
2881 for (m = 0, i = 0; m < 256; m++) {
2882 for (k = 0; k < histo[m]; k++, i++)
l_int32 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()
l_int32 pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
l_int32 pixcmapGetNearestIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetNearestIndex()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_int32 pixaIsFull(PIXA *pixa, l_int32 *pfullpa, l_int32 *pfullba)
pixaIsFull()
l_int32 numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * pixaFindAreaFraction(PIXA *pixa)
pixaFindAreaFraction()
NUMA * pixExtractOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor)
pixExtractOnLine()
l_int32 pixWindowedVarianceOnLine(PIX *pixs, l_int32 dir, l_int32 loc, l_int32 c1, l_int32 c2, l_int32 size, NUMA **pnad)
pixWindowedVarianceOnLine()
BOXA * pixFindRectangleComps(PIX *pixs, l_int32 dist, l_int32 minw, l_int32 minh)
pixFindRectangleComps()
l_int32 ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_int32 pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 pixZero(PIX *pix, l_int32 *pempty)
pixZero()
l_int32 pixScanForForeground(PIX *pixs, BOX *box, l_int32 scanflag, l_int32 *ploc)
pixScanForForeground()
PIX * pixExtractBorderConnComps(PIX *pixs, l_int32 connectivity)
pixExtractBorderConnComps()
PTA * ptaCreate(l_int32 n)
ptaCreate()
PIX * pixMakeFrameMask(l_int32 w, l_int32 h, l_float32 hf1, l_float32 hf2, l_float32 vf1, l_float32 vf2)
pixMakeFrameMask()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
l_int32 boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
NUMA * pixaFindAreaFractionMasked(PIXA *pixa, PIX *pixm, l_int32 debug)
pixaFindAreaFractionMasked()
l_float32 pixAverageOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor)
pixAverageOnLine()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_int32 pixSetOrClearBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
pixSetOrClearBorder()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
NUMA * pixaFindWidthHeightRatio(PIXA *pixa)
pixaFindWidthHeightRatio()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
BOX * pixaGetBox(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetBox()
l_int32 numaGetSum(NUMA *na, l_float32 *psum)
numaGetSum()
NUMA * pixaFindPerimSizeRatio(PIXA *pixa)
pixaFindPerimSizeRatio()
l_int32 pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
PIX * pixaDisplay(PIXA *pixa, l_int32 w, l_int32 h)
pixaDisplay()
#define GET_DATA_BIT(pdata, n)
l_int32 pixClipBoxToForeground(PIX *pixs, BOX *boxs, PIX **ppixd, BOX **pboxd)
pixClipBoxToForeground()
PIX * pixCreateTemplate(PIX *pixs)
pixCreateTemplate()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
NUMA * pixaFindPerimToAreaRatio(PIXA *pixa)
pixaFindPerimToAreaRatio()
PIX * pixClipMasked(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_uint32 outval)
pixClipMasked()
l_int32 pixaFindDimensions(PIXA *pixa, NUMA **pnaw, NUMA **pnah)
pixaFindDimensions()
NUMA * pixaFindWidthHeightProduct(PIXA *pixa)
pixaFindWidthHeightProduct()
l_int32 pixFindAreaPerimRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaPerimRatio()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
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()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
static const l_int32 L_INSERT
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
PTA * generatePtaLine(l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2)
generatePtaLine()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_int32 pixFindOverlapFraction(PIX *pixs1, PIX *pixs2, l_int32 x2, l_int32 y2, l_int32 *tab, l_float32 *pratio, l_int32 *pnoverlap)
pixFindOverlapFraction()
l_int32 pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIX * pixAnd(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixAnd()
PIX * pixCropToSize(PIX *pixs, l_int32 w, l_int32 h)
pixCropToSize()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
#define SET_DATA_BYTE(pdata, n, val)
PIXA * pixClipRectangles(PIX *pixs, BOXA *boxa)
pixClipRectangles()
l_int32 pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
NUMA * pixAverageIntensityProfile(PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 factor1, l_int32 factor2)
pixAverageIntensityProfile()
l_int32 boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
#define GET_DATA_BYTE(pdata, n)
l_int32 pixFindPerimSizeRatio(PIX *pixs, l_int32 *tab, l_float32 *pratio)
pixFindPerimSizeRatio()
PIX * pixClone(PIX *pixs)
pixClone()
void pixDestroy(PIX **ppix)
pixDestroy()
l_int32 pixFindAreaFractionMasked(PIX *pixs, BOX *box, PIX *pixm, l_int32 *tab, l_float32 *pfract)
pixFindAreaFractionMasked()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
l_int32 pixPlotAlongPta(PIX *pixs, PTA *pta, l_int32 outformat, const char *title)
pixPlotAlongPta()
l_int32 numaSetParameters(NUMA *na, l_float32 startx, l_float32 delx)
numaSetParameters()
PIX * pixRankColumnTransform(PIX *pixs)
pixRankColumnTransform()
l_int32 pixPaintThroughMask(PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
pixPaintThroughMask()
void numaDestroy(NUMA **pna)
numaDestroy()
BOX * boxRelocateOneSide(BOX *boxd, BOX *boxs, l_int32 loc, l_int32 sideflag)
boxRelocateOneSide()
l_int32 ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_int32 pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_int32 pixFindPerimToAreaRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindPerimToAreaRatio()
l_int32 pixClipBoxToEdges(PIX *pixs, BOX *boxs, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, PIX **ppixd, BOX **pboxd)
pixClipBoxToEdges()
l_float32 * numaGetFArray(NUMA *na, l_int32 copyflag)
numaGetFArray()
l_int32 pixFractionFgInMask(PIX *pix1, PIX *pix2, l_float32 *pfract)
pixFractionFgInMask()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
l_int32 composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_int32 pixClipToForeground(PIX *pixs, PIX **ppixd, BOX **pbox)
pixClipToForeground()
l_int32 pixCropToMatch(PIX *pixs1, PIX *pixs2, PIX **ppixd1, PIX **ppixd2)
pixCropToMatch()
l_int32 pixScanForEdge(PIX *pixs, BOX *box, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, l_int32 scanflag, l_int32 *ploc)
pixScanForEdge()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_int32 pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
l_int32 numaCountReversals(NUMA *nas, l_float32 minreversal, l_int32 *pnr, l_float32 *pnrpl)
numaCountReversals()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
void boxDestroy(BOX **pbox)
boxDestroy()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_int32 pixSetAll(PIX *pix)
pixSetAll()
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()
l_int32 pixGetDimensions(PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
l_int32 pixFindAreaFraction(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaFraction()
l_int32 pixConformsToRectangle(PIX *pixs, BOX *box, l_int32 dist, l_int32 *pconforms)
pixConformsToRectangle()
PIX * pixRankRowTransform(PIX *pixs)
pixRankRowTransform()
PIX * pixErodeBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeBrick()
l_int32 pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
l_int32 pixTestClipToForeground(PIX *pixs, l_int32 *pcanclip)
pixTestClipToForeground()
l_int32 pixSetMaskedCmap(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetMaskedCmap()