141#include <config_auto.h>
144#include "allheaders.h"
163 l_int32 mindiff, l_int32 smoothx, l_int32 smoothy,
164 PIX **ppixmin,
PIX **ppixmax);
167 PIX *pixmin,
PIX *pixmax);
173#define DEBUG_GLOBAL 0
215 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
216 d = pixGetDepth(pixs);
217 if (d != 8 && d != 32)
218 return (
PIX *)ERROR_PTR(
"depth not 8 or 32", __func__, NULL);
219 if (whiteval > 200) {
220 L_WARNING(
"white value %d must not exceed 200; reset to 190",
227 return (
PIX *)ERROR_PTR(
"background norm failedd", __func__, NULL);
228 pixGammaTRC(pixd, pixd, gamma, blackval, whiteval);
340PIX *pixm, *pixmi, *pixd;
341PIX *pixmr, *pixmg, *pixmb, *pixmri, *pixmgi, *pixmbi;
344 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
345 d = pixGetDepth(pixs);
346 if (d != 8 && d != 32)
347 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
348 if (sx < 4 || sy < 4)
349 return (
PIX *)ERROR_PTR(
"sx and sy must be >= 4", __func__, NULL);
350 if (mincount > sx * sy) {
351 L_WARNING(
"mincount too large for tile size\n", __func__);
352 mincount = (sx * sy) / 3;
357 pixInvert(pixim, pixim);
358 pixZero(pixim, &allfg);
359 pixInvert(pixim, pixim);
361 return (
PIX *)ERROR_PTR(
"pixim all foreground", __func__, NULL);
369 L_WARNING(
"map not made; return a copy of the source\n", __func__);
370 return pixCopy(NULL, pixs);
375 L_WARNING(
"pixmi not made; return a copy of source\n", __func__);
377 return pixCopy(NULL, pixs);
386 pixmr = pixmg = pixmb = NULL;
388 mincount, &pixmr, &pixmg, &pixmb);
389 if (!pixmr || !pixmg || !pixmb) {
393 L_WARNING(
"map not made; return a copy of the source\n", __func__);
394 return pixCopy(NULL, pixs);
400 if (!pixmri || !pixmgi || !pixmbi) {
401 L_WARNING(
"not all pixm*i are made; return src copy\n", __func__);
402 pixd = pixCopy(NULL, pixs);
417 ERROR_PTR(
"pixd not made", __func__, NULL);
418 pixCopyResolution(pixd, pixs);
470PIX *pixm, *pixmi, *pixd;
471PIX *pixmr, *pixmg, *pixmb, *pixmri, *pixmgi, *pixmbi;
474 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
475 d = pixGetDepth(pixs);
476 if (d != 8 && d != 32)
477 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
478 if (reduction < 2 || reduction > 16)
479 return (
PIX *)ERROR_PTR(
"reduction must be between 2 and 16",
484 pixInvert(pixim, pixim);
485 pixZero(pixim, &allfg);
486 pixInvert(pixim, pixim);
488 return (
PIX *)ERROR_PTR(
"pixim all foreground", __func__, NULL);
495 return (
PIX *)ERROR_PTR(
"pixm not made", __func__, NULL);
498 ERROR_PTR(
"pixmi not made", __func__, NULL);
501 reduction, reduction);
506 pixmr = pixmg = pixmb = NULL;
508 &pixmr, &pixmg, &pixmb);
509 if (!pixmr || !pixmg || !pixmb) {
513 return (
PIX *)ERROR_PTR(
"not all pixm*", __func__, NULL);
519 if (!pixmri || !pixmgi || !pixmbi)
520 ERROR_PTR(
"not all pixm*i are made", __func__, NULL);
523 reduction, reduction);
534 ERROR_PTR(
"pixd not made", __func__, NULL);
535 pixCopyResolution(pixd, pixs);
587 return ERROR_INT(
"&pixd not defined", __func__, 1);
589 if (!pixs || pixGetDepth(pixs) != 8)
590 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
591 if (pixGetColormap(pixs))
592 return ERROR_INT(
"pixs is colormapped", __func__, 1);
593 if (pixim && pixGetDepth(pixim) != 1)
594 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
595 if (sx < 4 || sy < 4)
596 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
597 if (mincount > sx * sy) {
598 L_WARNING(
"mincount too large for tile size\n", __func__);
599 mincount = (sx * sy) / 3;
604 pixInvert(pixim, pixim);
605 pixZero(pixim, &allfg);
606 pixInvert(pixim, pixim);
608 return ERROR_INT(
"pixim all foreground", __func__, 1);
613 return ERROR_INT(
"pixm not made", __func__, 1);
615 pixCopyResolution(*ppixd, pixs);
662PIX *pixmr, *pixmg, *pixmb;
664 if (!ppixr || !ppixg || !ppixb)
665 return ERROR_INT(
"&pixr, &pixg, &pixb not all defined", __func__, 1);
666 *ppixr = *ppixg = *ppixb = NULL;
668 return ERROR_INT(
"pixs not defined", __func__, 1);
669 if (pixGetDepth(pixs) != 32)
670 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
671 if (pixim && pixGetDepth(pixim) != 1)
672 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
673 if (sx < 4 || sy < 4)
674 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
675 if (mincount > sx * sy) {
676 L_WARNING(
"mincount too large for tile size\n", __func__);
677 mincount = (sx * sy) / 3;
682 pixInvert(pixim, pixim);
683 pixZero(pixim, &allfg);
684 pixInvert(pixim, pixim);
686 return ERROR_INT(
"pixim all foreground", __func__, 1);
690 &pixmr, &pixmg, &pixmb);
691 if (!pixmr || !pixmg || !pixmb) {
695 return ERROR_INT(
"not all pixm* made", __func__, 1);
739 return ERROR_INT(
"&pixd not defined", __func__, 1);
742 return ERROR_INT(
"pixs not defined", __func__, 1);
743 if (pixGetDepth(pixs) != 8)
744 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
745 if (pixim && pixGetDepth(pixim) != 1)
746 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
747 if (reduction < 2 || reduction > 16)
748 return ERROR_INT(
"reduction must be between 2 and 16", __func__, 1);
752 pixInvert(pixim, pixim);
753 pixZero(pixim, &allfg);
754 pixInvert(pixim, pixim);
756 return ERROR_INT(
"pixim all foreground", __func__, 1);
761 return ERROR_INT(
"pixm not made", __func__, 1);
763 pixCopyResolution(*ppixd, pixs);
801PIX *pixmr, *pixmg, *pixmb;
803 if (!ppixr || !ppixg || !ppixb)
804 return ERROR_INT(
"&pixr, &pixg, &pixb not all defined", __func__, 1);
805 *ppixr = *ppixg = *ppixb = NULL;
807 return ERROR_INT(
"pixs not defined", __func__, 1);
808 if (pixGetDepth(pixs) != 32)
809 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
810 if (pixim && pixGetDepth(pixim) != 1)
811 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
812 if (reduction < 2 || reduction > 16)
813 return ERROR_INT(
"reduction must be between 2 and 16", __func__, 1);
817 pixInvert(pixim, pixim);
818 pixZero(pixim, &allfg);
819 pixInvert(pixim, pixim);
821 return ERROR_INT(
"pixim all foreground", __func__, 1);
825 &pixmr, &pixmg, &pixmb);
826 if (!pixmr || !pixmg || !pixmb) {
830 return ERROR_INT(
"not all pixm* made", __func__, 1);
874l_int32 w, h, wd, hd, wim, him, wpls, wplim, wpld, wplf;
875l_int32 xim, yim, delx, nx, ny, i, j, k, m;
876l_int32 count, sum, val8;
877l_int32 empty, fgpixels;
878l_uint32 *datas, *dataim, *datad, *dataf, *lines, *lineim, *lined, *linef;
879l_float32 scalex, scaley;
880PIX *pixd, *piximi, *pixb, *pixf, *pixims;
883 return ERROR_INT(
"&pixd not defined", __func__, 1);
885 if (!pixs || pixGetDepth(pixs) != 8)
886 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
887 if (pixGetColormap(pixs))
888 return ERROR_INT(
"pixs is colormapped", __func__, 1);
889 if (pixim && pixGetDepth(pixim) != 1)
890 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
891 if (sx < 4 || sy < 4)
892 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
893 if (mincount > sx * sy) {
894 L_WARNING(
"mincount too large for tile size\n", __func__);
895 mincount = (sx * sy) / 3;
902 piximi = pixInvert(NULL, pixim);
903 pixZero(piximi, &empty);
906 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
907 pixZero(pixim, &empty);
915 pixb = pixThresholdToBinary(pixs, thresh);
916 pixf = pixMorphSequence(pixb,
"d7.1 + d1.7", 0);
919 return ERROR_INT(
"pixf not made", __func__, 1);
924 w = pixGetWidth(pixs);
925 h = pixGetHeight(pixs);
926 wd = (w + sx - 1) / sx;
927 hd = (h + sy - 1) / sy;
928 pixd = pixCreate(wd, hd, 8);
935 wpls = pixGetWpl(pixs);
936 datas = pixGetData(pixs);
937 wpld = pixGetWpl(pixd);
938 datad = pixGetData(pixd);
939 wplf = pixGetWpl(pixf);
940 dataf = pixGetData(pixf);
941 for (i = 0; i < ny; i++) {
942 lines = datas + sy * i * wpls;
943 linef = dataf + sy * i * wplf;
944 lined = datad + i * wpld;
945 for (j = 0; j < nx; j++) {
949 for (k = 0; k < sy; k++) {
950 for (m = 0; m < sx; m++) {
957 if (count >= mincount) {
976 if (pixim && fgpixels) {
977 wim = pixGetWidth(pixim);
978 him = pixGetHeight(pixim);
979 dataim = pixGetData(pixim);
980 wplim = pixGetWpl(pixim);
981 for (i = 0; i < ny; i++) {
982 yim = i * sy + sy / 2;
985 lineim = dataim + yim * wplim;
986 for (j = 0; j < nx; j++) {
987 xim = j * sx + sx / 2;
991 pixSetPixel(pixd, j, i, 0);
999 L_WARNING(
"can't make the map\n", __func__);
1008 if (pixim && fgpixels) {
1009 scalex = 1. / (l_float32)sx;
1010 scaley = 1. / (l_float32)sy;
1011 pixims = pixScaleBySampling(pixim, scalex, scaley);
1013 pixDestroy(&pixims);
1017 pixCopyResolution(*ppixd, pixs);
1057l_int32 w, h, wm, hm, wim, him, wpls, wplim, wplf;
1058l_int32 xim, yim, delx, nx, ny, i, j, k, m;
1059l_int32 count, rsum, gsum, bsum, rval, gval, bval;
1060l_int32 empty, fgpixels;
1062l_uint32 *datas, *dataim, *dataf, *lines, *lineim, *linef;
1063l_float32 scalex, scaley;
1064PIX *piximi, *pixgc, *pixb, *pixf, *pixims;
1065PIX *pixmr, *pixmg, *pixmb;
1067 if (!ppixmr || !ppixmg || !ppixmb)
1068 return ERROR_INT(
"&pixm* not all defined", __func__, 1);
1069 *ppixmr = *ppixmg = *ppixmb = NULL;
1071 return ERROR_INT(
"pixs not defined", __func__, 1);
1072 if (pixGetDepth(pixs) != 32)
1073 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
1074 if (pixim && pixGetDepth(pixim) != 1)
1075 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1076 if (sx < 4 || sy < 4)
1077 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
1078 if (mincount > sx * sy) {
1079 L_WARNING(
"mincount too large for tile size\n", __func__);
1080 mincount = (sx * sy) / 3;
1086 piximi = pixInvert(NULL, pixim);
1087 pixZero(piximi, &empty);
1088 pixDestroy(&piximi);
1090 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1091 pixZero(pixim, &empty);
1099 pixgc = pixClone(pixg);
1101 pixgc = pixConvertRGBToGrayFast(pixs);
1102 pixb = pixThresholdToBinary(pixgc, thresh);
1103 pixf = pixMorphSequence(pixb,
"d7.1 + d1.7", 0);
1108 w = pixGetWidth(pixs);
1109 h = pixGetHeight(pixs);
1110 wm = (w + sx - 1) / sx;
1111 hm = (h + sy - 1) / sy;
1112 pixmr = pixCreate(wm, hm, 8);
1113 pixmg = pixCreate(wm, hm, 8);
1114 pixmb = pixCreate(wm, hm, 8);
1122 wpls = pixGetWpl(pixs);
1123 datas = pixGetData(pixs);
1124 wplf = pixGetWpl(pixf);
1125 dataf = pixGetData(pixf);
1126 for (i = 0; i < ny; i++) {
1127 lines = datas + sy * i * wpls;
1128 linef = dataf + sy * i * wplf;
1129 for (j = 0; j < nx; j++) {
1131 rsum = gsum = bsum = 0;
1133 for (k = 0; k < sy; k++) {
1134 for (m = 0; m < sx; m++) {
1136 pixel = *(lines + k * wpls + delx + m);
1137 rsum += (pixel >> 24);
1138 gsum += ((pixel >> 16) & 0xff);
1139 bsum += ((pixel >> 8) & 0xff);
1144 if (count >= mincount) {
1145 rval = rsum / count;
1146 gval = gsum / count;
1147 bval = bsum / count;
1148 pixSetPixel(pixmr, j, i, rval);
1149 pixSetPixel(pixmg, j, i, gval);
1150 pixSetPixel(pixmb, j, i, bval);
1162 wim = pixGetWidth(pixim);
1163 him = pixGetHeight(pixim);
1164 dataim = pixGetData(pixim);
1165 wplim = pixGetWpl(pixim);
1166 for (i = 0; i < ny; i++) {
1167 yim = i * sy + sy / 2;
1170 lineim = dataim + yim * wplim;
1171 for (j = 0; j < nx; j++) {
1172 xim = j * sx + sx / 2;
1176 pixSetPixel(pixmr, j, i, 0);
1177 pixSetPixel(pixmg, j, i, 0);
1178 pixSetPixel(pixmb, j, i, 0);
1191 L_WARNING(
"can't make the maps\n", __func__);
1197 if (pixim && fgpixels) {
1198 scalex = 1. / (l_float32)sx;
1199 scaley = 1. / (l_float32)sy;
1200 pixims = pixScaleBySampling(pixim, scalex, scaley);
1204 pixDestroy(&pixims);
1210 pixCopyResolution(*ppixmr, pixs);
1211 pixCopyResolution(*ppixmg, pixs);
1212 pixCopyResolution(*ppixmb, pixs);
1235l_int32 nx, ny, empty, fgpixels;
1237PIX *pixm, *pix1, *pix2, *pix3, *pixims;
1240 return ERROR_INT(
"&pixm not defined", __func__, 1);
1242 if (!pixs || pixGetDepth(pixs) != 8)
1243 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
1244 if (pixGetColormap(pixs))
1245 return ERROR_INT(
"pixs is colormapped", __func__, 1);
1246 if (pixim && pixGetDepth(pixim) != 1)
1247 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1252 pixInvert(pixim, pixim);
1253 pixZero(pixim, &empty);
1255 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1256 pixInvert(pixim, pixim);
1257 pixZero(pixim, &empty);
1263 scale = 1. / (l_float32)reduction;
1264 pix1 = pixScaleBySampling(pixs, scale, scale);
1265 pix2 = pixCloseGray(pix1, size, size);
1274 pixims = pixScale(pixim, scale, scale);
1275 pixm = pixConvertTo8(pixims, FALSE);
1276 pixAnd(pixm, pixm, pix3);
1279 pixm = pixClone(pix3);
1283 nx = pixGetWidth(pixs) / reduction;
1284 ny = pixGetHeight(pixs) / reduction;
1287 pixDestroy(&pixims);
1288 L_WARNING(
"can't make the map\n", __func__);
1294 if (pixim && fgpixels)
1296 pixDestroy(&pixims);
1299 pixCopyResolution(*ppixm, pixs);
1326l_int32 nx, ny, empty, fgpixels;
1328PIX *pixm, *pixmr, *pixmg, *pixmb, *pix1, *pix2, *pix3, *pixims;
1330 if (!ppixmr || !ppixmg || !ppixmb)
1331 return ERROR_INT(
"&pixm* not all defined", __func__, 1);
1332 *ppixmr = *ppixmg = *ppixmb = NULL;
1334 return ERROR_INT(
"pixs not defined", __func__, 1);
1335 if (pixGetDepth(pixs) != 32)
1336 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
1337 if (pixim && pixGetDepth(pixim) != 1)
1338 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1343 pixInvert(pixim, pixim);
1344 pixZero(pixim, &empty);
1346 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1347 pixInvert(pixim, pixim);
1348 pixZero(pixim, &empty);
1354 scale = 1. / (l_float32)reduction;
1358 pixims = pixScale(pixim, scale, scale);
1359 pixm = pixConvertTo8(pixims, FALSE);
1365 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_RED);
1366 pix2 = pixCloseGray(pix1, size, size);
1369 pixmr = pixAnd(NULL, pixm, pix3);
1371 pixmr = pixClone(pix3);
1376 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_GREEN);
1377 pix2 = pixCloseGray(pix1, size, size);
1380 pixmg = pixAnd(NULL, pixm, pix3);
1382 pixmg = pixClone(pix3);
1387 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_BLUE);
1388 pix2 = pixCloseGray(pix1, size, size);
1391 pixmb = pixAnd(NULL, pixm, pix3);
1393 pixmb = pixClone(pix3);
1400 nx = pixGetWidth(pixs) / reduction;
1401 ny = pixGetHeight(pixs) / reduction;
1408 pixDestroy(&pixims);
1409 L_WARNING(
"can't make the maps\n", __func__);
1416 if (pixim && fgpixels) {
1420 pixDestroy(&pixims);
1426 pixCopyResolution(*ppixmr, pixs);
1427 pixCopyResolution(*ppixmg, pixs);
1428 pixCopyResolution(*ppixmb, pixs);
1475l_int32 w, h, y, nmiss, goodcol, i, j, found, ival, valtest;
1476l_uint32 val, lastval;
1479 if (!pix || pixGetDepth(pix) != 8)
1480 return ERROR_INT(
"pix not defined or not 8 bpp", __func__, 1);
1481 if (pixGetColormap(pix))
1482 return ERROR_INT(
"pix is colormapped", __func__, 1);
1485 pixGetDimensions(pix, &w, &h, NULL);
1489 for (j = 0; j < nx; j++) {
1491 for (i = 0; i < ny; i++) {
1492 pixGetPixel(pix, j, i, &val);
1493 if (val != valtest) {
1499 if (found == FALSE) {
1500 numaAddNumber(na, 0);
1504 numaAddNumber(na, 1);
1505 for (i = y - 1; i >= 0; i--)
1506 pixSetPixel(pix, j, i, val);
1507 pixGetPixel(pix, j, 0, &lastval);
1508 for (i = 1; i < h; i++) {
1509 pixGetPixel(pix, j, i, &val);
1511 pixSetPixel(pix, j, i, lastval);
1520 L_WARNING(
"no bg found; no data in any column\n", __func__);
1528 for (j = 0; j < w; j++) {
1529 numaGetIValue(na, j, &ival);
1536 for (j = goodcol - 1; j >= 0; j--)
1537 pixRasterop(pix, j, 0, 1, h,
PIX_SRC, pix, j + 1, 0);
1539 for (j = goodcol + 1; j < w; j++) {
1540 numaGetIValue(na, j, &ival);
1543 pixRasterop(pix, j, 0, 1, h,
PIX_SRC, pix, j - 1, 0);
1548 pixRasterop(pix, w - 1, 0, 1, h,
PIX_SRC, pix, w - 2, 0);
1578 if (!pixs || pixGetDepth(pixs) != 8)
1579 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1581 if (addw == 0 && addh == 0)
1582 return pixCopy(NULL, pixs);
1584 pixGetDimensions(pixs, &w, &h, NULL);
1585 if ((pixd = pixCreate(w + addw, h + addh, 8)) == NULL)
1586 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1587 pixRasterop(pixd, 0, 0, w, h,
PIX_SRC, pixs, 0, 0);
1590 for (i = 0; i < h; i++) {
1591 pixGetPixel(pixd, w - 1, i, &val);
1592 for (j = 0; j < addw; j++)
1593 pixSetPixel(pixd, w + j, i, val);
1598 for (j = 0; j < w + addw; j++) {
1599 pixGetPixel(pixd, j, h - 1, &val);
1600 for (i = 0; i < addh; i++)
1601 pixSetPixel(pixd, j, h + i, val);
1605 pixCopyResolution(pixd, pixs);
1635l_int32 empty, i, n, x, y;
1641 if (!pixs || pixGetDepth(pixs) != 8)
1642 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
1643 if (pixGetColormap(pixs))
1644 return ERROR_INT(
"pixs has colormap", __func__, 1);
1646 L_INFO(
"pixm not defined\n", __func__);
1649 if (pixGetDepth(pixm) != 1)
1650 return ERROR_INT(
"pixm not 1 bpp", __func__, 1);
1651 pixZero(pixm, &empty);
1653 L_INFO(
"pixm has no fg pixels; nothing to do\n", __func__);
1657 boxa = pixConnComp(pixm, &pixa, 8);
1658 n = boxaGetCount(boxa);
1659 for (i = 0; i < n; i++) {
1660 if ((pixmc = pixaGetPix(pixa, i,
L_CLONE)) == NULL) {
1661 L_WARNING(
"missing pixmc!\n", __func__);
1664 boxaGetBoxGeometry(boxa, i, &x, &y, NULL, NULL);
1665 pixGetAverageMasked(pixs, pixmc, x, y, factor,
L_MEAN_ABSVAL, &aveval);
1666 pixPaintThroughMask(pixs, pixmc, x, y, (l_int32)aveval);
1718pixGetForegroundGrayMap(
PIX *pixs,
1725l_int32 w, h, d, wd, hd;
1726l_int32 empty, fgpixels;
1727PIX *pixd, *piximi, *pixim2, *pixims, *pixs2, *pixb, *pixt1, *pixt2, *pixt3;
1730 return ERROR_INT(
"&pixd not defined", __func__, 1);
1733 return ERROR_INT(
"pixs not defined", __func__, 1);
1734 pixGetDimensions(pixs, &w, &h, &d);
1736 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
1737 if (pixim && pixGetDepth(pixim) != 1)
1738 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1739 if (sx < 2 || sy < 2)
1740 return ERROR_INT(
"sx and sy must be >= 2", __func__, 1);
1743 wd = (w + sx - 1) / sx;
1744 hd = (h + sy - 1) / sy;
1745 pixd = pixCreate(wd, hd, 8);
1752 piximi = pixInvert(NULL, pixim);
1753 pixZero(piximi, &empty);
1754 pixDestroy(&piximi);
1757 pixZero(pixim, &empty);
1763 pixs2 = pixScaleBySampling(pixs, 0.5, 0.5);
1764 if (pixim && fgpixels) {
1765 pixim2 = pixReduceBinary2(pixim, NULL);
1766 pixPaintThroughMask(pixs2, pixim2, 0, 0, 255);
1767 pixDestroy(&pixim2);
1771 pixt1 = pixScaleGrayMinMax(pixs2, sx, sy, L_CHOOSE_MIN);
1776 pixb = pixThresholdToBinary(pixt1, thresh);
1777 pixInvert(pixb, pixb);
1778 pixPaintThroughMask(pixt1, pixb, 0, 0, 255);
1782 pixt2 = pixExpandReplicate(pixt1, 2);
1792 pixt3 = pixBlockconv(pixt2, 8, 8);
1793 pixRasterop(pixd, 0, 0, wd, hd,
PIX_SRC, pixt3, 0, 0);
1796 pixims = pixScaleBySampling(pixim, 1. / sx, 1. / sy);
1797 pixPaintThroughMask(pixd, pixims, 0, 0, 0);
1833l_int32 w, h, wplsm, wpld, i, j;
1835l_uint32 *datasm, *datad, *linesm, *lined;
1838 if (!pixs || pixGetDepth(pixs) != 8)
1839 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1840 if (pixGetColormap(pixs))
1841 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1842 pixGetDimensions(pixs, &w, &h, NULL);
1844 return (
PIX *)ERROR_PTR(
"w and h must be >= 5", __func__, NULL);
1847 pixsm = pixBlockconv(pixs, smoothx, smoothy);
1848 datasm = pixGetData(pixsm);
1849 wplsm = pixGetWpl(pixsm);
1852 pixd = pixCreate(w, h, 16);
1853 datad = pixGetData(pixd);
1854 wpld = pixGetWpl(pixd);
1855 for (i = 0; i < h; i++) {
1856 linesm = datasm + i * wplsm;
1857 lined = datad + i * wpld;
1858 for (j = 0; j < w; j++) {
1861 val16 = (256 * bgval) / val;
1863 L_WARNING(
"smoothed bg has 0 pixel!\n", __func__);
1871 pixCopyResolution(pixd, pixs);
1894l_int32 w, h, wm, hm, wpls, wpld, i, j, k, m, xoff, yoff;
1897l_uint32 *datas, *datad, *lines, *lined, *flines, *flined;
1900 if (!pixs || pixGetDepth(pixs) != 8)
1901 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1902 if (pixGetColormap(pixs))
1903 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1904 if (!pixm || pixGetDepth(pixm) != 16)
1905 return (
PIX *)ERROR_PTR(
"pixm undefined or not 16 bpp", __func__, NULL);
1906 if (sx == 0 || sy == 0)
1907 return (
PIX *)ERROR_PTR(
"invalid sx and/or sy", __func__, NULL);
1909 datas = pixGetData(pixs);
1910 wpls = pixGetWpl(pixs);
1911 pixGetDimensions(pixs, &w, &h, NULL);
1912 pixGetDimensions(pixm, &wm, &hm, NULL);
1913 if ((pixd = pixCreateTemplate(pixs)) == NULL)
1914 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1915 datad = pixGetData(pixd);
1916 wpld = pixGetWpl(pixd);
1917 for (i = 0; i < hm; i++) {
1918 lines = datas + sy * i * wpls;
1919 lined = datad + sy * i * wpld;
1921 for (j = 0; j < wm; j++) {
1922 pixGetPixel(pixm, j, i, &val16);
1924 for (k = 0; k < sy && yoff + k < h; k++) {
1925 flines = lines + k * wpls;
1926 flined = lined + k * wpld;
1927 for (m = 0; m < sx && xoff + m < w; m++) {
1929 vald = (vals * val16) / 256;
1930 vald = L_MIN(vald, 255);
1960l_int32 w, h, wm, hm, wpls, wpld, i, j, k, m, xoff, yoff;
1961l_int32 rvald, gvald, bvald;
1963l_uint32 rval16, gval16, bval16;
1964l_uint32 *datas, *datad, *lines, *lined, *flines, *flined;
1968 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1969 if (pixGetDepth(pixs) != 32)
1970 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
1971 if (!pixmr || !pixmg || !pixmb)
1972 return (
PIX *)ERROR_PTR(
"pix maps not all defined", __func__, NULL);
1973 if (pixGetDepth(pixmr) != 16 || pixGetDepth(pixmg) != 16 ||
1974 pixGetDepth(pixmb) != 16)
1975 return (
PIX *)ERROR_PTR(
"pix maps not all 16 bpp", __func__, NULL);
1976 if (sx == 0 || sy == 0)
1977 return (
PIX *)ERROR_PTR(
"invalid sx and/or sy", __func__, NULL);
1979 datas = pixGetData(pixs);
1980 wpls = pixGetWpl(pixs);
1981 w = pixGetWidth(pixs);
1982 h = pixGetHeight(pixs);
1983 wm = pixGetWidth(pixmr);
1984 hm = pixGetHeight(pixmr);
1985 if ((pixd = pixCreateTemplate(pixs)) == NULL)
1986 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1987 datad = pixGetData(pixd);
1988 wpld = pixGetWpl(pixd);
1989 for (i = 0; i < hm; i++) {
1990 lines = datas + sy * i * wpls;
1991 lined = datad + sy * i * wpld;
1993 for (j = 0; j < wm; j++) {
1994 pixGetPixel(pixmr, j, i, &rval16);
1995 pixGetPixel(pixmg, j, i, &gval16);
1996 pixGetPixel(pixmb, j, i, &bval16);
1998 for (k = 0; k < sy && yoff + k < h; k++) {
1999 flines = lines + k * wpls;
2000 flined = lined + k * wpld;
2001 for (m = 0; m < sx && xoff + m < w; m++) {
2002 vals = *(flines + xoff + m);
2003 rvald = ((vals >> 24) * rval16) / 256;
2004 rvald = L_MIN(rvald, 255);
2005 gvald = (((vals >> 16) & 0xff) * gval16) / 256;
2006 gvald = L_MIN(gvald, 255);
2007 bvald = (((vals >> 8) & 0xff) * bval16) / 256;
2008 bvald = L_MIN(bvald, 255);
2009 composeRGBPixel(rvald, gvald, bvald, flined + xoff + m);
2053l_int32 i, j, w, h, d, wpls, wplg, wpld, vals, valg, vald;
2055l_uint32 *datas, *datag, *datad, *lines, *lineg, *lined;
2060 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2062 return (
PIX *)ERROR_PTR(
"pixg not defined", __func__, NULL);
2063 if (!pixSizesEqual(pixs, pixg))
2064 return (
PIX *)ERROR_PTR(
"pix sizes not equal", __func__, NULL);
2065 pixGetDimensions(pixs, &w, &h, &d);
2067 return (
PIX *)ERROR_PTR(
"depth not 8 bpp", __func__, NULL);
2077 if (w * h > 100000) {
2078 lut = (l_uint8 *)LEPT_CALLOC(0x10000,
sizeof(l_uint8));
2079 for (i = 0; i < 256; i++) {
2080 for (j = 0; j < 256; j++) {
2081 fval = (l_float32)(i * target) / (j + 0.5);
2082 lut[(i << 8) + j] = L_MIN(255, (l_int32)(fval + 0.5));
2087 if ((pixd = pixCreate(w, h, 8)) == NULL) {
2089 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2091 pixCopyResolution(pixd, pixs);
2092 datad = pixGetData(pixd);
2093 wpld = pixGetWpl(pixd);
2094 datas = pixGetData(pixs);
2095 wpls = pixGetWpl(pixs);
2096 datag = pixGetData(pixg);
2097 wplg = pixGetWpl(pixg);
2098 for (i = 0; i < h; i++) {
2099 lines = datas + i * wpls;
2100 lineg = datag + i * wplg;
2101 lined = datad + i * wpld;
2103 for (j = 0; j < w; j++) {
2106 vald = lut[(vals << 8) + valg];
2111 for (j = 0; j < w; j++) {
2114 fval = (l_float32)(vals * target) / (valg + 0.5);
2115 vald = L_MIN(255, (l_int32)(fval + 0.5));
2171l_int32 w, h, d, i, j, ncolors, rv, gv, bv, wpl;
2172l_int32 *rarray, *garray, *barray;
2173l_uint32 *data, *line;
2174NUMA *nar, *nag, *nab;
2178 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2179 cmap = pixGetColormap(pixs);
2180 pixGetDimensions(pixs, &w, &h, &d);
2181 if (!cmap && d != 32)
2182 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
2184 L_WARNING(
"mapval must be > 0; setting to 255\n", __func__);
2189 if ((pixd = pixCopy(pixd, pixs)) == NULL)
2190 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2194 nar = numaGammaTRC(1.0, 0, L_MAX(1, 255 * rval / mapval));
2195 nag = numaGammaTRC(1.0, 0, L_MAX(1, 255 * gval / mapval));
2196 nab = numaGammaTRC(1.0, 0, L_MAX(1, 255 * bval / mapval));
2199 rarray = numaGetIArray(nar);
2200 garray = numaGetIArray(nag);
2201 barray = numaGetIArray(nab);
2202 if (!nar || !nag || !nab || !rarray || !garray || !barray) {
2203 L_ERROR(
"allocation failure in arrays\n", __func__);
2204 goto cleanup_arrays;
2208 ncolors = pixcmapGetCount(cmap);
2209 for (i = 0; i < ncolors; i++) {
2210 pixcmapGetColor(cmap, i, &rv, &gv, &bv);
2211 pixcmapResetColor(cmap, i, rarray[rv], garray[gv], barray[bv]);
2215 data = pixGetData(pixd);
2216 wpl = pixGetWpl(pixd);
2217 for (i = 0; i < h; i++) {
2218 line = data + i * wpl;
2219 for (j = 0; j < w; j++) {
2220 extractRGBValues(line[j], &rv, &gv, &bv);
2221 composeRGBPixel(rarray[rv], garray[gv], barray[bv], line + j);
2280l_float32 rankrval, rankgval, rankbval;
2281l_float32 rfract, gfract, bfract, maxfract;
2284 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2285 if (pixGetDepth(pixs) != 32)
2286 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
2288 return (
PIX *)ERROR_PTR(
"sampling factor < 1", __func__, NULL);
2289 if (rank < 0.0 || rank > 1.0)
2290 return (
PIX *)ERROR_PTR(
"rank not in [0.0 ... 1.0]", __func__, NULL);
2291 if (rval <= 0 || gval <= 0 || bval <= 0)
2292 return (
PIX *)ERROR_PTR(
"invalid estim. color values", __func__, NULL);
2304 pixGetRankValueMaskedRGB(pixs, NULL, 0, 0, factor, rank, &rankrval,
2305 &rankgval, &rankbval);
2306 rfract = rankrval / (l_float32)rval;
2307 gfract = rankgval / (l_float32)gval;
2308 bfract = rankbval / (l_float32)bval;
2309 maxfract = L_MAX(rfract, gfract);
2310 maxfract = L_MAX(maxfract, bfract);
2312 lept_stderr(
"rankrval = %7.2f, rankgval = %7.2f, rankbval = %7.2f\n",
2313 rankrval, rankgval, rankbval);
2314 lept_stderr(
"rfract = %7.4f, gfract = %7.4f, bfract = %7.4f\n",
2315 rfract, gfract, bfract);
2318 mapval = (l_int32)(255. / maxfract);
2379 l_int32 targetthresh,
2384PIX *pixe, *pixet, *pixsd, *pixg1, *pixg2, *pixth;
2386 if (ppixth) *ppixth = NULL;
2387 if (ppixb) *ppixb = NULL;
2388 if (ppixd) *ppixd = NULL;
2389 if (!pixs || pixGetDepth(pixs) != 8)
2390 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
2391 if (pixGetColormap(pixs))
2392 return ERROR_INT(
"pixs is colormapped", __func__, 1);
2393 if (!ppixth && !ppixb && !ppixd)
2394 return ERROR_INT(
"no output requested", __func__, 1);
2396 return ERROR_INT(
"invalid filter type", __func__, 1);
2404 pixet = pixThresholdToBinary(pixe, edgethresh);
2405 pixInvert(pixet, pixet);
2409 pixsd = pixCreateTemplate(pixs);
2410 pixCombineMasked(pixsd, pixs, pixet);
2413 pixg1 = pixSeedspread(pixsd, 4);
2414 pixg2 = pixBlockconv(pixg1, smoothx, smoothy);
2417 pixth = pixGammaTRC(NULL, pixg2, gamma, minval, maxval);
2423 *ppixb = pixThresholdToBinary(*ppixd, targetthresh);
2426 *ppixb = pixVarThresholdToBinary(pixs, pixth);
2482l_float32 scalex, scaley;
2483PIX *pixt, *pixsd, *pixmin, *pixbg, *pixbgi, *pixd;
2485 if (!pixs || pixGetDepth(pixs) != 8)
2486 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
2487 if (pixGetColormap(pixs))
2488 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, NULL);
2489 if (sx < 3 || sy < 3)
2490 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 3", __func__, NULL);
2491 if (sx > 10 || sy > 10)
2492 return (
PIX *)ERROR_PTR(
"sx and/or sy exceed 10", __func__, NULL);
2493 if (smoothx < 1 || smoothy < 1)
2494 return (
PIX *)ERROR_PTR(
"smooth params less than 1", __func__, NULL);
2495 if (smoothx > 3 || smoothy > 3)
2496 return (
PIX *)ERROR_PTR(
"smooth params exceed 3", __func__, NULL);
2499 scalex = 1. / (l_float32)sx;
2500 scaley = 1. / (l_float32)sy;
2501 pixt = pixScaleSmooth(pixs, scalex, scaley);
2505 pixsd = pixClone(pixt);
2507 pixLocalExtrema(pixt, 0, 0, &pixmin, NULL);
2508 pixsd = pixSeedfillGrayBasin(pixmin, pixt, delta, 4);
2509 pixDestroy(&pixmin);
2520 pixDestroy(&pixbgi);
2576PIX *pixmin, *pixmax;
2578 if (!pixs || pixGetDepth(pixs) != 8)
2579 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, pixd);
2580 if (pixd && pixd != pixs)
2581 return (
PIX *)ERROR_PTR(
"pixd not null or == pixs", __func__, pixd);
2582 if (pixGetColormap(pixs))
2583 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, pixd);
2584 if (sx < 5 || sy < 5)
2585 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 5", __func__, pixd);
2586 if (smoothx < 0 || smoothy < 0)
2587 return (
PIX *)ERROR_PTR(
"smooth params less than 0", __func__, pixd);
2588 if (smoothx > 8 || smoothy > 8)
2589 return (
PIX *)ERROR_PTR(
"smooth params exceed 8", __func__, pixd);
2593 pixMinMaxTiles(pixs, sx, sy, mindiff, smoothx, smoothy, &pixmin, &pixmax);
2600 pixDestroy(&pixmin);
2601 pixDestroy(&pixmax);
2636PIX *pixmin1, *pixmax1, *pixmin2, *pixmax2;
2638 if (ppixmin) *ppixmin = NULL;
2639 if (ppixmax) *ppixmax = NULL;
2640 if (!ppixmin || !ppixmax)
2641 return ERROR_INT(
"&pixmin or &pixmax undefined", __func__, 1);
2642 if (!pixs || pixGetDepth(pixs) != 8)
2643 return ERROR_INT(
"pixs undefined or not 8 bpp", __func__, 1);
2644 if (pixGetColormap(pixs))
2645 return ERROR_INT(
"pixs is colormapped", __func__, 1);
2646 if (sx < 5 || sy < 5)
2647 return ERROR_INT(
"sx and/or sy less than 3", __func__, 1);
2648 if (smoothx < 0 || smoothy < 0)
2649 return ERROR_INT(
"smooth params less than 0", __func__, 1);
2650 if (smoothx > 5 || smoothy > 5)
2651 return ERROR_INT(
"smooth params exceed 5", __func__, 1);
2654 pixmin1 = pixScaleGrayMinMax(pixs, sx, sy, L_CHOOSE_MIN);
2655 pixmax1 = pixScaleGrayMinMax(pixs, sx, sy, L_CHOOSE_MAX);
2659 pixDestroy(&pixmin1);
2660 pixDestroy(&pixmax1);
2663 pixAddConstantGray(pixmin2, 1);
2664 pixAddConstantGray(pixmax2, 1);
2670 pixGetDimensions(pixmin2, &w, &h, NULL);
2675 if (smoothx > 0 || smoothy > 0) {
2676 smoothx = L_MIN(smoothx, (w - 1) / 2);
2677 smoothy = L_MIN(smoothy, (h - 1) / 2);
2678 *ppixmin = pixBlockconv(pixmin2, smoothx, smoothy);
2679 *ppixmax = pixBlockconv(pixmax2, smoothx, smoothy);
2682 *ppixmin = pixClone(pixmin2);
2683 *ppixmax = pixClone(pixmax2);
2685 pixCopyResolution(*ppixmin, pixs);
2686 pixCopyResolution(*ppixmax, pixs);
2687 pixDestroy(&pixmin2);
2688 pixDestroy(&pixmax2);
2719l_int32 i, j, w, h, d, wpl, val1, val2, found;
2720l_uint32 *data1, *data2, *line1, *line2;
2722 if (!pixs1 || !pixs2)
2723 return ERROR_INT(
"pixs1 and pixs2 not both defined", __func__, 1);
2724 if (pixSizesEqual(pixs1, pixs2) == 0)
2725 return ERROR_INT(
"pixs1 and pixs2 not equal size", __func__, 1);
2726 pixGetDimensions(pixs1, &w, &h, &d);
2728 return ERROR_INT(
"depth not 8 bpp", __func__, 1);
2729 if (mindiff > 254)
return 0;
2731 data1 = pixGetData(pixs1);
2732 data2 = pixGetData(pixs2);
2733 wpl = pixGetWpl(pixs1);
2735 for (i = 0; i < h; i++) {
2736 line1 = data1 + i * wpl;
2737 line2 = data2 + i * wpl;
2738 for (j = 0; j < w; j++) {
2741 if (L_ABS(val1 - val2) >= mindiff) {
2749 L_WARNING(
"no pixel pair diffs as large as mindiff\n", __func__);
2755 for (i = 0; i < h; i++) {
2756 line1 = data1 + i * wpl;
2757 line2 = data2 + i * wpl;
2758 for (j = 0; j < w; j++) {
2761 if (L_ABS(val1 - val2) < mindiff) {
2803l_int32 i, j, k, m, w, h, wt, ht, wpl, wplt, xoff, yoff;
2804l_int32 minval, maxval, val, sval;
2807l_uint32 *data, *datamin, *datamax, *line, *tline, *linemin, *linemax;
2809 if (!pixs || pixGetDepth(pixs) != 8)
2810 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, pixd);
2811 if (pixd && pixd != pixs)
2812 return (
PIX *)ERROR_PTR(
"pixd not null or == pixs", __func__, pixd);
2813 if (pixGetColormap(pixs))
2814 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, pixd);
2815 if (!pixmin || !pixmax)
2816 return (
PIX *)ERROR_PTR(
"pixmin & pixmax not defined", __func__, pixd);
2817 if (sx < 5 || sy < 5)
2818 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 5", __func__, pixd);
2820 iaa = (l_int32 **)LEPT_CALLOC(256,
sizeof(l_int32 *));
2821 if ((pixd = pixCopy(pixd, pixs)) == NULL) {
2823 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2825 pixGetDimensions(pixd, &w, &h, NULL);
2827 data = pixGetData(pixd);
2828 wpl = pixGetWpl(pixd);
2829 datamin = pixGetData(pixmin);
2830 datamax = pixGetData(pixmax);
2831 wplt = pixGetWpl(pixmin);
2832 pixGetDimensions(pixmin, &wt, &ht, NULL);
2833 for (i = 0; i < ht; i++) {
2834 line = data + sy * i * wpl;
2835 linemin = datamin + i * wplt;
2836 linemax = datamax + i * wplt;
2838 for (j = 0; j < wt; j++) {
2842 if (maxval == minval) {
2843 L_ERROR(
"shouldn't happen! i,j = %d,%d, minval = %d\n",
2844 __func__, i, j, minval);
2848 L_ERROR(
"failure to make ia for j = %d!\n", __func__, j);
2851 for (k = 0; k < sy && yoff + k < h; k++) {
2852 tline = line + k * wpl;
2853 for (m = 0; m < sx && xoff + m < w; m++) {
2855 sval = val - minval;
2856 sval = L_MAX(0, sval);
2863 for (i = 0; i < 256; i++)
2888 return (l_int32 *)ERROR_PTR(
"iaa not defined", __func__, NULL);
2890 if (iaa[diff] != NULL)
2893 ia = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2896 for (i = 0; i < 256; i++)
2900 factor = 255. / (l_float32)diff;
2901 for (i = 0; i < diff + 1; i++)
2902 ia[i] = (l_int32)(factor * i + 0.5);
2903 for (i = diff + 1; i < 256; i++)
2941 l_int32 scalefactor)
2943PIX *pix1, *pix2, *pixd;
2946 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2947 if (contrast < 1 || contrast > 10)
2948 return (
PIX *)ERROR_PTR(
"contrast not in [1 ... 10]", __func__, NULL);
2949 if (scalefactor != 1 && scalefactor != 2)
2950 return (
PIX *)ERROR_PTR(
"scalefactor not 1 or 2", __func__, NULL);
2952 if (pixGetDepth(pixs) == 1) {
2953 pixd = pixCopy(NULL, pixs);
2958 if (scalefactor == 1)
2959 pixd = pixThresholdToBinary(pix2, 180);
2961 pixd = pixScaleGray2xLIThresh(pix2, 180);
2986 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2988 l_int32 d = pixGetDepth(pixs);
2990 return pixConvert1To8(NULL, pixs, 255, 0);
2991 }
else if (d == 2) {
2992 return pixConvert2To8(pixs, 0, 85, 170, 255, FALSE);
2993 }
else if (d == 4) {
2994 return pixConvert4To8(pixs, FALSE);
2995 }
else if (d == 8) {
2996 if (pixGetColormap(pixs) != NULL)
2999 return pixCopy(NULL, pixs);
3000 }
else if (d == 16) {
3001 return pixConvert16To8(pixs,
L_MS_BYTE);
3002 }
else if (d == 32) {
3003 return pixConvertRGBToGrayMinMax(pixs, L_CHOOSE_MIN);
3006 L_ERROR(
"Invalid depth d = %d\n", __func__, d);
3037 if (!pixs || pixGetDepth(pixs) != 8)
3038 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
3041 pixGammaTRC(pixs, pixs, 2.0, 50, 200);
3042 else if (contrast == 2)
3043 pixGammaTRC(pixs, pixs, 1.8, 60, 200);
3044 else if (contrast == 3)
3045 pixGammaTRC(pixs, pixs, 1.6, 70, 200);
3046 else if (contrast == 4)
3047 pixGammaTRC(pixs, pixs, 1.4, 80, 200);
3048 else if (contrast == 5)
3049 pixGammaTRC(pixs, pixs, 1.2, 90, 200);
3050 else if (contrast == 6)
3051 pixGammaTRC(pixs, pixs, 1.0, 100, 200);
3052 else if (contrast == 7)
3053 pixGammaTRC(pixs, pixs, 0.85, 110, 200);
3054 else if (contrast == 8)
3055 pixGammaTRC(pixs, pixs, 0.7, 120, 200);
3056 else if (contrast == 9)
3057 pixGammaTRC(pixs, pixs, 0.6, 130, 200);
3059 pixGammaTRC(pixs, pixs, 0.5, 140, 200);
l_ok pixGetBackgroundRGBMap(PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, PIX **ppixmr, PIX **ppixmg, PIX **ppixmb)
pixGetBackgroundRGBMap()
PIX * pixApplyVariableGrayMap(PIX *pixs, PIX *pixg, l_int32 target)
pixApplyVariableGrayMap()
PIX * pixBackgroundNormMorph(PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval)
pixBackgroundNormMorph()
static l_ok pixSelectiveContrastMod(PIX *pixs, l_int32 contrast)
pixSelectiveContrastMod()
l_ok pixBackgroundNormRGBArraysMorph(PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval, PIX **ppixr, PIX **ppixg, PIX **ppixb)
pixBackgroundNormRGBArraysMorph()
static const l_int32 DefaultFgThreshold
static const l_int32 DefaultTileHeight
static l_int32 * iaaGetLinearTRC(l_int32 **iaa, l_int32 diff)
iaaGetLinearTRC()
PIX * pixBackgroundNormFlex(PIX *pixs, l_int32 sx, l_int32 sy, l_int32 smoothx, l_int32 smoothy, l_int32 delta)
pixBackgroundNormFlex()
l_ok pixBackgroundNormRGBArrays(PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy, PIX **ppixr, PIX **ppixg, PIX **ppixb)
pixBackgroundNormRGBArrays()
l_ok pixSmoothConnectedRegions(PIX *pixs, PIX *pixm, l_int32 factor)
pixSmoothConnectedRegions()
PIX * pixApplyInvBackgroundGrayMap(PIX *pixs, PIX *pixm, l_int32 sx, l_int32 sy)
pixApplyInvBackgroundGrayMap()
PIX * pixGlobalNormNoSatRGB(PIX *pixd, PIX *pixs, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 factor, l_float32 rank)
pixGlobalNormNoSatRGB()
l_ok pixBackgroundNormGrayArrayMorph(PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, l_int32 bgval, PIX **ppixd)
pixBackgroundNormGrayArrayMorph()
l_ok pixGetBackgroundGrayMap(PIX *pixs, PIX *pixim, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, PIX **ppixd)
pixGetBackgroundGrayMap()
PIX * pixApplyInvBackgroundRGBMap(PIX *pixs, PIX *pixmr, PIX *pixmg, PIX *pixmb, l_int32 sx, l_int32 sy)
pixApplyInvBackgroundRGBMap()
l_ok pixGetBackgroundRGBMapMorph(PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, PIX **ppixmr, PIX **ppixmg, PIX **ppixmb)
pixGetBackgroundRGBMapMorph()
PIX * pixBackgroundNormSimple(PIX *pixs, PIX *pixim, PIX *pixg)
pixBackgroundNormSimple()
static l_int32 pixSetLowContrast(PIX *pixs1, PIX *pixs2, l_int32 mindiff)
pixSetLowContrast()
PIX * pixExtendByReplication(PIX *pixs, l_int32 addw, l_int32 addh)
pixExtendByReplication()
PIX * pixGlobalNormRGB(PIX *pixd, PIX *pixs, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 mapval)
pixGlobalNormRGB()
static const l_int32 DefaultBgVal
l_ok pixBackgroundNormGrayArray(PIX *pixs, PIX *pixim, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy, PIX **ppixd)
pixBackgroundNormGrayArray()
PIX * pixContrastNorm(PIX *pixd, PIX *pixs, l_int32 sx, l_int32 sy, l_int32 mindiff, l_int32 smoothx, l_int32 smoothy)
pixContrastNorm()
static const l_int32 DefaultTileWidth
static const l_int32 DefaultMinCount
PIX * pixConvertTo8MinMax(PIX *pixs)
pixConvertTo8MinMax()
l_ok pixFillMapHoles(PIX *pix, l_int32 nx, l_int32 ny, l_int32 filltype)
pixFillMapHoles()
PIX * pixBackgroundNorm(PIX *pixs, PIX *pixim, PIX *pixg, l_int32 sx, l_int32 sy, l_int32 thresh, l_int32 mincount, l_int32 bgval, l_int32 smoothx, l_int32 smoothy)
pixBackgroundNorm()
l_ok pixGetBackgroundGrayMapMorph(PIX *pixs, PIX *pixim, l_int32 reduction, l_int32 size, PIX **ppixm)
pixGetBackgroundGrayMapMorph()
PIX * pixGetInvBackgroundMap(PIX *pixs, l_int32 bgval, l_int32 smoothx, l_int32 smoothy)
pixGetInvBackgroundMap()
static l_int32 pixMinMaxTiles(PIX *pixs, l_int32 sx, l_int32 sy, l_int32 mindiff, l_int32 smoothx, l_int32 smoothy, PIX **ppixmin, PIX **ppixmax)
pixMinMaxTiles()
static const l_int32 DefaultXSmoothSize
PIX * pixBackgroundNormTo1MinMax(PIX *pixs, l_int32 contrast, l_int32 scalefactor)
pixBackgroundNormTo1MinMax()
static PIX * pixLinearTRCTiled(PIX *pixd, PIX *pixs, l_int32 sx, l_int32 sy, PIX *pixmin, PIX *pixmax)
pixLinearTRCTiled()
PIX * pixCleanBackgroundToWhite(PIX *pixs, PIX *pixim, PIX *pixg, l_float32 gamma, l_int32 blackval, l_int32 whiteval)
pixCleanBackgroundToWhite()
static const l_int32 DefaultYSmoothSize
l_ok pixThresholdSpreadNorm(PIX *pixs, l_int32 filtertype, l_int32 edgethresh, l_int32 smoothx, l_int32 smoothy, l_float32 gamma, l_int32 minval, l_int32 maxval, l_int32 targetthresh, PIX **ppixth, PIX **ppixb, PIX **ppixd)
pixThresholdSpreadNorm()
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
@ REMOVE_CMAP_TO_GRAYSCALE