105 #include "allheaders.h" 107 static const l_uint32 rmask32[] = {0x0,
108 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
109 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
110 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
111 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
112 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
113 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
114 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
115 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
117 #ifndef NO_CONSOLE_IO 118 #define DEBUG_EDGES 0 141 PROCNAME(
"pixaFindDimensions");
143 if (pnaw) *pnaw = NULL;
144 if (pnah) *pnah = NULL;
146 return ERROR_INT(
"no output requested", procName, 1);
148 return ERROR_INT(
"pixa not defined", procName, 1);
153 for (i = 0; i < n; i++) {
192 PROCNAME(
"pixFindAreaPerimRatio");
195 return ERROR_INT(
"&fract not defined", procName, 1);
197 if (!pixs || pixGetDepth(pixs) != 1)
198 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
209 if (!tab) LEPT_FREE(tab8);
214 *pfract = (l_float32)nfg / (l_float32)nbound;
217 if (!tab) LEPT_FREE(tab8);
243 PROCNAME(
"pixaFindPerimToAreaRatio");
246 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
251 for (i = 0; i < n; i++) {
293 PROCNAME(
"pixFindPerimToAreaRatio");
296 return ERROR_INT(
"&fract not defined", procName, 1);
298 if (!pixs || pixGetDepth(pixs) != 1)
299 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
308 if (!tab) LEPT_FREE(tab8);
314 *pfract = (l_float32)nbound / (l_float32)nfg;
317 if (!tab) LEPT_FREE(tab8);
347 PROCNAME(
"pixaFindPerimSizeRatio");
350 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
355 for (i = 0; i < n; i++) {
394 l_int32 w, h, nbound;
397 PROCNAME(
"pixFindPerimSizeRatio");
400 return ERROR_INT(
"&ratio not defined", procName, 1);
402 if (!pixs || pixGetDepth(pixs) != 1)
403 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
414 *pratio = (0.5 * nbound) / (l_float32)(w + h);
417 if (!tab) LEPT_FREE(tab8);
443 PROCNAME(
"pixaFindAreaFraction");
446 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
451 for (i = 0; i < n; i++) {
485 PROCNAME(
"pixFindAreaFraction");
488 return ERROR_INT(
"&fract not defined", procName, 1);
490 if (!pixs || pixGetDepth(pixs) != 1)
491 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
499 *pfract = (l_float32)sum / (l_float32)(w * h);
501 if (!tab) LEPT_FREE(tab8);
537 PROCNAME(
"pixaFindAreaFractionMasked");
540 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
541 if (!pixm || pixGetDepth(pixm) != 1)
542 return (
NUMA *)ERROR_PTR(
"pixm undefined or not 1 bpp", procName, NULL);
549 for (i = 0; i < n; i++) {
571 pixDisplay(pix2, 100, 100);
611 l_int32 x, y, w, h, sum, masksum;
615 PROCNAME(
"pixFindAreaFractionMasked");
618 return ERROR_INT(
"&fract not defined", procName, 1);
620 if (!pixs || pixGetDepth(pixs) != 1)
621 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
622 if (!pixm || pixGetDepth(pixm) != 1)
623 return ERROR_INT(
"pixm not defined or not 1 bpp", procName, 1);
639 if (!tab) LEPT_FREE(tab8);
643 *pfract = (l_float32)masksum / (l_float32)sum;
645 if (!tab) LEPT_FREE(tab8);
670 PROCNAME(
"pixaFindWidthHeightRatio");
673 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
677 for (i = 0; i < n; i++) {
706 PROCNAME(
"pixaFindWidthHeightProduct");
709 return (
NUMA *)ERROR_PTR(
"pixa not defined", procName, NULL);
713 for (i = 0; i < n; i++) {
749 l_int32 w, h, nintersect, nunion;
752 PROCNAME(
"pixFindOverlapFraction");
754 if (pnoverlap) *pnoverlap = 0;
756 return ERROR_INT(
"&ratio not defined", procName, 1);
758 if (!pixs1 || pixGetDepth(pixs1) != 1)
759 return ERROR_INT(
"pixs1 not defined or not 1 bpp", procName, 1);
760 if (!pixs2 || pixGetDepth(pixs2) != 1)
761 return ERROR_INT(
"pixs2 not defined or not 1 bpp", procName, 1);
773 *pnoverlap = nintersect;
777 if (!tab) LEPT_FREE(tab8);
781 *pratio = (l_float32)nintersect / (l_float32)nunion;
812 l_int32 w, h, i, n, conforms;
818 PROCNAME(
"pixFindRectangleComps");
820 if (!pixs || pixGetDepth(pixs) != 1)
821 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
823 return (
BOXA *)ERROR_PTR(
"dist must be >= 0", procName, NULL);
824 if (minw <= 2 * dist && minh <= 2 * dist)
825 return (
BOXA *)ERROR_PTR(
"invalid parameters", procName, NULL);
830 for (i = 0; i < n; i++) {
833 if (w < minw || h < minh) {
895 PROCNAME(
"pixConformsToRectangle");
898 return ERROR_INT(
"&conforms not defined", procName, 1);
900 if (!pixs || pixGetDepth(pixs) != 1)
901 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
903 return ERROR_INT(
"dist must be >= 0", procName, 1);
905 if (w <= 2 * dist || h <= 2 * dist) {
906 L_WARNING(
"automatic conformation: distance too large\n", procName);
932 *pconforms = (empty) ? 1 : 0;
962 PROCNAME(
"pixClipRectangles");
965 return (
PIXA *)ERROR_PTR(
"pixs not defined", procName, NULL);
967 return (
PIXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
971 for (i = 0; i < n; i++) {
1024 l_int32 w, h, d, bx, by, bw, bh;
1028 PROCNAME(
"pixClipRectangle");
1030 if (pboxc) *pboxc = NULL;
1032 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1034 return (
PIX *)ERROR_PTR(
"box not defined", procName, NULL);
1039 L_WARNING(
"box doesn't overlap pix\n", procName);
1045 if ((pixd =
pixCreate(bw, bh, d)) == NULL) {
1047 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1049 pixCopyResolution(pixd, pixs);
1051 pixCopyText(pixd, pixs);
1099 l_int32 wm, hm, index, rval, gval, bval;
1105 PROCNAME(
"pixClipMasked");
1108 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1109 if (!pixm || pixGetDepth(pixm) != 1)
1110 return (
PIX *)ERROR_PTR(
"pixm undefined or not 1 bpp", procName, NULL);
1119 cmap = pixGetColormap(pixd);
1160 l_int32 w1, h1, w2, h2, w, h;
1162 PROCNAME(
"pixCropToMatch");
1164 if (!ppixd1 || !ppixd2)
1165 return ERROR_INT(
"&pixd1 and &pixd2 not both defined", procName, 1);
1166 *ppixd1 = *ppixd2 = NULL;
1167 if (!pixs1 || !pixs2)
1168 return ERROR_INT(
"pixs1 and pixs2 not defined", procName, 1);
1177 if (*ppixd1 == NULL || *ppixd2 == NULL)
1178 return ERROR_INT(
"cropped image failure", procName, 1);
1202 l_int32 ws, hs, wd, hd, d;
1205 PROCNAME(
"pixCropToSize");
1208 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1211 if (ws <= w && hs <= h)
1216 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
1217 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1218 pixCopyResolution(pixd, pixs);
1220 pixCopyText(pixd, pixs);
1221 pixCopyInputFormat(pixd, pixs);
1257 l_int32 i, j, ws, hs, d;
1260 PROCNAME(
"pixResizeToMatch");
1263 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1264 if (!pixt && (w <= 0 || h <= 0))
1265 return (
PIX *)ERROR_PTR(
"both w and h not > 0", procName, NULL);
1270 if (ws == w && hs == h)
1273 if ((pixd =
pixCreate(w, h, d)) == NULL)
1274 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1275 pixCopyResolution(pixd, pixs);
1277 pixCopyText(pixd, pixs);
1278 pixCopyInputFormat(pixd, pixs);
1280 if (ws >= w && hs >= h)
1285 for (j = ws; j < w; j++)
1289 for (i = hs; i < h; i++)
1321 pixSelectComponentBySize(
PIX *pixs,
1324 l_int32 connectivity,
1327 l_int32 n, empty, sorttype, index;
1331 PIXA *pixa1, *pixa2;
1333 PROCNAME(
"pixSelectComponentBySize");
1335 if (pbox) *pbox = NULL;
1336 if (!pixs || pixGetDepth(pixs) != 1)
1337 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
1349 return (
PIX *)ERROR_PTR(
"invalid selection type", procName, NULL);
1350 if (connectivity != 4 && connectivity != 8)
1351 return (
PIX *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
1354 return (
PIX *)ERROR_PTR(
"no foreground pixels", procName, NULL);
1358 if (rankorder < 0 || rankorder >= n)
1394 pixFilterComponentBySize(
PIX *pixs,
1397 l_int32 connectivity,
1404 PROCNAME(
"pixFilterComponentBySize");
1406 if (!pixs || pixGetDepth(pixs) != 1)
1407 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
1409 pix1 = pixSelectComponentBySize(pixs, rankorder, type, connectivity, &box);
1412 return (
PIX *)ERROR_PTR(
"pix1 not made", procName, NULL);
1472 l_int32 h1, h2, v1, v2;
1475 PROCNAME(
"pixMakeFrameMask");
1477 if (w <= 0 || h <= 0)
1478 return (
PIX *)ERROR_PTR(
"mask size 0", procName, NULL);
1479 if (hf1 < 0.0 || hf1 > 1.0 || hf2 < 0.0 || hf2 > 1.0)
1480 return (
PIX *)ERROR_PTR(
"invalid horiz fractions", procName, NULL);
1481 if (vf1 < 0.0 || vf1 > 1.0 || vf2 < 0.0 || vf2 > 1.0)
1482 return (
PIX *)ERROR_PTR(
"invalid vert fractions", procName, NULL);
1483 if (hf1 > hf2 || vf1 > vf2)
1484 return (
PIX *)ERROR_PTR(
"invalid relative sizes", procName, NULL);
1489 if (hf1 == 0.0 && vf1 == 0.0 && hf2 == 1.0 && vf2 == 1.0) {
1493 if (hf1 == hf2 && vf1 == vf2) {
1503 if (hf2 < 1.0 && vf2 < 1.0)
1534 l_int32 empty, same, niters;
1538 PROCNAME(
"pixMakeCoveringOfRectangles");
1540 if (!pixs || pixGetDepth(pixs) != 1)
1541 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
1543 return (
PIX *)ERROR_PTR(
"maxiters must be >= 0", procName, NULL);
1544 if (maxiters == 0) maxiters = 50;
1548 if (empty)
return pix1;
1554 if (maxiters == 1)
return pix1;
1557 while (niters < maxiters) {
1566 L_INFO(
"%d iterations\n", procName, niters - 1);
1570 L_INFO(
"maxiters = %d reached\n", procName, niters);
1608 l_int32 w1, h1, w2, h2, empty, count1, count3;
1611 PROCNAME(
"pixFractionFgInMask");
1614 return ERROR_INT(
"&fract not defined", procName, 1);
1616 if (!pix1 || pixGetDepth(pix1) != 1)
1617 return ERROR_INT(
"pix1 not defined or not 1 bpp", procName, 1);
1618 if (!pix2 || pixGetDepth(pix2) != 1)
1619 return ERROR_INT(
"pix2 not defined or not 1 bpp", procName, 1);
1623 if (w1 != w2 || h1 != h2) {
1624 L_INFO(
"sizes unequal: (w1,w2) = (%d,%d), (h1,h2) = (%d,%d)\n",
1625 procName, w1, w2, h1, h2);
1628 if (empty)
return 0;
1630 if (empty)
return 0;
1633 pixAnd(pix3, pix3, pix2);
1636 *pfract = (l_float32)count3 / (l_float32)count1;
1664 l_int32 w, h, wpl, nfullwords, extra, i, j;
1665 l_int32 minx, miny, maxx, maxy;
1666 l_uint32 result, mask;
1667 l_uint32 *data, *line;
1670 PROCNAME(
"pixClipToForeground");
1672 if (ppixd) *ppixd = NULL;
1673 if (pbox) *pbox = NULL;
1674 if (!ppixd && !pbox)
1675 return ERROR_INT(
"no output requested", procName, 1);
1676 if (!pixs || (pixGetDepth(pixs) != 1))
1677 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1680 nfullwords = w / 32;
1682 mask = ~rmask32[32 - extra];
1683 wpl = pixGetWpl(pixs);
1687 for (i = 0, miny = 0; i < h; i++, miny++) {
1688 line = data + i * wpl;
1689 for (j = 0; j < nfullwords; j++)
1692 result |= (line[j] & mask);
1700 for (i = h - 1, maxy = h - 1; i >= 0; i--, maxy--) {
1701 line = data + i * wpl;
1702 for (j = 0; j < nfullwords; j++)
1705 result |= (line[j] & mask);
1711 for (j = 0, minx = 0; j < w; j++, minx++) {
1712 for (i = 0; i < h; i++) {
1713 line = data + i * wpl;
1720 for (j = w - 1, maxx = w - 1; j >= 0; j--, maxx--) {
1721 for (i = 0; i < h; i++) {
1722 line = data + i * wpl;
1729 box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1);
1763 l_int32 i, j, w, h, wpl, found;
1764 l_uint32 *data, *line;
1766 PROCNAME(
"pixTestClipToForeground");
1769 return ERROR_INT(
"&canclip not defined", procName, 1);
1771 if (!pixs || (pixGetDepth(pixs) != 1))
1772 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1777 wpl = pixGetWpl(pixs);
1779 for (j = 0; found == FALSE && j < w; j++)
1786 line = data + (h - 1) * wpl;
1788 for (j = 0; found == FALSE && j < w; j++)
1797 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1805 for (i = 0, line = data; found == FALSE && i < h; line += wpl, i++)
1837 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
1840 PROCNAME(
"pixClipBoxToForeground");
1842 if (ppixd) *ppixd = NULL;
1843 if (pboxd) *pboxd = NULL;
1844 if (!ppixd && !pboxd)
1845 return ERROR_INT(
"no output requested", procName, 1);
1846 if (!pixs || (pixGetDepth(pixs) != 1))
1847 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1854 cbw = L_MIN(bw, w - bx);
1855 cbh = L_MIN(bh, h - by);
1856 if (cbw < 0 || cbh < 0)
1857 return ERROR_INT(
"box not within image", procName, 1);
1868 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
1903 l_int32 bx, by, bw, bh, x, xstart, xend, y, ystart, yend, wpl;
1904 l_uint32 *data, *line;
1907 PROCNAME(
"pixScanForForeground");
1910 return ERROR_INT(
"&loc not defined", procName, 1);
1912 if (!pixs || (pixGetDepth(pixs) != 1))
1913 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1919 return ERROR_INT(
"invalid box", procName, 1);
1931 wpl = pixGetWpl(pixs);
1933 for (x = xstart; x <= xend; x++) {
1934 for (y = ystart; y <= yend; y++) {
1935 line = data + y * wpl;
1943 for (x = xend; x >= xstart; x--) {
1944 for (y = ystart; y <= yend; y++) {
1945 line = data + y * wpl;
1953 for (y = ystart; y <= yend; y++) {
1954 line = data + y * wpl;
1955 for (x = xstart; x <= xend; x++) {
1963 for (y = yend; y >= ystart; y--) {
1964 line = data + y * wpl;
1965 for (x = xstart; x <= xend; x++) {
1973 return ERROR_INT(
"invalid scanflag", procName, 1);
2023 l_int32 w, h, bx, by, bw, bh, cbw, cbh, left, right, top, bottom;
2024 l_int32 lfound, rfound, tfound, bfound, change;
2027 PROCNAME(
"pixClipBoxToEdges");
2029 if (ppixd) *ppixd = NULL;
2030 if (pboxd) *pboxd = NULL;
2031 if (!ppixd && !pboxd)
2032 return ERROR_INT(
"no output requested", procName, 1);
2033 if (!pixs || (pixGetDepth(pixs) != 1))
2034 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
2035 if (lowthresh < 1 || highthresh < 1 ||
2036 lowthresh > highthresh || maxwidth < 1)
2037 return ERROR_INT(
"invalid thresholds", procName, 1);
2038 factor = L_MIN(1, factor);
2040 if (lowthresh == 1 && highthresh == 1)
2046 cbw = L_MIN(bw, w - bx);
2047 cbh = L_MIN(bh, h - by);
2048 if (cbw < 0 || cbh < 0)
2049 return ERROR_INT(
"box not within image", procName, 1);
2055 lfound = rfound = tfound = bfound = 0;
2056 while (!lfound || !rfound || !tfound || !bfound) {
2092 fprintf(stderr,
"iter: %d %d %d %d\n", lfound, rfound, tfound, bfound);
2095 if (change == 0)
break;
2100 return ERROR_INT(
"not all edges found", procName, 1);
2102 boxd =
boxCreate(left, top, right - left + 1, bottom - top + 1);
2153 l_int32 bx, by, bw, bh, foundmin, loc, sum, wpl;
2154 l_int32 x, xstart, xend, y, ystart, yend;
2155 l_uint32 *data, *line;
2158 PROCNAME(
"pixScanForEdge");
2161 return ERROR_INT(
"&ploc not defined", procName, 1);
2163 if (!pixs || (pixGetDepth(pixs) != 1))
2164 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
2165 if (lowthresh < 1 || highthresh < 1 ||
2166 lowthresh > highthresh || maxwidth < 1)
2167 return ERROR_INT(
"invalid thresholds", procName, 1);
2168 factor = L_MIN(1, factor);
2174 return ERROR_INT(
"invalid box", procName, 1);
2186 wpl = pixGetWpl(pixs);
2189 for (x = xstart; x <= xend; x++) {
2191 for (y = ystart; y <= yend; y += factor) {
2192 line = data + y * wpl;
2196 if (!foundmin && sum < lowthresh)
2202 if (sum >= highthresh) {
2204 fprintf(stderr,
"Left: x = %d, loc = %d\n", x, loc);
2206 if (x - loc < maxwidth) {
2215 for (x = xend; x >= xstart; x--) {
2217 for (y = ystart; y <= yend; y += factor) {
2218 line = data + y * wpl;
2222 if (!foundmin && sum < lowthresh)
2228 if (sum >= highthresh) {
2230 fprintf(stderr,
"Right: x = %d, loc = %d\n", x, loc);
2232 if (loc - x < maxwidth) {
2241 for (y = ystart; y <= yend; y++) {
2243 line = data + y * wpl;
2244 for (x = xstart; x <= xend; x += factor) {
2248 if (!foundmin && sum < lowthresh)
2254 if (sum >= highthresh) {
2256 fprintf(stderr,
"Top: y = %d, loc = %d\n", y, loc);
2258 if (y - loc < maxwidth) {
2267 for (y = yend; y >= ystart; y--) {
2269 line = data + y * wpl;
2270 for (x = xstart; x <= xend; x += factor) {
2274 if (!foundmin && sum < lowthresh)
2280 if (sum >= highthresh) {
2282 fprintf(stderr,
"Bottom: y = %d, loc = %d\n", y, loc);
2284 if (loc - y < maxwidth) {
2293 return ERROR_INT(
"invalid scanflag", procName, 1);
2332 l_int32 i, w, h, d, xmin, ymin, xmax, ymax, npts, direction;
2339 PROCNAME(
"pixExtractOnLine");
2342 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2344 if (d != 1 && d != 8)
2345 return (
NUMA *)ERROR_PTR(
"d not 1 or 8 bpp", procName, NULL);
2346 if (pixGetColormap(pixs))
2347 return (
NUMA *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
2349 L_WARNING(
"factor must be >= 1; setting to 1\n", procName);
2354 x1 = L_MAX(0, L_MIN(x1, w - 1));
2355 x2 = L_MAX(0, L_MIN(x2, w - 1));
2356 y1 = L_MAX(0, L_MIN(y1, h - 1));
2357 y2 = L_MAX(0, L_MIN(y2, h - 1));
2359 if (x1 == x2 && y1 == y2) {
2375 xmin = L_MIN(x1, x2);
2376 xmax = L_MAX(x1, x2);
2378 for (i = xmin; i <= xmax; i += factor) {
2383 ymin = L_MIN(y1, y2);
2384 ymax = L_MAX(y1, y2);
2386 for (i = ymin; i <= ymax; i += factor) {
2391 slope = (l_float64)((y2 - y1) / (x2 - x1));
2392 if (L_ABS(slope) < 1.0) {
2393 xmin = L_MIN(x1, x2);
2394 xmax = L_MAX(x1, x2);
2395 ymin = (xmin == x1) ? y1 : y2;
2396 ymax = (ymin == y1) ? y2 : y1;
2400 ymin = L_MIN(y1, y2);
2401 ymax = L_MAX(y1, y2);
2402 xmin = (ymin == y1) ? x1 : x2;
2403 xmax = (xmin == x1) ? x2 : x1;
2408 for (i = 0; i < npts; i += factor) {
2452 l_int32 i, j, w, h, d, direction, count, wpl;
2453 l_uint32 *data, *line;
2456 PROCNAME(
"pixAverageOnLine");
2459 return ERROR_INT(
"pixs not defined", procName, 1);
2461 if (d != 1 && d != 8)
2462 return ERROR_INT(
"d not 1 or 8 bpp", procName, 1);
2463 if (pixGetColormap(pixs))
2464 return ERROR_INT(
"pixs has a colormap", procName, 1);
2465 if (x1 > x2 || y1 > y2)
2466 return ERROR_INT(
"x1 > x2 or y1 > y2", procName, 1);
2470 x2 = L_MIN(w - 1, x2);
2471 y1 = L_MAX(0, L_MIN(y1, h - 1));
2473 }
else if (x1 == x2) {
2475 y2 = L_MIN(h - 1, y2);
2476 x1 = L_MAX(0, L_MIN(x1, w - 1));
2479 return ERROR_INT(
"line neither horiz nor vert", procName, 1);
2483 L_WARNING(
"factor must be >= 1; setting to 1\n", procName);
2488 wpl = pixGetWpl(pixs);
2492 line = data + y1 * wpl;
2493 for (j = x1, count = 0; j <= x2; count++, j += factor) {
2500 for (i = y1, count = 0; i <= y2; count++, i += factor) {
2501 line = data + i * wpl;
2509 return sum / (l_float32)count;
2552 l_int32 i, j, w, h, d, start, end;
2557 PROCNAME(
"pixAverageIntensityProfile");
2560 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2561 if (fract < 0.0 || fract > 1.0)
2562 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", procName, NULL);
2564 return (
NUMA *)ERROR_PTR(
"invalid direction", procName, NULL);
2565 if (first < 0) first = 0;
2567 return (
NUMA *)ERROR_PTR(
"last must be >= first", procName, NULL);
2569 L_WARNING(
"factor1 must be >= 1; setting to 1\n", procName);
2573 L_WARNING(
"factor2 must be >= 1; setting to 1\n", procName);
2578 if (pixGetColormap(pixs))
2591 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2594 L_WARNING(
"last > h - 1; clipping\n", procName);
2597 for (i = first; i <= last; i += factor2) {
2602 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2605 L_WARNING(
"last > w - 1; clipping\n", procName);
2608 for (j = first; j <= last; j += factor2) {
2664 l_int32 minreversal,
2668 l_int32 i, j, w, h, d, start, end, nr;
2672 PROCNAME(
"pixReversalProfile");
2675 return (
NUMA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2676 if (fract < 0.0 || fract > 1.0)
2677 return (
NUMA *)ERROR_PTR(
"fract < 0.0 or > 1.0", procName, NULL);
2679 return (
NUMA *)ERROR_PTR(
"invalid direction", procName, NULL);
2680 if (first < 0) first = 0;
2682 return (
NUMA *)ERROR_PTR(
"last must be >= first", procName, NULL);
2684 L_WARNING(
"factor1 must be >= 1; setting to 1\n", procName);
2688 L_WARNING(
"factor2 must be >= 1; setting to 1\n", procName);
2693 if (pixGetColormap(pixs))
2708 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)w);
2711 L_WARNING(
"last > h - 1; clipping\n", procName);
2714 for (i = first; i <= last; i += factor2) {
2721 start = (l_int32)(0.5 * (1.0 - fract) * (l_float32)h);
2724 L_WARNING(
"last > w - 1; clipping\n", procName);
2727 for (j = first; j <= last; j += factor2) {
2776 l_int32 i, j, w, h, cmin, cmax, maxloc, n, x, y;
2778 l_float32 norm, rootvar;
2780 l_float64 sum1, sum2, ave, var;
2784 PROCNAME(
"pixWindowedVarianceOnLine");
2787 return ERROR_INT(
"&nad not defined", procName, 1);
2789 if (!pixs || pixGetDepth(pixs) != 8)
2790 return ERROR_INT(
"pixs not defined or not 8bpp", procName, 1);
2792 return ERROR_INT(
"window size must be > 1", procName, 1);
2794 return ERROR_INT(
"invalid direction", procName, 1);
2797 if (loc < 0 || loc > maxloc)
2798 return ERROR_INT(
"invalid line position", procName, 1);
2801 cmin = L_MIN(c1, c2);
2802 cmax = L_MAX(c1, c2);
2804 cmin = L_MAX(0, L_MIN(cmin, maxloc));
2805 cmax = L_MAX(0, L_MIN(cmax, maxloc));
2806 n = cmax - cmin + 1;
2811 for (i = cmin; i <= cmax; i++)
2814 for (i = cmin; i <= cmax; i++)
2821 for (i = 0; i < n; i++) {
2833 norm = 1.0 / (l_float32)size;
2834 for (i = 0; i < n - size; i++) {
2836 for (j = 0; j < size; j++) {
2839 sum2 += (l_float64)(val) * val;
2842 var = norm * sum2 - ave * ave;
2843 rootvar = (l_float32)sqrt(var);
2898 l_int32 i, j, w, h, d, x, y, n, dir, found, minval, maxval, negloc, posloc;
2901 NUMA *namin, *namax;
2904 PROCNAME(
"pixMinMaxNearLine");
2906 if (pnamin) *pnamin = NULL;
2907 if (pnamax) *pnamax = NULL;
2908 if (pminave) *pminave = UNDEF;
2909 if (pmaxave) *pmaxave = UNDEF;
2910 if (!pnamin && !pnamax && !pminave && !pmaxave)
2911 return ERROR_INT(
"no output requested", procName, 1);
2913 return ERROR_INT(
"pixs not defined", procName, 1);
2915 if (d != 8 || pixGetColormap(pixs))
2916 return ERROR_INT(
"pixs not 8 bpp or has colormap", procName, 1);
2920 return ERROR_INT(
"invalid direction", procName, 1);
2924 dir = (L_ABS(x1 - x2) == n - 1) ? L_HORIZ : L_VERT;
2933 for (i = 0; i < n; i++) {
2938 if (dir == L_HORIZ) {
2939 if (x < 0 || x >= w)
continue;
2940 for (j = negloc; j <= posloc; j++) {
2941 if (y + j < 0 || y + j >= h)
continue;
2944 if (val < minval) minval = val;
2945 if (val > maxval) maxval = val;
2948 if (y < 0 || y >= h)
continue;
2949 for (j = negloc; j <= posloc; j++) {
2950 if (x + j < 0 || x + j >= w)
continue;
2953 if (val < minval) minval = val;
2954 if (val > maxval) maxval = val;
2968 return ERROR_INT(
"no output from this line", procName, 1);
3011 l_int32 i, j, k, m, w, h, wpl, val;
3013 l_uint32 *datas, *datad, *lines, *lined;
3016 PROCNAME(
"pixRankRowTransform");
3019 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
3020 if (pixGetDepth(pixs) != 8)
3021 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
3022 if (pixGetColormap(pixs))
3023 return (
PIX *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
3029 wpl = pixGetWpl(pixs);
3030 for (i = 0; i < h; i++) {
3031 memset(histo, 0, 1024);
3032 lines = datas + i * wpl;
3033 lined = datad + i * wpl;
3034 for (j = 0; j < w; j++) {
3038 for (m = 0, j = 0; m < 256; m++) {
3039 for (k = 0; k < histo[m]; k++, j++)
3064 l_int32 i, j, k, m, w, h, val;
3066 void **lines8, **lined8;
3069 PROCNAME(
"pixRankColumnTransform");
3072 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
3073 if (pixGetDepth(pixs) != 8)
3074 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", procName, NULL);
3075 if (pixGetColormap(pixs))
3076 return (
PIX *)ERROR_PTR(
"pixs has a colormap", procName, NULL);
3082 for (j = 0; j < w; j++) {
3083 memset(histo, 0, 1024);
3084 for (i = 0; i < h; i++) {
3088 for (m = 0, i = 0; m < 256; m++) {
3089 for (k = 0; k < histo[m]; k++, i++)
l_ok numaGetSum(NUMA *na, l_float32 *psum)
numaGetSum()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
l_ok pixPlotAlongPta(PIX *pixs, PTA *pta, l_int32 outformat, const char *title)
pixPlotAlongPta()
NUMA * pixaFindAreaFraction(PIXA *pixa)
pixaFindAreaFraction()
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()
NUMA * pixExtractOnLine(PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor)
pixExtractOnLine()
BOXA * pixFindRectangleComps(PIX *pixs, l_int32 dist, l_int32 minw, l_int32 minh)
pixFindRectangleComps()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_ok pixcmapGetNearestIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetNearestIndex()
PIX * pixExtractBorderConnComps(PIX *pixs, l_int32 connectivity)
pixExtractBorderConnComps()
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()
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)
pixSelectComponentBySize()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
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_ok pixWindowedVarianceOnLine(PIX *pixs, l_int32 dir, l_int32 loc, l_int32 c1, l_int32 c2, l_int32 size, NUMA **pnad)
pixWindowedVarianceOnLine()
l_ok pixSetAll(PIX *pix)
pixSetAll()
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()
NUMA * pixaFindPerimSizeRatio(PIXA *pixa)
pixaFindPerimSizeRatio()
l_ok pixClipBoxToEdges(PIX *pixs, BOX *boxs, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, PIX **ppixd, BOX **pboxd)
pixClipBoxToEdges()
PIX * pixaDisplay(PIXA *pixa, l_int32 w, l_int32 h)
pixaDisplay()
#define GET_DATA_BIT(pdata, n)
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_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
l_ok pixSetOrClearBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
pixSetOrClearBorder()
NUMA * pixaFindWidthHeightProduct(PIXA *pixa)
pixaFindWidthHeightProduct()
l_ok pixPaintThroughMask(PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
pixPaintThroughMask()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
PIX * pixMakeCoveringOfRectangles(PIX *pixs, l_int32 maxiters)
pixMakeCoveringOfRectangles()
l_ok pixClipToForeground(PIX *pixs, PIX **ppixd, BOX **pbox)
pixClipToForeground()
l_ok pixaFindDimensions(PIXA *pixa, NUMA **pnaw, NUMA **pnah)
pixaFindDimensions()
l_ok numaCountReversals(NUMA *nas, l_float32 minreversal, l_int32 *pnr, l_float32 *prd)
numaCountReversals()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
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 pixFindPerimToAreaRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindPerimToAreaRatio()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
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()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
PIX * pixAnd(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixAnd()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
PIX * pixCropToSize(PIX *pixs, l_int32 w, l_int32 h)
pixCropToSize()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
#define SET_DATA_BYTE(pdata, n, val)
PIXA * pixClipRectangles(PIX *pixs, BOXA *boxa)
pixClipRectangles()
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 pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixSetMaskedCmap(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetMaskedCmap()
#define GET_DATA_BYTE(pdata, n)
l_ok numaSetParameters(NUMA *na, l_float32 startx, l_float32 delx)
numaSetParameters()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixClipBoxToForeground(PIX *pixs, BOX *boxs, PIX **ppixd, BOX **pboxd)
pixClipBoxToForeground()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
PIX * pixMaskBoxa(PIX *pixd, PIX *pixs, BOXA *boxa, l_int32 op)
pixMaskBoxa()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
PIXA * pixaSort(PIXA *pixas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex, l_int32 copyflag)
pixaSort()
PIX * pixRankColumnTransform(PIX *pixs)
pixRankColumnTransform()
l_ok pixFindAreaFractionMasked(PIX *pixs, BOX *box, PIX *pixm, l_int32 *tab, l_float32 *pfract)
pixFindAreaFractionMasked()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok pixFindAreaPerimRatio(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaPerimRatio()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
BOX * boxRelocateOneSide(BOX *boxd, BOX *boxs, l_int32 loc, l_int32 sideflag)
boxRelocateOneSide()
l_ok pixFindPerimSizeRatio(PIX *pixs, l_int32 *tab, l_float32 *pratio)
pixFindPerimSizeRatio()
l_ok pixaIsFull(PIXA *pixa, l_int32 *pfullpa, l_int32 *pfullba)
pixaIsFull()
l_float32 * numaGetFArray(NUMA *na, l_int32 copyflag)
numaGetFArray()
l_ok pixScanForForeground(PIX *pixs, BOX *box, l_int32 scanflag, l_int32 *ploc)
pixScanForForeground()
l_ok pixFractionFgInMask(PIX *pix1, PIX *pix2, l_float32 *pfract)
pixFractionFgInMask()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
l_ok pixCropToMatch(PIX *pixs1, PIX *pixs2, PIX **ppixd1, PIX **ppixd2)
pixCropToMatch()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
void boxDestroy(BOX **pbox)
boxDestroy()
l_ok pixEqual(PIX *pix1, PIX *pix2, l_int32 *psame)
pixEqual()
l_ok pixFindOverlapFraction(PIX *pixs1, PIX *pixs2, l_int32 x2, l_int32 y2, l_int32 *tab, l_float32 *pratio, l_int32 *pnoverlap)
pixFindOverlapFraction()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_ok pixFindAreaFraction(PIX *pixs, l_int32 *tab, l_float32 *pfract)
pixFindAreaFraction()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
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_ok pixTestClipToForeground(PIX *pixs, l_int32 *pcanclip)
pixTestClipToForeground()
PIX * pixRankRowTransform(PIX *pixs)
pixRankRowTransform()
PIX * pixErodeBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeBrick()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
l_ok pixConformsToRectangle(PIX *pixs, BOX *box, l_int32 dist, l_int32 *pconforms)
pixConformsToRectangle()
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()