211l_int32 w, h, i, j, wpl1, wplr, wplg, wplb;
212l_int32 rval, gval, bval, rgdiff, rbdiff, gbdiff, maxval, colorval;
214l_uint32 *data1, *datar, *datag, *datab, *line1, *liner, *lineg, *lineb;
215PIX *pix1, *pixr, *pixg, *pixb;
217 if (!ppixr && !ppixg && !ppixb)
218 return ERROR_INT(
"no return val requested", __func__, 1);
219 if (ppixr) *ppixr = NULL;
220 if (ppixg) *ppixg = NULL;
221 if (ppixb) *ppixb = NULL;
223 return ERROR_INT(
"pixs not defined", __func__, 1);
224 if (mingray < 0) mingray = 0;
226 return ERROR_INT(
"mingray > 255", __func__, 1);
230 return ERROR_INT(
"pix1 not returned", __func__, 1);
232 pixr = pixg = pixb = NULL;
233 datar = datag = datab = NULL;
234 liner = lineg = lineb = NULL;
236 pixGetDimensions(pix1, &w, &h, NULL);
238 pixr = pixCreate(w, h, 8);
239 datar = pixGetData(pixr);
240 wplr = pixGetWpl(pixr);
244 pixg = pixCreate(w, h, 8);
245 datag = pixGetData(pixg);
246 wplg = pixGetWpl(pixg);
250 pixb = pixCreate(w, h, 8);
251 datab = pixGetData(pixb);
252 wplb = pixGetWpl(pixb);
256 data1 = pixGetData(pix1);
257 wpl1 = pixGetWpl(pix1);
258 for (i = 0; i < h; i++) {
259 line1 = data1 + i * wpl1;
261 liner = datar + i * wplr;
263 lineg = datag + i * wplg;
265 lineb = datab + i * wplb;
266 for (j = 0; j < w; j++) {
268 extractRGBValues(pixel, &rval, &gval, &bval);
270 maxval = L_MAX(rval, gval);
271 maxval = L_MAX(maxval, bval);
272 if (maxval < mingray)
275 rgdiff = L_ABS(rval - gval);
276 rbdiff = L_ABS(rval - bval);
277 gbdiff = L_ABS(gval - bval);
279 colorval = (rgdiff + rbdiff) / 2;
283 colorval = (rgdiff + gbdiff) / 2;
287 colorval = (rbdiff + gbdiff) / 2;
369l_int32 w, h, i, j, wpl1, wpld;
370l_int32 rval, gval, bval, rdist, gdist, bdist, colorval;
371l_int32 rgdist, rbdist, gbdist, mindist, maxdist, minval, maxval;
373l_uint32 *data1, *datad, *line1, *lined;
377 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
380 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
384 return (
PIX *)ERROR_PTR(
"pix1 not returned", __func__, NULL);
386 pixGetDimensions(pix1, &w, &h, NULL);
387 pixd = pixCreate(w, h, 8);
388 datad = pixGetData(pixd);
389 wpld = pixGetWpl(pixd);
390 data1 = pixGetData(pix1);
391 wpl1 = pixGetWpl(pix1);
392 for (i = 0; i < h; i++) {
393 line1 = data1 + i * wpl1;
394 lined = datad + i * wpld;
395 for (j = 0; j < w; j++) {
397 extractRGBValues(pixel, &rval, &gval, &bval);
399 rgdist = L_ABS(rval - gval);
400 rbdist = L_ABS(rval - bval);
401 gbdist = L_ABS(gval - bval);
402 maxdist = L_MAX(rgdist, rbdist);
403 if (gbdist >= maxdist) {
406 mindist = L_MIN(rgdist, rbdist);
407 colorval = L_MAX(mindist, gbdist);
410 rdist = ((gval + bval ) / 2 - rval);
411 rdist = L_ABS(rdist);
412 gdist = ((rval + bval ) / 2 - gval);
413 gdist = L_ABS(gdist);
414 bdist = ((rval + gval ) / 2 - bval);
415 bdist = L_ABS(bdist);
416 colorval = L_MAX(rdist, gdist);
417 colorval = L_MAX(colorval, bdist);
419 minval = L_MIN(rval, gval);
420 minval = L_MIN(minval, bval);
421 maxval = L_MAX(rval, gval);
422 maxval = L_MAX(maxval, bval);
423 colorval = maxval - minval;
498 l_float32 *ppixfract,
499 l_float32 *pcolorfract)
501l_int32 i, j, w, h, wpl, rval, gval, bval, minval, maxval;
502l_int32 total, npix, ncolor;
504l_uint32 *data, *line;
506 if (ppixfract) *ppixfract = 0.0;
507 if (pcolorfract) *pcolorfract = 0.0;
508 if (!ppixfract && !pcolorfract)
509 return ERROR_INT(
"neither &pixfract nor &colorfract are defined",
511 if (!pixs || pixGetDepth(pixs) != 32)
512 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
514 pixGetDimensions(pixs, &w, &h, NULL);
515 data = pixGetData(pixs);
516 wpl = pixGetWpl(pixs);
517 npix = ncolor = total = 0;
518 for (i = 0; i < h; i += factor) {
519 line = data + i * wpl;
520 for (j = 0; j < w; j += factor) {
523 extractRGBValues(pixel, &rval, &gval, &bval);
524 minval = L_MIN(rval, gval);
525 minval = L_MIN(minval, bval);
526 if (minval > lightthresh)
528 maxval = L_MAX(rval, gval);
529 maxval = L_MAX(maxval, bval);
530 if (maxval < darkthresh)
534 if (maxval - minval >= diffthresh)
540 L_WARNING(
"No pixels found for consideration\n", __func__);
543 if (ppixfract) *ppixfract = (l_float32)npix / (l_float32)total;
544 if (pcolorfract) *pcolorfract = (l_float32)ncolor / (l_float32)npix;
585l_int32 w, h, i, j, wpl1, wpl2, rval, gval, bval;
586l_int32 *rtab, *gtab, *btab;
588l_uint32 *data1, *data2, *line1, *line2;
589NUMA *nar, *nag, *nab;
594 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
596 cmap = pixGetColormap(pixs);
597 if (!cmap && pixGetDepth(pixs) != 32)
598 return (
PIX *)ERROR_PTR(
"pixs neither cmapped nor 32 bpp",
603 pix1 = pixClone(pixs);
605 if (!rref && !gref && !bref)
609 if ((rref < 0 || gref < 0 || bref < 0) || (rref * gref * bref == 0)) {
610 L_WARNING(
"invalid set of ref values\n", __func__);
615 pixGetDimensions(pix1, &w, &h, NULL);
616 pix2 = pixCreate(w, h, 32);
617 data1 = pixGetData(pix1);
618 wpl1 = pixGetWpl(pix1);
619 data2 = pixGetData(pix2);
620 wpl2 = pixGetWpl(pix2);
621 nar = numaGammaTRC(1.0, 0, rref);
622 rtab = numaGetIArray(nar);
623 nag = numaGammaTRC(1.0, 0, gref);
624 gtab = numaGetIArray(nag);
625 nab = numaGammaTRC(1.0, 0, bref);
626 btab = numaGetIArray(nab);
627 for (i = 0; i < h; i++) {
628 line1 = data1 + i * wpl1;
629 line2 = data2 + i * wpl2;
630 for (j = 0; j < w; j++) {
632 extractRGBValues(pixel, &rval, &gval, &bval);
636 composeRGBPixel(rval, gval, bval, line2 + j);
687l_int32 w, h, d, i, j, wpls, wpld, size;
688l_int32 rval, gval, bval, minval, maxval;
689l_uint32 *datas, *datad, *lines, *lined;
694 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
695 pixGetDimensions(pixs, &w, &h, &d);
697 cmap = pixGetColormap(pixs);
698 if (!cmap && d != 32)
699 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
703 pixc = pixClone(pixs);
704 if (!pixc || pixGetDepth(pixc) != 32) {
706 return (
PIX *)ERROR_PTR(
"rgb pix not made", __func__, NULL);
709 pixd = pixCreate(w, h, 1);
710 datad = pixGetData(pixd);
711 wpld = pixGetWpl(pixd);
712 datas = pixGetData(pixc);
713 wpls = pixGetWpl(pixc);
714 for (i = 0; i < h; i++) {
715 lines = datas + i * wpls;
716 lined = datad + i * wpld;
717 for (j = 0; j < w; j++) {
718 extractRGBValues(lines[j], &rval, &gval, &bval);
719 minval = L_MIN(rval, gval);
720 minval = L_MIN(minval, bval);
721 maxval = L_MAX(rval, gval);
722 maxval = L_MAX(maxval, bval);
723 if (maxval - minval >= threshdiff)
729 size = 2 * (mindist - 1) + 1;
730 pixErodeBrick(pixd, pixd, size, size);
767l_int32 w, h, i, j, wpls, wpld;
768l_int32 rval, gval, bval, minrg, min, maxrg, max, sat;
769l_uint32 *datas, *datad, *lines, *lined;
772 if (!pixs || pixGetDepth(pixs) != 32)
773 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
774 if (maxlimit < 0 || maxlimit > 255)
775 return (
PIX *)ERROR_PTR(
"invalid maxlimit", __func__, NULL);
777 return (
PIX *)ERROR_PTR(
"invalid satlimit", __func__, NULL);
779 pixGetDimensions(pixs, &w, &h, NULL);
780 datas = pixGetData(pixs);
781 wpls = pixGetWpl(pixs);
782 if ((pixd = pixCreate(w, h, 1)) == NULL)
783 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
784 datad = pixGetData(pixd);
785 wpld = pixGetWpl(pixd);
787 for (i = 0; i < h; i++) {
788 lines = datas + i * wpls;
789 lined = datad + i * wpld;
790 for (j = 0; j < w; j++) {
791 extractRGBValues(lines[j], &rval, &gval, &bval);
792 minrg = L_MIN(rval, gval);
793 min = L_MIN(minrg, bval);
794 maxrg = L_MAX(rval, gval);
795 max = L_MAX(maxrg, bval);
797 if (max <= maxlimit && sat <= satlimit)
827l_int32 w, h, d, i, j, wpls, wpld;
828l_int32 rval, gval, bval;
829l_uint32 *datas, *datad, *lines, *lined;
834 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
835 pixGetDimensions(pixs, &w, &h, &d);
837 cmap = pixGetColormap(pixs);
838 if (!cmap && d != 32)
839 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
843 pixc = pixClone(pixs);
845 pixd = pixCreate(w, h, 1);
846 datad = pixGetData(pixd);
847 wpld = pixGetWpl(pixd);
848 datas = pixGetData(pixc);
849 wpls = pixGetWpl(pixc);
850 for (i = 0; i < h; i++) {
851 lines = datas + i * wpls;
852 lined = datad + i * wpld;
853 for (j = 0; j < w; j++) {
854 extractRGBValues(lines[j], &rval, &gval, &bval);
855 if (rval < rmin || rval > rmax)
continue;
856 if (gval < gmin || gval > gmax)
continue;
857 if (bval < bmin || bval > bmax)
continue;
944 l_float32 *pcolorfract,
949l_int32 w, h, count, rval, gval, bval, aveval, proceed;
953PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pixm1, *pixm2, *pixm3;
955 if (pcolormask1) *pcolormask1 = NULL;
956 if (pcolormask2) *pcolormask2 = NULL;
958 return ERROR_INT(
"&colorfract not defined", __func__, 1);
960 if (!pixs || pixGetDepth(pixs) != 32)
961 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
962 if (factor < 1) factor = 1;
963 if (lightthresh < 0) lightthresh = 210;
964 if (darkthresh < 0) darkthresh = 70;
965 if (mindiff < 0) mindiff = 10;
966 if (colordiff < 0) colordiff = 90;
967 if (edgefract < 0.0 || edgefract > 1.0) edgefract = 0.05f;
971 pixForegroundFraction(pixm, &ratio);
973 if (pixadb) L_INFO(
"pixm has big fg: %f5.2\n", __func__, ratio);
983 return ERROR_INT(
"rank color array not made", __func__, 1);
984 extractRGBValues(carray[9], &rval, &gval, &bval);
985 if (pixadb) L_INFO(
"lightest background color: (r,g,b) = (%d,%d,%d)\n",
986 __func__, rval, gval, bval);
988 if ((rval < bval - 2) || (rval < gval - 2)) {
989 if (pixadb) L_INFO(
"background not reddish\n", __func__);
992 aveval = (rval + gval + bval) / 3;
993 if (aveval < lightthresh) {
994 if (pixadb) L_INFO(
"background too dark\n", __func__);
998 pix1 = pixDisplayColorArray(carray, 10, 120, 3, 6);
1002 if (proceed == FALSE)
return 0;
1008 pix1 = pixConvertRGBToGray(pixs, 0.33f, 0.34f, 0.33f);
1009 if (pixadb) pixaAddPix(pixadb, pix1,
L_COPY);
1010 pixm1 = pixThresholdToBinary(pix1, darkthresh);
1011 pixDilateBrick(pixm1, pixm1, 7, 7);
1012 if (pixadb) pixaAddPix(pixadb, pixm1,
L_COPY);
1014 pixOr(pixm1, pixm1, pixm);
1015 if (pixadb) pixaAddPix(pixadb, pixm1,
L_COPY);
1021 pixm2 = pixConvertRGBToBinaryArb(pixs, -1.0, 0.0, 1.0, mindiff,
1023 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1024 pix1 = pixConvertRGBToBinaryArb(pixs, -1.0, 1.0, 0.0, mindiff,
1026 if (pixadb) pixaAddPix(pixadb, pix1,
L_COPY);
1027 pixOr(pixm2, pixm2, pix1);
1029 pix1 = pixConvertRGBToGrayMinMax(pixs, L_CHOOSE_MAXDIFF);
1030 pix2 = pixThresholdToBinary(pix1, colordiff);
1031 pixInvert(pix2, pix2);
1032 if (pixadb) pixaAddPix(pixadb, pix2,
L_COPY);
1033 pixOr(pixm2, pixm2, pix2);
1034 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1040 pixSubtract(pixm2, pixm2, pixm1);
1042 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1050 pixm3 = pixRemoveBorderConnComps(pixm2, 8);
1051 pixGetDimensions(pixm3, &w, &h, NULL);
1053 if (edgefract > 0.0) {
1054 pix2 = pixMakeSymmetricMask(w, h, edgefract, edgefract,
L_USE_INNER);
1055 pixAnd(pixm3, pixm3, pix2);
1058 if (pixadb) pixaAddPix(pixadb, pixm3,
L_COPY);
1061 pixCountPixels(pixm3, &count, NULL);
1062 *pcolorfract = (l_float32)count / ((l_float32)(w) * h);
1065 L_INFO(
"no light color pixels found\n", __func__);
1067 L_INFO(
"fraction of light color pixels = %5.3f\n", __func__,
1072 if (pixadb && count > 0) {
1074 pix3 = pixCreateTemplate(pixs);
1076 pixCombineMasked(pix3, pixs, pixm3);
1077 pixaAddPix(pixadb, pix3,
L_INSERT);
1080 pix3 = pixCloseSafeBrick(NULL, pixm3, 15, 15);
1081 pixaAddPix(pixadb, pix3,
L_INSERT);
1082 pix5 = pixCreateTemplate(pixs);
1084 pixCombineMasked(pix5, pixs, pix3);
1085 pixaAddPix(pixadb, pix5,
L_INSERT);
1089 boxa1 = pixConnCompBB(pix3, 8);
1090 boxa2 = boxaCombineOverlaps(boxa1, NULL);
1091 pix4 = pixCreateTemplate(pix3);
1093 pixaAddPix(pixadb, pix4,
L_INSERT);
1094 pix5 = pixCreateTemplate(pixs);
1096 pixCombineMasked(pix5, pixs, pix4);
1097 pixaAddPix(pixadb, pix5,
L_INSERT);
1098 boxaDestroy(&boxa1);
1099 boxaDestroy(&boxa2);
1101 pixaAddPix(pixadb, pixs,
L_COPY);
1104 if (pcolormask2 && count > 0)
1105 *pcolormask2 = pixCloseSafeBrick(NULL, pixm3, 15, 15);
1106 if (pcolormask1 && count > 0)
1107 *pcolormask1 = pixm3;
1278l_int32 w, h, d, minside, factor;
1279l_float32 pixfract, colorfract;
1280PIX *pixt, *pixsc, *pixg, *pixe, *pixb, *pixm;
1283 if (piscolor) *piscolor = 0;
1285 return ERROR_INT(
"&ncolors not defined", __func__, 1);
1288 return ERROR_INT(
"pixs not defined", __func__, 1);
1289 if ((cmap = pixGetColormap(pixs)) != NULL) {
1290 *pncolors = pixcmapGetCount(cmap);
1292 pixcmapHasColor(cmap, piscolor);
1296 pixGetDimensions(pixs, &w, &h, &d);
1297 if (d != 8 && d != 32)
1298 return ERROR_INT(
"pixs not 8 or 32 bpp", __func__, 1);
1307 minside = L_MIN(w, h);
1309 pixt = pixClone(pixs);
1311 factor = L_MAX(1, minside / 400);
1313 if (pixfract * colorfract < 0.00025) {
1314 pixt = pixGetRGBComponent(pixs,
COLOR_RED);
1317 pixt = pixClone(pixs);
1328 factor = L_MAX(1, minside / 500);
1330 pixsc = pixCopy(NULL, pixt);
1331 else if (factor == 2 || factor == 3)
1332 pixsc = pixScaleAreaMap2(pixt);
1334 pixsc = pixScaleAreaMap(pixt, 0.25, 0.25);
1347 pixg = pixClone(pixsc);
1349 pixg = pixConvertRGBToLuminance(pixsc);
1351 pixb = pixThresholdToBinary(pixe, thresh);
1352 pixInvert(pixb, pixb);
1354 pixm = pixMorphSequence(pixb,
"d3.3", 0);
1356 pixm = pixMorphSequence(pixb,
"d7.7", 0);
1367 pixSetMasked(pixg, pixm, 0xff);
1368 if (debug) pixWrite(
"junkpix8.png", pixg, IFF_PNG);
1371 pixSetMasked(pixsc, pixm, 0xffffffff);
1372 if (debug) pixWrite(
"junkpix32.png", pixsc, IFF_PNG);
1373 pixNumberOccupiedOctcubes(pixsc, 4, 20, -1, pncolors);
1416l_int32 w, h, d, i, j, wpl, hashsize, sum, count, manycolors;
1417l_int32 rval, gval, bval, val;
1420l_uint32 *data, *line;
1424 return ERROR_INT(
"&ncolors not defined", __func__, 1);
1427 return ERROR_INT(
"pixs not defined", __func__, 1);
1428 pixGetDimensions(pixs, &w, &h, &d);
1429 if (d != 2 && d != 4 && d != 8 && d != 32)
1430 return ERROR_INT(
"d not in {2, 4, 8, 32}", __func__, 1);
1431 if (factor < 1) factor = 1;
1433 data = pixGetData(pixs);
1434 wpl = pixGetWpl(pixs);
1437 inta = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1438 for (i = 0; i < h; i += factor) {
1439 line = data + i * wpl;
1440 for (j = 0; j < w; j += factor) {
1450 for (i = 0; i < 256; i++)
1455 cmap = pixGetColormap(pixs);
1456 if (cmap && factor == 1) {
1457 count = pixcmapGetCount(cmap);
1459 L_WARNING(
"colormap size %d differs from actual colors\n",
1467 inta = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1469 for (i = 0; i < h && manycolors == 0; i += factor) {
1470 line = data + i * wpl;
1471 for (j = 0; j < w; j += factor) {
1473 extractRGBValues(pixel, &rval, &gval, &bval);
1474 val = (137 * rval + 269 * gval + 353 * bval) % hashsize;
1475 if (inta[val] == 0) {
1487 if (manycolors == 0) {
1493 return pixCountRGBColorsByHash(pixs, pncolors);
1515l_int32 w, h, d, i, j, wpls, wpld, hashsize, hashval, ncolors, index;
1516l_int32 rval, gval, bval, val;
1517l_int32 *hasha1, *hasha2;
1519l_uint32 *datas, *lines, *datad, *lined;
1523 if (!pixs || pixGetDepth(pixs) != 32)
1524 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
1527 if (ncolors > 256) {
1528 L_ERROR(
"too many colors found: %d\n", __func__, ncolors);
1532 pixGetDimensions(pixs, &w, &h, NULL);
1535 else if (ncolors <= 4)
1537 else if (ncolors <= 16)
1542 if ((pixd = pixCreate(w, h, d)) == NULL)
1543 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1544 cmap = pixcmapCreate(d);
1545 datas = pixGetData(pixs);
1546 wpls = pixGetWpl(pixs);
1547 datad = pixGetData(pixd);
1548 wpld = pixGetWpl(pixd);
1555 hasha1 = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1556 hasha2 = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1558 for (i = 0; i < h; i++) {
1559 lines = datas + i * wpls;
1560 lined = datad + i * wpld;
1561 for (j = 0; j < w; j++) {
1563 extractRGBValues(pixel, &rval, &gval, &bval);
1564 hashval = (137 * rval + 269 * gval + 353 * bval) % hashsize;
1565 if (hasha1[hashval] == 0) {
1566 hasha1[hashval] = 1;
1568 hasha2[hashval] = index;
1569 pixcmapAddColor(cmap, rval, gval, bval);
1571 val = hasha2[hashval];
1572 setLineDataVal(lined, j, d, val);
1575 pixSetColormap(pixd, cmap);
1615l_int32 n, i, rgbindex, rval, gval, bval;
1616NUMA *nahisto, *naindex;
1618 if (!parray && !pcmap)
1619 return ERROR_INT(
"no return val requested", __func__, 1);
1620 if (parray) *parray = NULL;
1621 if (pcmap) *pcmap = NULL;
1622 if (!pixs || pixGetDepth(pixs) != 32)
1623 return ERROR_INT(
"pixs not defined", __func__, 1);
1624 if (sigbits < 2 || sigbits > 6)
1625 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1626 if (factor < 1 || ncolors < 1)
1627 return ERROR_INT(
"factor < 1 or ncolors < 1", __func__, 1);
1630 return ERROR_INT(
"nahisto not made", __func__, 1);
1634 numaDestroy(&nahisto);
1636 return ERROR_INT(
"naindex not made", __func__, 1);
1638 n = numaGetCount(naindex);
1639 ncolors = L_MIN(n, ncolors);
1640 if (parray) *parray = (l_uint32 *)LEPT_CALLOC(ncolors,
sizeof(l_uint32));
1641 if (pcmap) *pcmap = pixcmapCreate(8);
1642 for (i = 0; i < ncolors; i++) {
1643 numaGetIValue(naindex, i, &rgbindex);
1645 if (parray) composeRGBPixel(rval, gval, bval, *parray + i);
1646 if (pcmap) pixcmapAddColor(*pcmap, rval, gval, bval);
1649 numaDestroy(&naindex);
1731l_int32 w, h, i, j, size, wpl, rval, gval, bval, npts;
1732l_uint32 val32, rgbindex;
1734l_uint32 *data, *line, *rtab, *gtab, *btab;
1737 if (!pixs || pixGetDepth(pixs) != 32)
1738 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1739 if (sigbits < 2 || sigbits > 6)
1740 return (
NUMA *)ERROR_PTR(
"sigbits not in [2 ... 6]", __func__, NULL);
1742 return (
NUMA *)ERROR_PTR(
"factor < 1", __func__, NULL);
1745 size = 1 << (3 * sigbits);
1746 na = numaMakeConstant(0, size);
1747 array = numaGetFArray(na,
L_NOCOPY);
1752 pixGetDimensions(pixs, &w, &h, NULL);
1753 npts = ((w + factor - 1) / factor) * ((h + factor - 1) / factor);
1755 L_WARNING(
"only sampling %d pixels\n", __func__, npts);
1756 wpl = pixGetWpl(pixs);
1757 data = pixGetData(pixs);
1758 for (i = 0; i < h; i += factor) {
1759 line = data + i * wpl;
1760 for (j = 0; j < w; j += factor) {
1761 val32 = *(line + j);
1762 extractRGBValues(val32, &rval, &gval, &bval);
1763 rgbindex = rtab[rval] | gtab[gval] | btab[bval];
1799l_uint32 *rtab, *gtab, *btab;
1801 if (prtab) *prtab = NULL;
1802 if (pgtab) *pgtab = NULL;
1803 if (pbtab) *pbtab = NULL;
1804 if (!prtab || !pgtab || !pbtab)
1805 return ERROR_INT(
"not all table ptrs defined", __func__, 1);
1806 if (sigbits < 2 || sigbits > 6)
1807 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1809 rtab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1810 gtab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1811 btab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1812 if (!rtab || !gtab || !btab) {
1816 return ERROR_INT(
"calloc fail for tab", __func__, 1);
1823 for (i = 0; i < 256; i++) {
1824 rtab[i] = (i & 0xc0) >> 2;
1825 gtab[i] = (i & 0xc0) >> 4;
1826 btab[i] = (i & 0xc0) >> 6;
1830 for (i = 0; i < 256; i++) {
1831 rtab[i] = (i & 0xe0) << 1;
1832 gtab[i] = (i & 0xe0) >> 2;
1833 btab[i] = (i & 0xe0) >> 5;
1837 for (i = 0; i < 256; i++) {
1838 rtab[i] = (i & 0xf0) << 4;
1839 gtab[i] = (i & 0xf0);
1840 btab[i] = (i & 0xf0) >> 4;
1844 for (i = 0; i < 256; i++) {
1845 rtab[i] = (i & 0xf8) << 7;
1846 gtab[i] = (i & 0xf8) << 2;
1847 btab[i] = (i & 0xf8) >> 3;
1851 for (i = 0; i < 256; i++) {
1852 rtab[i] = (i & 0xfc) << 10;
1853 gtab[i] = (i & 0xfc) << 4;
1854 btab[i] = (i & 0xfc) >> 2;
1858 L_ERROR(
"Illegal sigbits = %d\n", __func__, sigbits);
1859 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1891 if (prval) *prval = 0;
1892 if (pgval) *pgval = 0;
1893 if (pbval) *pbval = 0;
1894 if (!prval || !pgval || !pbval)
1895 return ERROR_INT(
"not all component ptrs defined", __func__, 1);
1896 if (sigbits < 2 || sigbits > 6)
1897 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1901 *prval = ((index << 2) & 0xc0) | 0x20;
1902 *pgval = ((index << 4) & 0xc0) | 0x20;
1903 *pbval = ((index << 6) & 0xc0) | 0x20;
1906 *prval = ((index >> 1) & 0xe0) | 0x10;
1907 *pgval = ((index << 2) & 0xe0) | 0x10;
1908 *pbval = ((index << 5) & 0xe0) | 0x10;
1911 *prval = ((index >> 4) & 0xf0) | 0x08;
1912 *pgval = (index & 0xf0) | 0x08;
1913 *pbval = ((index << 4) & 0xf0) | 0x08;
1916 *prval = ((index >> 7) & 0xf8) | 0x04;
1917 *pgval = ((index >> 2) & 0xf8) | 0x04;
1918 *pbval = ((index << 3) & 0xf8) | 0x04;
1921 *prval = ((index >> 10) & 0xfc) | 0x02;
1922 *pgval = ((index >> 4) & 0xfc) | 0x02;
1923 *pbval = ((index << 2) & 0xfc) | 0x02;
1926 L_ERROR(
"Illegal sigbits = %d\n", __func__, sigbits);
1927 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1974l_float32 fract, ratio;
1975PIX *pix1, *pix2, *pix3, *pix4;
1978 if (pratio) *pratio = 0.0;
1979 if (ppixdb) *ppixdb = NULL;
1980 if (phasred) *phasred = 0;
1981 if (!pratio && !ppixdb)
1982 return ERROR_INT(
"no return val requested", __func__, 1);
1984 return ERROR_INT(
"&hasred not defined", __func__, 1);
1985 if (!pixs || pixGetDepth(pixs) != 32)
1986 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
1987 if (minfract <= 0.0)
1988 return ERROR_INT(
"minfract must be > 0.0", __func__, 1);
1989 if (fthresh < 1.5 || fthresh > 3.5)
1990 L_WARNING(
"fthresh = %f is out of normal bounds\n", __func__, fthresh);
1993 pix1 = pixScaleByIntSampling(pixs, factor);
1995 pix1 = pixClone(pixs);
1998 fpix = pixComponentFunction(pix1, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0);
1999 pix2 = fpixThresholdToPix(fpix, fthresh);
2000 pixInvert(pix2, pix2);
2003 pix3 = pixGetRGBComponent(pix1,
COLOR_RED);
2004 pix4 = pixThresholdToBinary(pix3, 130);
2005 pixInvert(pix4, pix4);
2007 pixAnd(pix4, pix4, pix2);
2008 pixForegroundFraction(pix4, &fract);
2009 ratio = fract / minfract;
2010 L_INFO(
"fract = %7.5f, ratio = %7.3f\n", __func__, fract, ratio);
2011 if (pratio) *pratio = ratio;
l_ok pixNumSignificantGrayColors(PIX *pixs, l_int32 darkthresh, l_int32 lightthresh, l_float32 minfract, l_int32 factor, l_int32 *pncolors)
pixNumSignificantGrayColors()
l_ok pixColorsForQuantization(PIX *pixs, l_int32 thresh, l_int32 *pncolors, l_int32 *piscolor, l_int32 debug)
pixColorsForQuantization()
l_ok pixColorFraction(PIX *pixs, l_int32 darkthresh, l_int32 lightthresh, l_int32 diffthresh, l_int32 factor, l_float32 *ppixfract, l_float32 *pcolorfract)
pixColorFraction()
l_ok pixHasHighlightRed(PIX *pixs, l_int32 factor, l_float32 minfract, l_float32 fthresh, l_int32 *phasred, l_float32 *pratio, PIX **ppixdb)
pixHasHighlightRed()
l_ok pixColorContent(PIX *pixs, l_int32 rref, l_int32 gref, l_int32 bref, l_int32 mingray, PIX **ppixr, PIX **ppixg, PIX **ppixb)
pixColorContent()
l_ok pixGetMostPopulatedColors(PIX *pixs, l_int32 sigbits, l_int32 factor, l_int32 ncolors, l_uint32 **parray, PIXCMAP **pcmap)
pixGetMostPopulatedColors()
PIX * pixSimpleColorQuantize(PIX *pixs, l_int32 sigbits, l_int32 factor, l_int32 ncolors)
pixSimpleColorQuantize()
PIX * pixMaskOverGrayPixels(PIX *pixs, l_int32 maxlimit, l_int32 satlimit)
pixMaskOverGrayPixels()
PIX * pixMaskOverColorPixels(PIX *pixs, l_int32 threshdiff, l_int32 mindist)
pixMaskOverColorPixels()
PIX * pixColorShiftWhitePoint(PIX *pixs, l_int32 rref, l_int32 gref, l_int32 bref)
pixColorShiftWhitePoint()
l_ok getRGBFromIndex(l_uint32 index, l_int32 sigbits, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
getRGBFromIndex()
NUMA * pixGetRGBHistogram(PIX *pixs, l_int32 sigbits, l_int32 factor)
pixGetRGBHistogram()
l_ok pixFindColorRegions(PIX *pixs, PIX *pixm, l_int32 factor, l_int32 lightthresh, l_int32 darkthresh, l_int32 mindiff, l_int32 colordiff, l_float32 edgefract, l_float32 *pcolorfract, PIX **pcolormask1, PIX **pcolormask2, PIXA *pixadb)
pixFindColorRegions()
l_ok makeRGBIndexTables(l_uint32 **prtab, l_uint32 **pgtab, l_uint32 **pbtab, l_int32 sigbits)
makeRGBIndexTables()
PIX * pixMaskOverColorRange(PIX *pixs, l_int32 rmin, l_int32 rmax, l_int32 gmin, l_int32 gmax, l_int32 bmin, l_int32 bmax)
pixMaskOverColorRange()
l_ok pixNumColors(PIX *pixs, l_int32 factor, l_int32 *pncolors)
pixNumColors()
PIX * pixColorMagnitude(PIX *pixs, l_int32 rref, l_int32 gref, l_int32 bref, l_int32 type)
pixColorMagnitude()