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 pixGetDimensions(pix1, &w, &h, NULL);
235 pixr = pixCreate(w, h, 8);
236 datar = pixGetData(pixr);
237 wplr = pixGetWpl(pixr);
241 pixg = pixCreate(w, h, 8);
242 datag = pixGetData(pixg);
243 wplg = pixGetWpl(pixg);
247 pixb = pixCreate(w, h, 8);
248 datab = pixGetData(pixb);
249 wplb = pixGetWpl(pixb);
253 data1 = pixGetData(pix1);
254 wpl1 = pixGetWpl(pix1);
255 for (i = 0; i < h; i++) {
256 line1 = data1 + i * wpl1;
258 liner = datar + i * wplr;
260 lineg = datag + i * wplg;
262 lineb = datab + i * wplb;
263 for (j = 0; j < w; j++) {
265 extractRGBValues(pixel, &rval, &gval, &bval);
267 maxval = L_MAX(rval, gval);
268 maxval = L_MAX(maxval, bval);
269 if (maxval < mingray)
272 rgdiff = L_ABS(rval - gval);
273 rbdiff = L_ABS(rval - bval);
274 gbdiff = L_ABS(gval - bval);
276 colorval = (rgdiff + rbdiff) / 2;
280 colorval = (rgdiff + gbdiff) / 2;
284 colorval = (rbdiff + gbdiff) / 2;
366l_int32 w, h, i, j, wpl1, wpld;
367l_int32 rval, gval, bval, rdist, gdist, bdist, colorval;
368l_int32 rgdist, rbdist, gbdist, mindist, maxdist, minval, maxval;
370l_uint32 *data1, *datad, *line1, *lined;
374 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
377 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
381 return (
PIX *)ERROR_PTR(
"pix1 not returned", __func__, NULL);
383 pixGetDimensions(pix1, &w, &h, NULL);
384 pixd = pixCreate(w, h, 8);
385 datad = pixGetData(pixd);
386 wpld = pixGetWpl(pixd);
387 data1 = pixGetData(pix1);
388 wpl1 = pixGetWpl(pix1);
389 for (i = 0; i < h; i++) {
390 line1 = data1 + i * wpl1;
391 lined = datad + i * wpld;
392 for (j = 0; j < w; j++) {
394 extractRGBValues(pixel, &rval, &gval, &bval);
396 rgdist = L_ABS(rval - gval);
397 rbdist = L_ABS(rval - bval);
398 gbdist = L_ABS(gval - bval);
399 maxdist = L_MAX(rgdist, rbdist);
400 if (gbdist >= maxdist) {
403 mindist = L_MIN(rgdist, rbdist);
404 colorval = L_MAX(mindist, gbdist);
407 rdist = ((gval + bval ) / 2 - rval);
408 rdist = L_ABS(rdist);
409 gdist = ((rval + bval ) / 2 - gval);
410 gdist = L_ABS(gdist);
411 bdist = ((rval + gval ) / 2 - bval);
412 bdist = L_ABS(bdist);
413 colorval = L_MAX(rdist, gdist);
414 colorval = L_MAX(colorval, bdist);
416 minval = L_MIN(rval, gval);
417 minval = L_MIN(minval, bval);
418 maxval = L_MAX(rval, gval);
419 maxval = L_MAX(maxval, bval);
420 colorval = maxval - minval;
495 l_float32 *ppixfract,
496 l_float32 *pcolorfract)
498l_int32 i, j, w, h, wpl, rval, gval, bval, minval, maxval;
499l_int32 total, npix, ncolor;
501l_uint32 *data, *line;
503 if (ppixfract) *ppixfract = 0.0;
504 if (pcolorfract) *pcolorfract = 0.0;
505 if (!ppixfract || !pcolorfract)
506 return ERROR_INT(
"&pixfract and &colorfract not defined",
508 if (!pixs || pixGetDepth(pixs) != 32)
509 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
511 pixGetDimensions(pixs, &w, &h, NULL);
512 data = pixGetData(pixs);
513 wpl = pixGetWpl(pixs);
514 npix = ncolor = total = 0;
515 for (i = 0; i < h; i += factor) {
516 line = data + i * wpl;
517 for (j = 0; j < w; j += factor) {
520 extractRGBValues(pixel, &rval, &gval, &bval);
521 minval = L_MIN(rval, gval);
522 minval = L_MIN(minval, bval);
523 if (minval > lightthresh)
525 maxval = L_MAX(rval, gval);
526 maxval = L_MAX(maxval, bval);
527 if (maxval < darkthresh)
531 if (maxval - minval >= diffthresh)
537 L_WARNING(
"No pixels found for consideration\n", __func__);
540 *ppixfract = (l_float32)npix / (l_float32)total;
541 *pcolorfract = (l_float32)ncolor / (l_float32)npix;
582l_int32 w, h, i, j, wpl1, wpl2, rval, gval, bval;
583l_int32 *rtab, *gtab, *btab;
585l_uint32 *data1, *data2, *line1, *line2;
586NUMA *nar, *nag, *nab;
591 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
593 cmap = pixGetColormap(pixs);
594 if (!cmap && pixGetDepth(pixs) != 32)
595 return (
PIX *)ERROR_PTR(
"pixs neither cmapped nor 32 bpp",
600 pix1 = pixClone(pixs);
602 if (!rref && !gref && !bref)
606 if ((rref < 0 || gref < 0 || bref < 0) || (rref * gref * bref == 0)) {
607 L_WARNING(
"invalid set of ref values\n", __func__);
612 pixGetDimensions(pix1, &w, &h, NULL);
613 pix2 = pixCreate(w, h, 32);
614 data1 = pixGetData(pix1);
615 wpl1 = pixGetWpl(pix1);
616 data2 = pixGetData(pix2);
617 wpl2 = pixGetWpl(pix2);
618 nar = numaGammaTRC(1.0, 0, rref);
619 rtab = numaGetIArray(nar);
620 nag = numaGammaTRC(1.0, 0, gref);
621 gtab = numaGetIArray(nag);
622 nab = numaGammaTRC(1.0, 0, bref);
623 btab = numaGetIArray(nab);
624 for (i = 0; i < h; i++) {
625 line1 = data1 + i * wpl1;
626 line2 = data2 + i * wpl2;
627 for (j = 0; j < w; j++) {
629 extractRGBValues(pixel, &rval, &gval, &bval);
633 composeRGBPixel(rval, gval, bval, line2 + j);
684l_int32 w, h, d, i, j, wpls, wpld, size;
685l_int32 rval, gval, bval, minval, maxval;
686l_uint32 *datas, *datad, *lines, *lined;
691 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
692 pixGetDimensions(pixs, &w, &h, &d);
694 cmap = pixGetColormap(pixs);
695 if (!cmap && d != 32)
696 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
700 pixc = pixClone(pixs);
701 if (!pixc || pixGetDepth(pixc) != 32) {
703 return (
PIX *)ERROR_PTR(
"rgb pix not made", __func__, NULL);
706 pixd = pixCreate(w, h, 1);
707 datad = pixGetData(pixd);
708 wpld = pixGetWpl(pixd);
709 datas = pixGetData(pixc);
710 wpls = pixGetWpl(pixc);
711 for (i = 0; i < h; i++) {
712 lines = datas + i * wpls;
713 lined = datad + i * wpld;
714 for (j = 0; j < w; j++) {
715 extractRGBValues(lines[j], &rval, &gval, &bval);
716 minval = L_MIN(rval, gval);
717 minval = L_MIN(minval, bval);
718 maxval = L_MAX(rval, gval);
719 maxval = L_MAX(maxval, bval);
720 if (maxval - minval >= threshdiff)
726 size = 2 * (mindist - 1) + 1;
727 pixErodeBrick(pixd, pixd, size, size);
764l_int32 w, h, i, j, wpls, wpld;
765l_int32 rval, gval, bval, minrg, min, maxrg, max, sat;
766l_uint32 *datas, *datad, *lines, *lined;
769 if (!pixs || pixGetDepth(pixs) != 32)
770 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
771 if (maxlimit < 0 || maxlimit > 255)
772 return (
PIX *)ERROR_PTR(
"invalid maxlimit", __func__, NULL);
774 return (
PIX *)ERROR_PTR(
"invalid satlimit", __func__, NULL);
776 pixGetDimensions(pixs, &w, &h, NULL);
777 datas = pixGetData(pixs);
778 wpls = pixGetWpl(pixs);
779 if ((pixd = pixCreate(w, h, 1)) == NULL)
780 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
781 datad = pixGetData(pixd);
782 wpld = pixGetWpl(pixd);
784 for (i = 0; i < h; i++) {
785 lines = datas + i * wpls;
786 lined = datad + i * wpld;
787 for (j = 0; j < w; j++) {
788 extractRGBValues(lines[j], &rval, &gval, &bval);
789 minrg = L_MIN(rval, gval);
790 min = L_MIN(minrg, bval);
791 maxrg = L_MAX(rval, gval);
792 max = L_MAX(maxrg, bval);
794 if (max <= maxlimit && sat <= satlimit)
824l_int32 w, h, d, i, j, wpls, wpld;
825l_int32 rval, gval, bval;
826l_uint32 *datas, *datad, *lines, *lined;
831 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
832 pixGetDimensions(pixs, &w, &h, &d);
834 cmap = pixGetColormap(pixs);
835 if (!cmap && d != 32)
836 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
840 pixc = pixClone(pixs);
842 pixd = pixCreate(w, h, 1);
843 datad = pixGetData(pixd);
844 wpld = pixGetWpl(pixd);
845 datas = pixGetData(pixc);
846 wpls = pixGetWpl(pixc);
847 for (i = 0; i < h; i++) {
848 lines = datas + i * wpls;
849 lined = datad + i * wpld;
850 for (j = 0; j < w; j++) {
851 extractRGBValues(lines[j], &rval, &gval, &bval);
852 if (rval < rmin || rval > rmax)
continue;
853 if (gval < gmin || gval > gmax)
continue;
854 if (bval < bmin || bval > bmax)
continue;
941 l_float32 *pcolorfract,
946l_int32 w, h, count, rval, gval, bval, aveval, proceed;
950PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pixm1, *pixm2, *pixm3;
952 if (pcolormask1) *pcolormask1 = NULL;
953 if (pcolormask2) *pcolormask2 = NULL;
955 return ERROR_INT(
"&colorfract not defined", __func__, 1);
957 if (!pixs || pixGetDepth(pixs) != 32)
958 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
959 if (factor < 1) factor = 1;
960 if (lightthresh < 0) lightthresh = 210;
961 if (darkthresh < 0) darkthresh = 70;
962 if (mindiff < 0) mindiff = 10;
963 if (colordiff < 0) colordiff = 90;
964 if (edgefract < 0.0 || edgefract > 1.0) edgefract = 0.05;
968 pixForegroundFraction(pixm, &ratio);
970 if (pixadb) L_INFO(
"pixm has big fg: %f5.2\n", __func__, ratio);
980 return ERROR_INT(
"rank color array not made", __func__, 1);
981 extractRGBValues(carray[9], &rval, &gval, &bval);
982 if (pixadb) L_INFO(
"lightest background color: (r,g,b) = (%d,%d,%d)\n",
983 __func__, rval, gval, bval);
985 if ((rval < bval - 2) || (rval < gval - 2)) {
986 if (pixadb) L_INFO(
"background not reddish\n", __func__);
989 aveval = (rval + gval + bval) / 3;
990 if (aveval < lightthresh) {
991 if (pixadb) L_INFO(
"background too dark\n", __func__);
995 pix1 = pixDisplayColorArray(carray, 10, 120, 3, 6);
999 if (proceed == FALSE)
return 0;
1005 pix1 = pixConvertRGBToGray(pixs, 0.33, 0.34, 0.33);
1006 if (pixadb) pixaAddPix(pixadb, pix1,
L_COPY);
1007 pixm1 = pixThresholdToBinary(pix1, darkthresh);
1008 pixDilateBrick(pixm1, pixm1, 7, 7);
1009 if (pixadb) pixaAddPix(pixadb, pixm1,
L_COPY);
1011 pixOr(pixm1, pixm1, pixm);
1012 if (pixadb) pixaAddPix(pixadb, pixm1,
L_COPY);
1018 pixm2 = pixConvertRGBToBinaryArb(pixs, -1.0, 0.0, 1.0, mindiff,
1020 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1021 pix1 = pixConvertRGBToBinaryArb(pixs, -1.0, 1.0, 0.0, mindiff,
1023 if (pixadb) pixaAddPix(pixadb, pix1,
L_COPY);
1024 pixOr(pixm2, pixm2, pix1);
1026 pix1 = pixConvertRGBToGrayMinMax(pixs, L_CHOOSE_MAXDIFF);
1027 pix2 = pixThresholdToBinary(pix1, colordiff);
1028 pixInvert(pix2, pix2);
1029 if (pixadb) pixaAddPix(pixadb, pix2,
L_COPY);
1030 pixOr(pixm2, pixm2, pix2);
1031 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1037 pixSubtract(pixm2, pixm2, pixm1);
1039 if (pixadb) pixaAddPix(pixadb, pixm2,
L_COPY);
1047 pixm3 = pixRemoveBorderConnComps(pixm2, 8);
1048 pixGetDimensions(pixm3, &w, &h, NULL);
1050 if (edgefract > 0.0) {
1051 pix2 = pixMakeSymmetricMask(w, h, edgefract, edgefract,
L_USE_INNER);
1052 pixAnd(pixm3, pixm3, pix2);
1055 if (pixadb) pixaAddPix(pixadb, pixm3,
L_COPY);
1058 pixCountPixels(pixm3, &count, NULL);
1059 *pcolorfract = (l_float32)count / ((l_float32)(w) * h);
1062 L_INFO(
"no light color pixels found\n", __func__);
1064 L_INFO(
"fraction of light color pixels = %5.3f\n", __func__,
1069 if (pixadb && count > 0) {
1071 pix3 = pixCreateTemplate(pixs);
1073 pixCombineMasked(pix3, pixs, pixm3);
1074 pixaAddPix(pixadb, pix3,
L_INSERT);
1077 pix3 = pixCloseSafeBrick(NULL, pixm3, 15, 15);
1078 pixaAddPix(pixadb, pix3,
L_INSERT);
1079 pix5 = pixCreateTemplate(pixs);
1081 pixCombineMasked(pix5, pixs, pix3);
1082 pixaAddPix(pixadb, pix5,
L_INSERT);
1086 boxa1 = pixConnCompBB(pix3, 8);
1087 boxa2 = boxaCombineOverlaps(boxa1, NULL);
1088 pix4 = pixCreateTemplate(pix3);
1090 pixaAddPix(pixadb, pix4,
L_INSERT);
1091 pix5 = pixCreateTemplate(pixs);
1093 pixCombineMasked(pix5, pixs, pix4);
1094 pixaAddPix(pixadb, pix5,
L_INSERT);
1095 boxaDestroy(&boxa1);
1096 boxaDestroy(&boxa2);
1098 pixaAddPix(pixadb, pixs,
L_COPY);
1101 if (pcolormask2 && count > 0)
1102 *pcolormask2 = pixCloseSafeBrick(NULL, pixm3, 15, 15);
1103 if (pcolormask1 && count > 0)
1104 *pcolormask1 = pixm3;
1274l_int32 w, h, d, minside, factor;
1275l_float32 pixfract, colorfract;
1276PIX *pixt, *pixsc, *pixg, *pixe, *pixb, *pixm;
1279 if (piscolor) *piscolor = 0;
1281 return ERROR_INT(
"&ncolors not defined", __func__, 1);
1284 return ERROR_INT(
"pixs not defined", __func__, 1);
1285 if ((cmap = pixGetColormap(pixs)) != NULL) {
1286 *pncolors = pixcmapGetCount(cmap);
1288 pixcmapHasColor(cmap, piscolor);
1292 pixGetDimensions(pixs, &w, &h, &d);
1293 if (d != 8 && d != 32)
1294 return ERROR_INT(
"pixs not 8 or 32 bpp", __func__, 1);
1303 minside = L_MIN(w, h);
1305 pixt = pixClone(pixs);
1307 factor = L_MAX(1, minside / 400);
1309 if (pixfract * colorfract < 0.00025) {
1310 pixt = pixGetRGBComponent(pixs,
COLOR_RED);
1313 pixt = pixClone(pixs);
1324 factor = L_MAX(1, minside / 500);
1326 pixsc = pixCopy(NULL, pixt);
1327 else if (factor == 2 || factor == 3)
1328 pixsc = pixScaleAreaMap2(pixt);
1330 pixsc = pixScaleAreaMap(pixt, 0.25, 0.25);
1343 pixg = pixClone(pixsc);
1345 pixg = pixConvertRGBToLuminance(pixsc);
1347 pixb = pixThresholdToBinary(pixe, thresh);
1348 pixInvert(pixb, pixb);
1350 pixm = pixMorphSequence(pixb,
"d3.3", 0);
1352 pixm = pixMorphSequence(pixb,
"d7.7", 0);
1363 pixSetMasked(pixg, pixm, 0xff);
1364 if (debug) pixWrite(
"junkpix8.png", pixg, IFF_PNG);
1367 pixSetMasked(pixsc, pixm, 0xffffffff);
1368 if (debug) pixWrite(
"junkpix32.png", pixsc, IFF_PNG);
1369 pixNumberOccupiedOctcubes(pixsc, 4, 20, -1, pncolors);
1412l_int32 w, h, d, i, j, wpl, hashsize, sum, count, manycolors;
1413l_int32 rval, gval, bval, val;
1416l_uint32 *data, *line;
1420 return ERROR_INT(
"&ncolors not defined", __func__, 1);
1423 return ERROR_INT(
"pixs not defined", __func__, 1);
1424 pixGetDimensions(pixs, &w, &h, &d);
1425 if (d != 2 && d != 4 && d != 8 && d != 32)
1426 return ERROR_INT(
"d not in {2, 4, 8, 32}", __func__, 1);
1427 if (factor < 1) factor = 1;
1429 data = pixGetData(pixs);
1430 wpl = pixGetWpl(pixs);
1433 inta = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1434 for (i = 0; i < h; i += factor) {
1435 line = data + i * wpl;
1436 for (j = 0; j < w; j += factor) {
1446 for (i = 0; i < 256; i++)
1451 cmap = pixGetColormap(pixs);
1452 if (cmap && factor == 1) {
1453 count = pixcmapGetCount(cmap);
1455 L_WARNING(
"colormap size %d differs from actual colors\n",
1463 inta = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1465 for (i = 0; i < h && manycolors == 0; i += factor) {
1466 line = data + i * wpl;
1467 for (j = 0; j < w; j += factor) {
1469 extractRGBValues(pixel, &rval, &gval, &bval);
1470 val = (137 * rval + 269 * gval + 353 * bval) % hashsize;
1471 if (inta[val] == 0) {
1483 if (manycolors == 0) {
1489 return pixCountRGBColorsByHash(pixs, pncolors);
1511l_int32 w, h, d, i, j, wpls, wpld, hashsize, hashval, ncolors, index;
1512l_int32 rval, gval, bval, val;
1513l_int32 *hasha1, *hasha2;
1515l_uint32 *datas, *lines, *datad, *lined;
1519 if (!pixs || pixGetDepth(pixs) != 32)
1520 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
1523 if (ncolors > 256) {
1524 L_ERROR(
"too many colors found: %d\n", __func__, ncolors);
1528 pixGetDimensions(pixs, &w, &h, NULL);
1531 else if (ncolors <= 4)
1533 else if (ncolors <= 16)
1538 if ((pixd = pixCreate(w, h, d)) == NULL)
1539 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1540 cmap = pixcmapCreate(d);
1541 datas = pixGetData(pixs);
1542 wpls = pixGetWpl(pixs);
1543 datad = pixGetData(pixd);
1544 wpld = pixGetWpl(pixd);
1551 hasha1 = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1552 hasha2 = (l_int32 *)LEPT_CALLOC(hashsize,
sizeof(l_int32));
1554 for (i = 0; i < h; i++) {
1555 lines = datas + i * wpls;
1556 lined = datad + i * wpld;
1557 for (j = 0; j < w; j++) {
1559 extractRGBValues(pixel, &rval, &gval, &bval);
1560 hashval = (137 * rval + 269 * gval + 353 * bval) % hashsize;
1561 if (hasha1[hashval] == 0) {
1562 hasha1[hashval] = 1;
1564 hasha2[hashval] = index;
1565 pixcmapAddColor(cmap, rval, gval, bval);
1567 val = hasha2[hashval];
1568 setLineDataVal(lined, j, d, val);
1571 pixSetColormap(pixd, cmap);
1611l_int32 n, i, rgbindex, rval, gval, bval;
1612NUMA *nahisto, *naindex;
1614 if (!parray && !pcmap)
1615 return ERROR_INT(
"no return val requested", __func__, 1);
1616 if (parray) *parray = NULL;
1617 if (pcmap) *pcmap = NULL;
1618 if (!pixs || pixGetDepth(pixs) != 32)
1619 return ERROR_INT(
"pixs not defined", __func__, 1);
1620 if (sigbits < 2 || sigbits > 6)
1621 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1622 if (factor < 1 || ncolors < 1)
1623 return ERROR_INT(
"factor < 1 or ncolors < 1", __func__, 1);
1626 return ERROR_INT(
"nahisto not made", __func__, 1);
1630 numaDestroy(&nahisto);
1632 return ERROR_INT(
"naindex not made", __func__, 1);
1634 n = numaGetCount(naindex);
1635 ncolors = L_MIN(n, ncolors);
1636 if (parray) *parray = (l_uint32 *)LEPT_CALLOC(ncolors,
sizeof(l_uint32));
1637 if (pcmap) *pcmap = pixcmapCreate(8);
1638 for (i = 0; i < ncolors; i++) {
1639 numaGetIValue(naindex, i, &rgbindex);
1641 if (parray) composeRGBPixel(rval, gval, bval, *parray + i);
1642 if (pcmap) pixcmapAddColor(*pcmap, rval, gval, bval);
1645 numaDestroy(&naindex);
1727l_int32 w, h, i, j, size, wpl, rval, gval, bval, npts;
1728l_uint32 val32, rgbindex;
1730l_uint32 *data, *line, *rtab, *gtab, *btab;
1733 if (!pixs || pixGetDepth(pixs) != 32)
1734 return (
NUMA *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1735 if (sigbits < 2 || sigbits > 6)
1736 return (
NUMA *)ERROR_PTR(
"sigbits not in [2 ... 6]", __func__, NULL);
1738 return (
NUMA *)ERROR_PTR(
"factor < 1", __func__, NULL);
1741 size = 1 << (3 * sigbits);
1742 na = numaMakeConstant(0, size);
1743 array = numaGetFArray(na,
L_NOCOPY);
1748 pixGetDimensions(pixs, &w, &h, NULL);
1749 npts = ((w + factor - 1) / factor) * ((h + factor - 1) / factor);
1751 L_WARNING(
"only sampling %d pixels\n", __func__, npts);
1752 wpl = pixGetWpl(pixs);
1753 data = pixGetData(pixs);
1754 for (i = 0; i < h; i += factor) {
1755 line = data + i * wpl;
1756 for (j = 0; j < w; j += factor) {
1757 val32 = *(line + j);
1758 extractRGBValues(val32, &rval, &gval, &bval);
1759 rgbindex = rtab[rval] | gtab[gval] | btab[bval];
1795l_uint32 *rtab, *gtab, *btab;
1797 if (prtab) *prtab = NULL;
1798 if (pgtab) *pgtab = NULL;
1799 if (pbtab) *pbtab = NULL;
1800 if (!prtab || !pgtab || !pbtab)
1801 return ERROR_INT(
"not all table ptrs defined", __func__, 1);
1802 if (sigbits < 2 || sigbits > 6)
1803 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1805 rtab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1806 gtab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1807 btab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1808 if (!rtab || !gtab || !btab) {
1812 return ERROR_INT(
"calloc fail for tab", __func__, 1);
1819 for (i = 0; i < 256; i++) {
1820 rtab[i] = (i & 0xc0) >> 2;
1821 gtab[i] = (i & 0xc0) >> 4;
1822 btab[i] = (i & 0xc0) >> 6;
1826 for (i = 0; i < 256; i++) {
1827 rtab[i] = (i & 0xe0) << 1;
1828 gtab[i] = (i & 0xe0) >> 2;
1829 btab[i] = (i & 0xe0) >> 5;
1833 for (i = 0; i < 256; i++) {
1834 rtab[i] = (i & 0xf0) << 4;
1835 gtab[i] = (i & 0xf0);
1836 btab[i] = (i & 0xf0) >> 4;
1840 for (i = 0; i < 256; i++) {
1841 rtab[i] = (i & 0xf8) << 7;
1842 gtab[i] = (i & 0xf8) << 2;
1843 btab[i] = (i & 0xf8) >> 3;
1847 for (i = 0; i < 256; i++) {
1848 rtab[i] = (i & 0xfc) << 10;
1849 gtab[i] = (i & 0xfc) << 4;
1850 btab[i] = (i & 0xfc) >> 2;
1854 L_ERROR(
"Illegal sigbits = %d\n", __func__, sigbits);
1855 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1887 if (prval) *prval = 0;
1888 if (pgval) *pgval = 0;
1889 if (pbval) *pbval = 0;
1890 if (!prval || !pgval || !pbval)
1891 return ERROR_INT(
"not all component ptrs defined", __func__, 1);
1892 if (sigbits < 2 || sigbits > 6)
1893 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1897 *prval = ((index << 2) & 0xc0) | 0x20;
1898 *pgval = ((index << 4) & 0xc0) | 0x20;
1899 *pbval = ((index << 6) & 0xc0) | 0x20;
1902 *prval = ((index >> 1) & 0xe0) | 0x10;
1903 *pgval = ((index << 2) & 0xe0) | 0x10;
1904 *pbval = ((index << 5) & 0xe0) | 0x10;
1907 *prval = ((index >> 4) & 0xf0) | 0x08;
1908 *pgval = (index & 0xf0) | 0x08;
1909 *pbval = ((index << 4) & 0xf0) | 0x08;
1912 *prval = ((index >> 7) & 0xf8) | 0x04;
1913 *pgval = ((index >> 2) & 0xf8) | 0x04;
1914 *pbval = ((index << 3) & 0xf8) | 0x04;
1917 *prval = ((index >> 10) & 0xfc) | 0x02;
1918 *pgval = ((index >> 4) & 0xfc) | 0x02;
1919 *pbval = ((index << 2) & 0xfc) | 0x02;
1922 L_ERROR(
"Illegal sigbits = %d\n", __func__, sigbits);
1923 return ERROR_INT(
"sigbits not in [2 ... 6]", __func__, 1);
1970l_float32 fract, ratio;
1971PIX *pix1, *pix2, *pix3, *pix4;
1974 if (pratio) *pratio = 0.0;
1975 if (ppixdb) *ppixdb = NULL;
1976 if (phasred) *phasred = 0;
1977 if (!pratio && !ppixdb)
1978 return ERROR_INT(
"no return val requested", __func__, 1);
1980 return ERROR_INT(
"&hasred not defined", __func__, 1);
1981 if (!pixs || pixGetDepth(pixs) != 32)
1982 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
1983 if (minfract <= 0.0)
1984 return ERROR_INT(
"minfract must be > 0.0", __func__, 1);
1985 if (fthresh < 1.5 || fthresh > 3.5)
1986 L_WARNING(
"fthresh = %f is out of normal bounds\n", __func__, fthresh);
1989 pix1 = pixScaleByIntSampling(pixs, factor);
1991 pix1 = pixClone(pixs);
1994 fpix = pixComponentFunction(pix1, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0);
1995 pix2 = fpixThresholdToPix(fpix, fthresh);
1996 pixInvert(pix2, pix2);
1999 pix3 = pixGetRGBComponent(pix1,
COLOR_RED);
2000 pix4 = pixThresholdToBinary(pix3, 130);
2001 pixInvert(pix4, pix4);
2003 pixAnd(pix4, pix4, pix2);
2004 pixForegroundFraction(pix4, &fract);
2005 ratio = fract / minfract;
2006 L_INFO(
"fract = %7.5f, ratio = %7.3f\n", __func__, fract, ratio);
2007 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()