151#include <config_auto.h>
154#include "allheaders.h"
173 l_int32 mindiff, l_int32 smoothx, l_int32 smoothy,
174 PIX **ppixmin,
PIX **ppixmax);
177 PIX *pixmin,
PIX *pixmax);
183#define DEBUG_GLOBAL 0
225 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
226 d = pixGetDepth(pixs);
227 if (d != 8 && d != 32)
228 return (
PIX *)ERROR_PTR(
"depth not 8 or 32", __func__, NULL);
229 if (whiteval > 200) {
230 L_WARNING(
"white value %d must not exceed 200; reset to 190",
237 return (
PIX *)ERROR_PTR(
"background norm failedd", __func__, NULL);
238 pixGammaTRC(pixd, pixd, gamma, blackval, whiteval);
350PIX *pixm, *pixmi, *pixd;
351PIX *pixmr, *pixmg, *pixmb, *pixmri, *pixmgi, *pixmbi;
354 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
355 d = pixGetDepth(pixs);
356 if (d != 8 && d != 32)
357 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
358 if (sx < 4 || sy < 4)
359 return (
PIX *)ERROR_PTR(
"sx and sy must be >= 4", __func__, NULL);
360 if (mincount > sx * sy) {
361 L_WARNING(
"mincount too large for tile size\n", __func__);
362 mincount = (sx * sy) / 3;
367 pixInvert(pixim, pixim);
368 pixZero(pixim, &allfg);
369 pixInvert(pixim, pixim);
371 return (
PIX *)ERROR_PTR(
"pixim all foreground", __func__, NULL);
379 L_WARNING(
"map not made; return a copy of the source\n", __func__);
380 return pixCopy(NULL, pixs);
385 L_WARNING(
"pixmi not made; return a copy of source\n", __func__);
387 return pixCopy(NULL, pixs);
396 pixmr = pixmg = pixmb = NULL;
398 mincount, &pixmr, &pixmg, &pixmb);
399 if (!pixmr || !pixmg || !pixmb) {
403 L_WARNING(
"map not made; return a copy of the source\n", __func__);
404 return pixCopy(NULL, pixs);
410 if (!pixmri || !pixmgi || !pixmbi) {
411 L_WARNING(
"not all pixm*i are made; return src copy\n", __func__);
412 pixd = pixCopy(NULL, pixs);
427 ERROR_PTR(
"pixd not made", __func__, NULL);
428 pixCopyResolution(pixd, pixs);
480PIX *pixm, *pixmi, *pixd;
481PIX *pixmr, *pixmg, *pixmb, *pixmri, *pixmgi, *pixmbi;
484 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
485 d = pixGetDepth(pixs);
486 if (d != 8 && d != 32)
487 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
488 if (reduction < 2 || reduction > 16)
489 return (
PIX *)ERROR_PTR(
"reduction must be between 2 and 16",
494 pixInvert(pixim, pixim);
495 pixZero(pixim, &allfg);
496 pixInvert(pixim, pixim);
498 return (
PIX *)ERROR_PTR(
"pixim all foreground", __func__, NULL);
505 return (
PIX *)ERROR_PTR(
"pixm not made", __func__, NULL);
508 ERROR_PTR(
"pixmi not made", __func__, NULL);
511 reduction, reduction);
516 pixmr = pixmg = pixmb = NULL;
518 &pixmr, &pixmg, &pixmb);
519 if (!pixmr || !pixmg || !pixmb) {
523 return (
PIX *)ERROR_PTR(
"not all pixm*", __func__, NULL);
529 if (!pixmri || !pixmgi || !pixmbi)
530 ERROR_PTR(
"not all pixm*i are made", __func__, NULL);
533 reduction, reduction);
544 ERROR_PTR(
"pixd not made", __func__, NULL);
545 pixCopyResolution(pixd, pixs);
597 return ERROR_INT(
"&pixd not defined", __func__, 1);
599 if (!pixs || pixGetDepth(pixs) != 8)
600 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
601 if (pixGetColormap(pixs))
602 return ERROR_INT(
"pixs is colormapped", __func__, 1);
603 if (pixim && pixGetDepth(pixim) != 1)
604 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
605 if (sx < 4 || sy < 4)
606 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
607 if (mincount > sx * sy) {
608 L_WARNING(
"mincount too large for tile size\n", __func__);
609 mincount = (sx * sy) / 3;
614 pixInvert(pixim, pixim);
615 pixZero(pixim, &allfg);
616 pixInvert(pixim, pixim);
618 return ERROR_INT(
"pixim all foreground", __func__, 1);
623 return ERROR_INT(
"pixm not made", __func__, 1);
625 pixCopyResolution(*ppixd, pixs);
672PIX *pixmr, *pixmg, *pixmb;
674 if (!ppixr || !ppixg || !ppixb)
675 return ERROR_INT(
"&pixr, &pixg, &pixb not all defined", __func__, 1);
676 *ppixr = *ppixg = *ppixb = NULL;
678 return ERROR_INT(
"pixs not defined", __func__, 1);
679 if (pixGetDepth(pixs) != 32)
680 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
681 if (pixim && pixGetDepth(pixim) != 1)
682 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
683 if (sx < 4 || sy < 4)
684 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
685 if (mincount > sx * sy) {
686 L_WARNING(
"mincount too large for tile size\n", __func__);
687 mincount = (sx * sy) / 3;
692 pixInvert(pixim, pixim);
693 pixZero(pixim, &allfg);
694 pixInvert(pixim, pixim);
696 return ERROR_INT(
"pixim all foreground", __func__, 1);
700 &pixmr, &pixmg, &pixmb);
701 if (!pixmr || !pixmg || !pixmb) {
705 return ERROR_INT(
"not all pixm* made", __func__, 1);
749 return ERROR_INT(
"&pixd not defined", __func__, 1);
752 return ERROR_INT(
"pixs not defined", __func__, 1);
753 if (pixGetDepth(pixs) != 8)
754 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
755 if (pixim && pixGetDepth(pixim) != 1)
756 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
757 if (reduction < 2 || reduction > 16)
758 return ERROR_INT(
"reduction must be between 2 and 16", __func__, 1);
762 pixInvert(pixim, pixim);
763 pixZero(pixim, &allfg);
764 pixInvert(pixim, pixim);
766 return ERROR_INT(
"pixim all foreground", __func__, 1);
771 return ERROR_INT(
"pixm not made", __func__, 1);
773 pixCopyResolution(*ppixd, pixs);
811PIX *pixmr, *pixmg, *pixmb;
813 if (!ppixr || !ppixg || !ppixb)
814 return ERROR_INT(
"&pixr, &pixg, &pixb not all defined", __func__, 1);
815 *ppixr = *ppixg = *ppixb = NULL;
817 return ERROR_INT(
"pixs not defined", __func__, 1);
818 if (pixGetDepth(pixs) != 32)
819 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
820 if (pixim && pixGetDepth(pixim) != 1)
821 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
822 if (reduction < 2 || reduction > 16)
823 return ERROR_INT(
"reduction must be between 2 and 16", __func__, 1);
827 pixInvert(pixim, pixim);
828 pixZero(pixim, &allfg);
829 pixInvert(pixim, pixim);
831 return ERROR_INT(
"pixim all foreground", __func__, 1);
835 &pixmr, &pixmg, &pixmb);
836 if (!pixmr || !pixmg || !pixmb) {
840 return ERROR_INT(
"not all pixm* made", __func__, 1);
884l_int32 w, h, wd, hd, wim, him, wpls, wplim, wpld, wplf;
885l_int32 xim, yim, delx, nx, ny, i, j, k, m;
886l_int32 count, sum, val8;
887l_int32 empty, fgpixels;
888l_uint32 *datas, *dataim, *datad, *dataf, *lines, *lineim, *lined, *linef;
889l_float32 scalex, scaley;
890PIX *pixd, *piximi, *pixb, *pixf, *pixims;
893 return ERROR_INT(
"&pixd not defined", __func__, 1);
895 if (!pixs || pixGetDepth(pixs) != 8)
896 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
897 if (pixGetColormap(pixs))
898 return ERROR_INT(
"pixs is colormapped", __func__, 1);
899 if (pixim && pixGetDepth(pixim) != 1)
900 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
901 if (sx < 4 || sy < 4)
902 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
903 if (mincount > sx * sy) {
904 L_WARNING(
"mincount too large for tile size\n", __func__);
905 mincount = (sx * sy) / 3;
912 piximi = pixInvert(NULL, pixim);
913 pixZero(piximi, &empty);
916 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
917 pixZero(pixim, &empty);
925 pixb = pixThresholdToBinary(pixs, thresh);
926 pixf = pixMorphSequence(pixb,
"d7.1 + d1.7", 0);
929 return ERROR_INT(
"pixf not made", __func__, 1);
934 w = pixGetWidth(pixs);
935 h = pixGetHeight(pixs);
936 wd = (w + sx - 1) / sx;
937 hd = (h + sy - 1) / sy;
938 pixd = pixCreate(wd, hd, 8);
945 wpls = pixGetWpl(pixs);
946 datas = pixGetData(pixs);
947 wpld = pixGetWpl(pixd);
948 datad = pixGetData(pixd);
949 wplf = pixGetWpl(pixf);
950 dataf = pixGetData(pixf);
951 for (i = 0; i < ny; i++) {
952 lines = datas + sy * i * wpls;
953 linef = dataf + sy * i * wplf;
954 lined = datad + i * wpld;
955 for (j = 0; j < nx; j++) {
959 for (k = 0; k < sy; k++) {
960 for (m = 0; m < sx; m++) {
967 if (count >= mincount) {
986 if (pixim && fgpixels) {
987 wim = pixGetWidth(pixim);
988 him = pixGetHeight(pixim);
989 dataim = pixGetData(pixim);
990 wplim = pixGetWpl(pixim);
991 for (i = 0; i < ny; i++) {
992 yim = i * sy + sy / 2;
995 lineim = dataim + yim * wplim;
996 for (j = 0; j < nx; j++) {
997 xim = j * sx + sx / 2;
1001 pixSetPixel(pixd, j, i, 0);
1009 L_WARNING(
"can't make the map\n", __func__);
1018 if (pixim && fgpixels) {
1019 scalex = 1. / (l_float32)sx;
1020 scaley = 1. / (l_float32)sy;
1021 pixims = pixScaleBySampling(pixim, scalex, scaley);
1023 pixDestroy(&pixims);
1027 pixCopyResolution(*ppixd, pixs);
1067l_int32 w, h, wm, hm, wim, him, wpls, wplim, wplf;
1068l_int32 xim, yim, delx, nx, ny, i, j, k, m;
1069l_int32 count, rsum, gsum, bsum, rval, gval, bval;
1070l_int32 empty, fgpixels;
1072l_uint32 *datas, *dataim, *dataf, *lines, *lineim, *linef;
1073l_float32 scalex, scaley;
1074PIX *piximi, *pixgc, *pixb, *pixf, *pixims;
1075PIX *pixmr, *pixmg, *pixmb;
1077 if (!ppixmr || !ppixmg || !ppixmb)
1078 return ERROR_INT(
"&pixm* not all defined", __func__, 1);
1079 *ppixmr = *ppixmg = *ppixmb = NULL;
1081 return ERROR_INT(
"pixs not defined", __func__, 1);
1082 if (pixGetDepth(pixs) != 32)
1083 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
1084 if (pixim && pixGetDepth(pixim) != 1)
1085 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1086 if (sx < 4 || sy < 4)
1087 return ERROR_INT(
"sx and sy must be >= 4", __func__, 1);
1088 if (mincount > sx * sy) {
1089 L_WARNING(
"mincount too large for tile size\n", __func__);
1090 mincount = (sx * sy) / 3;
1096 piximi = pixInvert(NULL, pixim);
1097 pixZero(piximi, &empty);
1098 pixDestroy(&piximi);
1100 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1101 pixZero(pixim, &empty);
1109 pixgc = pixClone(pixg);
1111 pixgc = pixConvertRGBToGrayFast(pixs);
1112 pixb = pixThresholdToBinary(pixgc, thresh);
1113 pixf = pixMorphSequence(pixb,
"d7.1 + d1.7", 0);
1118 w = pixGetWidth(pixs);
1119 h = pixGetHeight(pixs);
1120 wm = (w + sx - 1) / sx;
1121 hm = (h + sy - 1) / sy;
1122 pixmr = pixCreate(wm, hm, 8);
1123 pixmg = pixCreate(wm, hm, 8);
1124 pixmb = pixCreate(wm, hm, 8);
1132 wpls = pixGetWpl(pixs);
1133 datas = pixGetData(pixs);
1134 wplf = pixGetWpl(pixf);
1135 dataf = pixGetData(pixf);
1136 for (i = 0; i < ny; i++) {
1137 lines = datas + sy * i * wpls;
1138 linef = dataf + sy * i * wplf;
1139 for (j = 0; j < nx; j++) {
1141 rsum = gsum = bsum = 0;
1143 for (k = 0; k < sy; k++) {
1144 for (m = 0; m < sx; m++) {
1146 pixel = *(lines + k * wpls + delx + m);
1147 rsum += (pixel >> 24);
1148 gsum += ((pixel >> 16) & 0xff);
1149 bsum += ((pixel >> 8) & 0xff);
1154 if (count >= mincount) {
1155 rval = rsum / count;
1156 gval = gsum / count;
1157 bval = bsum / count;
1158 pixSetPixel(pixmr, j, i, rval);
1159 pixSetPixel(pixmg, j, i, gval);
1160 pixSetPixel(pixmb, j, i, bval);
1172 wim = pixGetWidth(pixim);
1173 him = pixGetHeight(pixim);
1174 dataim = pixGetData(pixim);
1175 wplim = pixGetWpl(pixim);
1176 for (i = 0; i < ny; i++) {
1177 yim = i * sy + sy / 2;
1180 lineim = dataim + yim * wplim;
1181 for (j = 0; j < nx; j++) {
1182 xim = j * sx + sx / 2;
1186 pixSetPixel(pixmr, j, i, 0);
1187 pixSetPixel(pixmg, j, i, 0);
1188 pixSetPixel(pixmb, j, i, 0);
1201 L_WARNING(
"can't make the maps\n", __func__);
1207 if (pixim && fgpixels) {
1208 scalex = 1. / (l_float32)sx;
1209 scaley = 1. / (l_float32)sy;
1210 pixims = pixScaleBySampling(pixim, scalex, scaley);
1214 pixDestroy(&pixims);
1220 pixCopyResolution(*ppixmr, pixs);
1221 pixCopyResolution(*ppixmg, pixs);
1222 pixCopyResolution(*ppixmb, pixs);
1245l_int32 nx, ny, empty, fgpixels;
1247PIX *pixm, *pix1, *pix2, *pix3, *pixims;
1250 return ERROR_INT(
"&pixm not defined", __func__, 1);
1252 if (!pixs || pixGetDepth(pixs) != 8)
1253 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
1254 if (pixGetColormap(pixs))
1255 return ERROR_INT(
"pixs is colormapped", __func__, 1);
1256 if (pixim && pixGetDepth(pixim) != 1)
1257 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1262 pixInvert(pixim, pixim);
1263 pixZero(pixim, &empty);
1265 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1266 pixInvert(pixim, pixim);
1267 pixZero(pixim, &empty);
1273 scale = 1. / (l_float32)reduction;
1274 pix1 = pixScaleBySampling(pixs, scale, scale);
1275 pix2 = pixCloseGray(pix1, size, size);
1284 pixims = pixScale(pixim, scale, scale);
1285 pixm = pixConvertTo8(pixims, FALSE);
1286 pixAnd(pixm, pixm, pix3);
1289 pixm = pixClone(pix3);
1293 nx = pixGetWidth(pixs) / reduction;
1294 ny = pixGetHeight(pixs) / reduction;
1297 pixDestroy(&pixims);
1298 L_WARNING(
"can't make the map\n", __func__);
1304 if (pixim && fgpixels)
1306 pixDestroy(&pixims);
1309 pixCopyResolution(*ppixm, pixs);
1336l_int32 nx, ny, empty, fgpixels;
1338PIX *pixm, *pixmr, *pixmg, *pixmb, *pix1, *pix2, *pix3, *pixims;
1340 if (!ppixmr || !ppixmg || !ppixmb)
1341 return ERROR_INT(
"&pixm* not all defined", __func__, 1);
1342 *ppixmr = *ppixmg = *ppixmb = NULL;
1344 return ERROR_INT(
"pixs not defined", __func__, 1);
1345 if (pixGetDepth(pixs) != 32)
1346 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
1347 if (pixim && pixGetDepth(pixim) != 1)
1348 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1353 pixInvert(pixim, pixim);
1354 pixZero(pixim, &empty);
1356 return ERROR_INT(
"pixim all fg; no background", __func__, 1);
1357 pixInvert(pixim, pixim);
1358 pixZero(pixim, &empty);
1364 scale = 1. / (l_float32)reduction;
1368 pixims = pixScale(pixim, scale, scale);
1369 pixm = pixConvertTo8(pixims, FALSE);
1375 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_RED);
1376 pix2 = pixCloseGray(pix1, size, size);
1379 pixmr = pixAnd(NULL, pixm, pix3);
1381 pixmr = pixClone(pix3);
1386 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_GREEN);
1387 pix2 = pixCloseGray(pix1, size, size);
1390 pixmg = pixAnd(NULL, pixm, pix3);
1392 pixmg = pixClone(pix3);
1397 pix1 = pixScaleRGBToGrayFast(pixs, reduction,
COLOR_BLUE);
1398 pix2 = pixCloseGray(pix1, size, size);
1401 pixmb = pixAnd(NULL, pixm, pix3);
1403 pixmb = pixClone(pix3);
1410 nx = pixGetWidth(pixs) / reduction;
1411 ny = pixGetHeight(pixs) / reduction;
1418 pixDestroy(&pixims);
1419 L_WARNING(
"can't make the maps\n", __func__);
1426 if (pixim && fgpixels) {
1430 pixDestroy(&pixims);
1436 pixCopyResolution(*ppixmr, pixs);
1437 pixCopyResolution(*ppixmg, pixs);
1438 pixCopyResolution(*ppixmb, pixs);
1485l_int32 w, h, y, nmiss, goodcol, i, j, found, ival, valtest;
1486l_uint32 val, lastval;
1489 if (!pix || pixGetDepth(pix) != 8)
1490 return ERROR_INT(
"pix not defined or not 8 bpp", __func__, 1);
1491 if (pixGetColormap(pix))
1492 return ERROR_INT(
"pix is colormapped", __func__, 1);
1495 pixGetDimensions(pix, &w, &h, NULL);
1499 for (j = 0; j < nx; j++) {
1501 for (i = 0; i < ny; i++) {
1502 pixGetPixel(pix, j, i, &val);
1503 if (val != valtest) {
1509 if (found == FALSE) {
1510 numaAddNumber(na, 0);
1514 numaAddNumber(na, 1);
1515 for (i = y - 1; i >= 0; i--)
1516 pixSetPixel(pix, j, i, val);
1517 pixGetPixel(pix, j, 0, &lastval);
1518 for (i = 1; i < h; i++) {
1519 pixGetPixel(pix, j, i, &val);
1521 pixSetPixel(pix, j, i, lastval);
1530 L_WARNING(
"no bg found; no data in any column\n", __func__);
1538 for (j = 0; j < w; j++) {
1539 numaGetIValue(na, j, &ival);
1546 for (j = goodcol - 1; j >= 0; j--)
1547 pixRasterop(pix, j, 0, 1, h,
PIX_SRC, pix, j + 1, 0);
1549 for (j = goodcol + 1; j < w; j++) {
1550 numaGetIValue(na, j, &ival);
1553 pixRasterop(pix, j, 0, 1, h,
PIX_SRC, pix, j - 1, 0);
1558 pixRasterop(pix, w - 1, 0, 1, h,
PIX_SRC, pix, w - 2, 0);
1588 if (!pixs || pixGetDepth(pixs) != 8)
1589 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1591 if (addw == 0 && addh == 0)
1592 return pixCopy(NULL, pixs);
1594 pixGetDimensions(pixs, &w, &h, NULL);
1595 if ((pixd = pixCreate(w + addw, h + addh, 8)) == NULL)
1596 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1597 pixRasterop(pixd, 0, 0, w, h,
PIX_SRC, pixs, 0, 0);
1600 for (i = 0; i < h; i++) {
1601 pixGetPixel(pixd, w - 1, i, &val);
1602 for (j = 0; j < addw; j++)
1603 pixSetPixel(pixd, w + j, i, val);
1608 for (j = 0; j < w + addw; j++) {
1609 pixGetPixel(pixd, j, h - 1, &val);
1610 for (i = 0; i < addh; i++)
1611 pixSetPixel(pixd, j, h + i, val);
1615 pixCopyResolution(pixd, pixs);
1645l_int32 empty, i, n, x, y;
1651 if (!pixs || pixGetDepth(pixs) != 8)
1652 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
1653 if (pixGetColormap(pixs))
1654 return ERROR_INT(
"pixs has colormap", __func__, 1);
1656 L_INFO(
"pixm not defined\n", __func__);
1659 if (pixGetDepth(pixm) != 1)
1660 return ERROR_INT(
"pixm not 1 bpp", __func__, 1);
1661 pixZero(pixm, &empty);
1663 L_INFO(
"pixm has no fg pixels; nothing to do\n", __func__);
1667 boxa = pixConnComp(pixm, &pixa, 8);
1668 n = boxaGetCount(boxa);
1669 for (i = 0; i < n; i++) {
1670 if ((pixmc = pixaGetPix(pixa, i,
L_CLONE)) == NULL) {
1671 L_WARNING(
"missing pixmc!\n", __func__);
1674 boxaGetBoxGeometry(boxa, i, &x, &y, NULL, NULL);
1675 pixGetAverageMasked(pixs, pixmc, x, y, factor,
L_MEAN_ABSVAL, &aveval);
1676 pixPaintThroughMask(pixs, pixmc, x, y, (l_int32)aveval);
1728pixGetForegroundGrayMap(
PIX *pixs,
1735l_int32 w, h, d, wd, hd;
1736l_int32 empty, fgpixels;
1737PIX *pixd, *piximi, *pixim2, *pixims, *pixs2, *pixb, *pixt1, *pixt2, *pixt3;
1740 return ERROR_INT(
"&pixd not defined", __func__, 1);
1743 return ERROR_INT(
"pixs not defined", __func__, 1);
1744 pixGetDimensions(pixs, &w, &h, &d);
1746 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
1747 if (pixim && pixGetDepth(pixim) != 1)
1748 return ERROR_INT(
"pixim not 1 bpp", __func__, 1);
1749 if (sx < 2 || sy < 2)
1750 return ERROR_INT(
"sx and sy must be >= 2", __func__, 1);
1753 wd = (w + sx - 1) / sx;
1754 hd = (h + sy - 1) / sy;
1755 pixd = pixCreate(wd, hd, 8);
1762 piximi = pixInvert(NULL, pixim);
1763 pixZero(piximi, &empty);
1764 pixDestroy(&piximi);
1767 pixZero(pixim, &empty);
1773 pixs2 = pixScaleBySampling(pixs, 0.5, 0.5);
1774 if (pixim && fgpixels) {
1775 pixim2 = pixReduceBinary2(pixim, NULL);
1776 pixPaintThroughMask(pixs2, pixim2, 0, 0, 255);
1777 pixDestroy(&pixim2);
1781 pixt1 = pixScaleGrayMinMax(pixs2, sx, sy, L_CHOOSE_MIN);
1786 pixb = pixThresholdToBinary(pixt1, thresh);
1787 pixInvert(pixb, pixb);
1788 pixPaintThroughMask(pixt1, pixb, 0, 0, 255);
1792 pixt2 = pixExpandReplicate(pixt1, 2);
1802 pixt3 = pixBlockconv(pixt2, 8, 8);
1803 pixRasterop(pixd, 0, 0, wd, hd,
PIX_SRC, pixt3, 0, 0);
1806 pixims = pixScaleBySampling(pixim, 1. / sx, 1. / sy);
1807 pixPaintThroughMask(pixd, pixims, 0, 0, 0);
1843l_int32 w, h, wplsm, wpld, i, j;
1845l_uint32 *datasm, *datad, *linesm, *lined;
1848 if (!pixs || pixGetDepth(pixs) != 8)
1849 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1850 if (pixGetColormap(pixs))
1851 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1852 pixGetDimensions(pixs, &w, &h, NULL);
1854 return (
PIX *)ERROR_PTR(
"w and h must be >= 5", __func__, NULL);
1857 pixsm = pixBlockconv(pixs, smoothx, smoothy);
1858 datasm = pixGetData(pixsm);
1859 wplsm = pixGetWpl(pixsm);
1862 pixd = pixCreate(w, h, 16);
1863 datad = pixGetData(pixd);
1864 wpld = pixGetWpl(pixd);
1865 for (i = 0; i < h; i++) {
1866 linesm = datasm + i * wplsm;
1867 lined = datad + i * wpld;
1868 for (j = 0; j < w; j++) {
1871 val16 = (256 * bgval) / val;
1873 L_WARNING(
"smoothed bg has 0 pixel!\n", __func__);
1881 pixCopyResolution(pixd, pixs);
1904l_int32 w, h, wm, hm, wpls, wpld, i, j, k, m, xoff, yoff;
1907l_uint32 *datas, *datad, *lines, *lined, *flines, *flined;
1910 if (!pixs || pixGetDepth(pixs) != 8)
1911 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
1912 if (pixGetColormap(pixs))
1913 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
1914 if (!pixm || pixGetDepth(pixm) != 16)
1915 return (
PIX *)ERROR_PTR(
"pixm undefined or not 16 bpp", __func__, NULL);
1916 if (sx == 0 || sy == 0)
1917 return (
PIX *)ERROR_PTR(
"invalid sx and/or sy", __func__, NULL);
1919 datas = pixGetData(pixs);
1920 wpls = pixGetWpl(pixs);
1921 pixGetDimensions(pixs, &w, &h, NULL);
1922 pixGetDimensions(pixm, &wm, &hm, NULL);
1923 if ((pixd = pixCreateTemplate(pixs)) == NULL)
1924 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1925 datad = pixGetData(pixd);
1926 wpld = pixGetWpl(pixd);
1927 for (i = 0; i < hm; i++) {
1928 lines = datas + sy * i * wpls;
1929 lined = datad + sy * i * wpld;
1931 for (j = 0; j < wm; j++) {
1932 pixGetPixel(pixm, j, i, &val16);
1934 for (k = 0; k < sy && yoff + k < h; k++) {
1935 flines = lines + k * wpls;
1936 flined = lined + k * wpld;
1937 for (m = 0; m < sx && xoff + m < w; m++) {
1939 vald = (vals * val16) / 256;
1940 vald = L_MIN(vald, 255);
1970l_int32 w, h, wm, hm, wpls, wpld, i, j, k, m, xoff, yoff;
1971l_int32 rvald, gvald, bvald;
1973l_uint32 rval16, gval16, bval16;
1974l_uint32 *datas, *datad, *lines, *lined, *flines, *flined;
1978 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1979 if (pixGetDepth(pixs) != 32)
1980 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
1981 if (!pixmr || !pixmg || !pixmb)
1982 return (
PIX *)ERROR_PTR(
"pix maps not all defined", __func__, NULL);
1983 if (pixGetDepth(pixmr) != 16 || pixGetDepth(pixmg) != 16 ||
1984 pixGetDepth(pixmb) != 16)
1985 return (
PIX *)ERROR_PTR(
"pix maps not all 16 bpp", __func__, NULL);
1986 if (sx == 0 || sy == 0)
1987 return (
PIX *)ERROR_PTR(
"invalid sx and/or sy", __func__, NULL);
1989 datas = pixGetData(pixs);
1990 wpls = pixGetWpl(pixs);
1991 w = pixGetWidth(pixs);
1992 h = pixGetHeight(pixs);
1993 wm = pixGetWidth(pixmr);
1994 hm = pixGetHeight(pixmr);
1995 if ((pixd = pixCreateTemplate(pixs)) == NULL)
1996 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1997 datad = pixGetData(pixd);
1998 wpld = pixGetWpl(pixd);
1999 for (i = 0; i < hm; i++) {
2000 lines = datas + sy * i * wpls;
2001 lined = datad + sy * i * wpld;
2003 for (j = 0; j < wm; j++) {
2004 pixGetPixel(pixmr, j, i, &rval16);
2005 pixGetPixel(pixmg, j, i, &gval16);
2006 pixGetPixel(pixmb, j, i, &bval16);
2008 for (k = 0; k < sy && yoff + k < h; k++) {
2009 flines = lines + k * wpls;
2010 flined = lined + k * wpld;
2011 for (m = 0; m < sx && xoff + m < w; m++) {
2012 vals = *(flines + xoff + m);
2013 rvald = ((vals >> 24) * rval16) / 256;
2014 rvald = L_MIN(rvald, 255);
2015 gvald = (((vals >> 16) & 0xff) * gval16) / 256;
2016 gvald = L_MIN(gvald, 255);
2017 bvald = (((vals >> 8) & 0xff) * bval16) / 256;
2018 bvald = L_MIN(bvald, 255);
2019 composeRGBPixel(rvald, gvald, bvald, flined + xoff + m);
2063l_int32 i, j, w, h, d, wpls, wplg, wpld, vals, valg, vald;
2065l_uint32 *datas, *datag, *datad, *lines, *lineg, *lined;
2070 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2072 return (
PIX *)ERROR_PTR(
"pixg not defined", __func__, NULL);
2073 if (!pixSizesEqual(pixs, pixg))
2074 return (
PIX *)ERROR_PTR(
"pix sizes not equal", __func__, NULL);
2075 pixGetDimensions(pixs, &w, &h, &d);
2077 return (
PIX *)ERROR_PTR(
"depth not 8 bpp", __func__, NULL);
2087 if (w * h > 100000) {
2088 lut = (l_uint8 *)LEPT_CALLOC(0x10000,
sizeof(l_uint8));
2089 for (i = 0; i < 256; i++) {
2090 for (j = 0; j < 256; j++) {
2091 fval = (l_float32)(i * target) / (j + 0.5);
2092 lut[(i << 8) + j] = L_MIN(255, (l_int32)(fval + 0.5));
2097 if ((pixd = pixCreate(w, h, 8)) == NULL) {
2099 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2101 pixCopyResolution(pixd, pixs);
2102 datad = pixGetData(pixd);
2103 wpld = pixGetWpl(pixd);
2104 datas = pixGetData(pixs);
2105 wpls = pixGetWpl(pixs);
2106 datag = pixGetData(pixg);
2107 wplg = pixGetWpl(pixg);
2108 for (i = 0; i < h; i++) {
2109 lines = datas + i * wpls;
2110 lineg = datag + i * wplg;
2111 lined = datad + i * wpld;
2113 for (j = 0; j < w; j++) {
2116 vald = lut[(vals << 8) + valg];
2121 for (j = 0; j < w; j++) {
2124 fval = (l_float32)(vals * target) / (valg + 0.5);
2125 vald = L_MIN(255, (l_int32)(fval + 0.5));
2181l_int32 w, h, d, i, j, ncolors, rv, gv, bv, wpl;
2182l_int32 *rarray, *garray, *barray;
2183l_uint32 *data, *line;
2184NUMA *nar, *nag, *nab;
2188 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2189 cmap = pixGetColormap(pixs);
2190 pixGetDimensions(pixs, &w, &h, &d);
2191 if (!cmap && d != 32)
2192 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
2194 L_WARNING(
"mapval must be > 0; setting to 255\n", __func__);
2199 if ((pixd = pixCopy(pixd, pixs)) == NULL)
2200 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2204 nar = numaGammaTRC(1.0, 0, L_MAX(1, 255 * rval / mapval));
2205 nag = numaGammaTRC(1.0, 0, L_MAX(1, 255 * gval / mapval));
2206 nab = numaGammaTRC(1.0, 0, L_MAX(1, 255 * bval / mapval));
2209 rarray = numaGetIArray(nar);
2210 garray = numaGetIArray(nag);
2211 barray = numaGetIArray(nab);
2212 if (!nar || !nag || !nab || !rarray || !garray || !barray) {
2213 L_ERROR(
"allocation failure in arrays\n", __func__);
2214 goto cleanup_arrays;
2218 ncolors = pixcmapGetCount(cmap);
2219 for (i = 0; i < ncolors; i++) {
2220 pixcmapGetColor(cmap, i, &rv, &gv, &bv);
2221 pixcmapResetColor(cmap, i, rarray[rv], garray[gv], barray[bv]);
2225 data = pixGetData(pixd);
2226 wpl = pixGetWpl(pixd);
2227 for (i = 0; i < h; i++) {
2228 line = data + i * wpl;
2229 for (j = 0; j < w; j++) {
2230 extractRGBValues(line[j], &rv, &gv, &bv);
2231 composeRGBPixel(rarray[rv], garray[gv], barray[bv], line + j);
2290l_float32 rankrval, rankgval, rankbval;
2291l_float32 rfract, gfract, bfract, maxfract;
2294 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2295 if (pixGetDepth(pixs) != 32)
2296 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
2298 return (
PIX *)ERROR_PTR(
"sampling factor < 1", __func__, NULL);
2299 if (rank < 0.0 || rank > 1.0)
2300 return (
PIX *)ERROR_PTR(
"rank not in [0.0 ... 1.0]", __func__, NULL);
2301 if (rval <= 0 || gval <= 0 || bval <= 0)
2302 return (
PIX *)ERROR_PTR(
"invalid estim. color values", __func__, NULL);
2314 pixGetRankValueMaskedRGB(pixs, NULL, 0, 0, factor, rank, &rankrval,
2315 &rankgval, &rankbval);
2316 rfract = rankrval / (l_float32)rval;
2317 gfract = rankgval / (l_float32)gval;
2318 bfract = rankbval / (l_float32)bval;
2319 maxfract = L_MAX(rfract, gfract);
2320 maxfract = L_MAX(maxfract, bfract);
2322 lept_stderr(
"rankrval = %7.2f, rankgval = %7.2f, rankbval = %7.2f\n",
2323 rankrval, rankgval, rankbval);
2324 lept_stderr(
"rfract = %7.4f, gfract = %7.4f, bfract = %7.4f\n",
2325 rfract, gfract, bfract);
2328 mapval = (l_int32)(255. / maxfract);
2389 l_int32 targetthresh,
2394PIX *pixe, *pixet, *pixsd, *pixg1, *pixg2, *pixth;
2396 if (ppixth) *ppixth = NULL;
2397 if (ppixb) *ppixb = NULL;
2398 if (ppixd) *ppixd = NULL;
2399 if (!pixs || pixGetDepth(pixs) != 8)
2400 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
2401 if (pixGetColormap(pixs))
2402 return ERROR_INT(
"pixs is colormapped", __func__, 1);
2403 if (!ppixth && !ppixb && !ppixd)
2404 return ERROR_INT(
"no output requested", __func__, 1);
2406 return ERROR_INT(
"invalid filter type", __func__, 1);
2414 pixet = pixThresholdToBinary(pixe, edgethresh);
2415 pixInvert(pixet, pixet);
2419 pixsd = pixCreateTemplate(pixs);
2420 pixCombineMasked(pixsd, pixs, pixet);
2423 pixg1 = pixSeedspread(pixsd, 4);
2424 pixg2 = pixBlockconv(pixg1, smoothx, smoothy);
2427 pixth = pixGammaTRC(NULL, pixg2, gamma, minval, maxval);
2433 *ppixb = pixThresholdToBinary(*ppixd, targetthresh);
2436 *ppixb = pixVarThresholdToBinary(pixs, pixth);
2492l_float32 scalex, scaley;
2493PIX *pixt, *pixsd, *pixmin, *pixbg, *pixbgi, *pixd;
2495 if (!pixs || pixGetDepth(pixs) != 8)
2496 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
2497 if (pixGetColormap(pixs))
2498 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, NULL);
2499 if (sx < 3 || sy < 3)
2500 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 3", __func__, NULL);
2501 if (sx > 10 || sy > 10)
2502 return (
PIX *)ERROR_PTR(
"sx and/or sy exceed 10", __func__, NULL);
2503 if (smoothx < 1 || smoothy < 1)
2504 return (
PIX *)ERROR_PTR(
"smooth params less than 1", __func__, NULL);
2505 if (smoothx > 3 || smoothy > 3)
2506 return (
PIX *)ERROR_PTR(
"smooth params exceed 3", __func__, NULL);
2509 scalex = 1. / (l_float32)sx;
2510 scaley = 1. / (l_float32)sy;
2511 pixt = pixScaleSmooth(pixs, scalex, scaley);
2515 pixsd = pixClone(pixt);
2517 pixLocalExtrema(pixt, 0, 0, &pixmin, NULL);
2518 pixsd = pixSeedfillGrayBasin(pixmin, pixt, delta, 4);
2519 pixDestroy(&pixmin);
2530 pixDestroy(&pixbgi);
2586PIX *pixmin, *pixmax;
2588 if (!pixs || pixGetDepth(pixs) != 8)
2589 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, pixd);
2590 if (pixd && pixd != pixs)
2591 return (
PIX *)ERROR_PTR(
"pixd not null or == pixs", __func__, pixd);
2592 if (pixGetColormap(pixs))
2593 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, pixd);
2594 if (sx < 5 || sy < 5)
2595 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 5", __func__, pixd);
2596 if (smoothx < 0 || smoothy < 0)
2597 return (
PIX *)ERROR_PTR(
"smooth params less than 0", __func__, pixd);
2598 if (smoothx > 8 || smoothy > 8)
2599 return (
PIX *)ERROR_PTR(
"smooth params exceed 8", __func__, pixd);
2603 pixMinMaxTiles(pixs, sx, sy, mindiff, smoothx, smoothy, &pixmin, &pixmax);
2610 pixDestroy(&pixmin);
2611 pixDestroy(&pixmax);
2646PIX *pixmin1, *pixmax1, *pixmin2, *pixmax2;
2648 if (ppixmin) *ppixmin = NULL;
2649 if (ppixmax) *ppixmax = NULL;
2650 if (!ppixmin || !ppixmax)
2651 return ERROR_INT(
"&pixmin or &pixmax undefined", __func__, 1);
2652 if (!pixs || pixGetDepth(pixs) != 8)
2653 return ERROR_INT(
"pixs undefined or not 8 bpp", __func__, 1);
2654 if (pixGetColormap(pixs))
2655 return ERROR_INT(
"pixs is colormapped", __func__, 1);
2656 if (sx < 5 || sy < 5)
2657 return ERROR_INT(
"sx and/or sy less than 3", __func__, 1);
2658 if (smoothx < 0 || smoothy < 0)
2659 return ERROR_INT(
"smooth params less than 0", __func__, 1);
2660 if (smoothx > 5 || smoothy > 5)
2661 return ERROR_INT(
"smooth params exceed 5", __func__, 1);
2664 pixmin1 = pixScaleGrayMinMax(pixs, sx, sy, L_CHOOSE_MIN);
2665 pixmax1 = pixScaleGrayMinMax(pixs, sx, sy, L_CHOOSE_MAX);
2669 pixDestroy(&pixmin1);
2670 pixDestroy(&pixmax1);
2673 pixAddConstantGray(pixmin2, 1);
2674 pixAddConstantGray(pixmax2, 1);
2680 pixGetDimensions(pixmin2, &w, &h, NULL);
2685 if (smoothx > 0 || smoothy > 0) {
2686 smoothx = L_MIN(smoothx, (w - 1) / 2);
2687 smoothy = L_MIN(smoothy, (h - 1) / 2);
2688 *ppixmin = pixBlockconv(pixmin2, smoothx, smoothy);
2689 *ppixmax = pixBlockconv(pixmax2, smoothx, smoothy);
2692 *ppixmin = pixClone(pixmin2);
2693 *ppixmax = pixClone(pixmax2);
2695 pixCopyResolution(*ppixmin, pixs);
2696 pixCopyResolution(*ppixmax, pixs);
2697 pixDestroy(&pixmin2);
2698 pixDestroy(&pixmax2);
2729l_int32 i, j, w, h, d, wpl, val1, val2, found;
2730l_uint32 *data1, *data2, *line1, *line2;
2732 if (!pixs1 || !pixs2)
2733 return ERROR_INT(
"pixs1 and pixs2 not both defined", __func__, 1);
2734 if (pixSizesEqual(pixs1, pixs2) == 0)
2735 return ERROR_INT(
"pixs1 and pixs2 not equal size", __func__, 1);
2736 pixGetDimensions(pixs1, &w, &h, &d);
2738 return ERROR_INT(
"depth not 8 bpp", __func__, 1);
2739 if (mindiff > 254)
return 0;
2741 data1 = pixGetData(pixs1);
2742 data2 = pixGetData(pixs2);
2743 wpl = pixGetWpl(pixs1);
2745 for (i = 0; i < h; i++) {
2746 line1 = data1 + i * wpl;
2747 line2 = data2 + i * wpl;
2748 for (j = 0; j < w; j++) {
2751 if (L_ABS(val1 - val2) >= mindiff) {
2759 L_WARNING(
"no pixel pair diffs as large as mindiff\n", __func__);
2765 for (i = 0; i < h; i++) {
2766 line1 = data1 + i * wpl;
2767 line2 = data2 + i * wpl;
2768 for (j = 0; j < w; j++) {
2771 if (L_ABS(val1 - val2) < mindiff) {
2813l_int32 i, j, k, m, w, h, wt, ht, wpl, wplt, xoff, yoff;
2814l_int32 minval, maxval, val, sval;
2817l_uint32 *data, *datamin, *datamax, *line, *tline, *linemin, *linemax;
2819 if (!pixs || pixGetDepth(pixs) != 8)
2820 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, pixd);
2821 if (pixd && pixd != pixs)
2822 return (
PIX *)ERROR_PTR(
"pixd not null or == pixs", __func__, pixd);
2823 if (pixGetColormap(pixs))
2824 return (
PIX *)ERROR_PTR(
"pixs is colormapped", __func__, pixd);
2825 if (!pixmin || !pixmax)
2826 return (
PIX *)ERROR_PTR(
"pixmin & pixmax not defined", __func__, pixd);
2827 if (sx < 5 || sy < 5)
2828 return (
PIX *)ERROR_PTR(
"sx and/or sy less than 5", __func__, pixd);
2830 iaa = (l_int32 **)LEPT_CALLOC(256,
sizeof(l_int32 *));
2831 if ((pixd = pixCopy(pixd, pixs)) == NULL) {
2833 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2835 pixGetDimensions(pixd, &w, &h, NULL);
2837 data = pixGetData(pixd);
2838 wpl = pixGetWpl(pixd);
2839 datamin = pixGetData(pixmin);
2840 datamax = pixGetData(pixmax);
2841 wplt = pixGetWpl(pixmin);
2842 pixGetDimensions(pixmin, &wt, &ht, NULL);
2843 for (i = 0; i < ht; i++) {
2844 line = data + sy * i * wpl;
2845 linemin = datamin + i * wplt;
2846 linemax = datamax + i * wplt;
2848 for (j = 0; j < wt; j++) {
2852 if (maxval == minval) {
2853 L_ERROR(
"shouldn't happen! i,j = %d,%d, minval = %d\n",
2854 __func__, i, j, minval);
2858 L_ERROR(
"failure to make ia for j = %d!\n", __func__, j);
2861 for (k = 0; k < sy && yoff + k < h; k++) {
2862 tline = line + k * wpl;
2863 for (m = 0; m < sx && xoff + m < w; m++) {
2865 sval = val - minval;
2866 sval = L_MAX(0, sval);
2873 for (i = 0; i < 256; i++)
2898 return (l_int32 *)ERROR_PTR(
"iaa not defined", __func__, NULL);
2900 if (iaa[diff] != NULL)
2903 ia = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2906 for (i = 0; i < 256; i++)
2910 factor = 255. / (l_float32)diff;
2911 for (i = 0; i < diff + 1; i++)
2912 ia[i] = (l_int32)(factor * i + 0.5);
2913 for (i = diff + 1; i < 256; i++)
2951 l_int32 scalefactor)
2953PIX *pix1, *pix2, *pixd;
2956 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2957 if (contrast < 1 || contrast > 10)
2958 return (
PIX *)ERROR_PTR(
"contrast not in [1 ... 10]", __func__, NULL);
2959 if (scalefactor != 1 && scalefactor != 2)
2960 return (
PIX *)ERROR_PTR(
"scalefactor not 1 or 2", __func__, NULL);
2962 if (pixGetDepth(pixs) == 1) {
2963 pixd = pixCopy(NULL, pixs);
2968 if (scalefactor == 1)
2969 pixd = pixThresholdToBinary(pix2, 180);
2971 pixd = pixScaleGray2xLIThresh(pix2, 180);
2998 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3000 d = pixGetDepth(pixs);
3002 return pixConvert1To8(NULL, pixs, 255, 0);
3003 }
else if (d == 2) {
3004 return pixConvert2To8(pixs, 0, 85, 170, 255, FALSE);
3005 }
else if (d == 4) {
3006 return pixConvert4To8(pixs, FALSE);
3007 }
else if (d == 8) {
3008 if (pixGetColormap(pixs) != NULL)
3011 return pixCopy(NULL, pixs);
3012 }
else if (d == 16) {
3013 return pixConvert16To8(pixs,
L_MS_BYTE);
3014 }
else if (d == 32) {
3015 return pixConvertRGBToGrayMinMax(pixs, L_CHOOSE_MIN);
3018 L_ERROR(
"Invalid depth d = %d\n", __func__, d);
3049 if (!pixs || pixGetDepth(pixs) != 8)
3050 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
3053 pixGammaTRC(pixs, pixs, 2.0, 50, 200);
3054 else if (contrast == 2)
3055 pixGammaTRC(pixs, pixs, 1.8, 60, 200);
3056 else if (contrast == 3)
3057 pixGammaTRC(pixs, pixs, 1.6, 70, 200);
3058 else if (contrast == 4)
3059 pixGammaTRC(pixs, pixs, 1.4, 80, 200);
3060 else if (contrast == 5)
3061 pixGammaTRC(pixs, pixs, 1.2, 90, 200);
3062 else if (contrast == 6)
3063 pixGammaTRC(pixs, pixs, 1.0, 100, 200);
3064 else if (contrast == 7)
3065 pixGammaTRC(pixs, pixs, 0.85, 110, 200);
3066 else if (contrast == 8)
3067 pixGammaTRC(pixs, pixs, 0.7, 120, 200);
3068 else if (contrast == 9)
3069 pixGammaTRC(pixs, pixs, 0.6, 130, 200);
3071 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