55 #include <config_auto.h>
59 #include "allheaders.h"
138 const char *sequence,
143 l_int32 nops, i, j, nred, fact, w, h, x, border, pdfout;
149 PROCNAME(
"pixMorphSequence");
152 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
154 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
158 sarraySplitString(sa, sequence,
"+");
160 pdfout = (dispsep < 0) ? 1 : 0;
163 return (
PIX *)ERROR_PTR(
"sequence not valid", procName, NULL);
176 for (i = 0; i < nops; i++) {
183 sscanf(&op[1],
"%d.%d", &w, &h);
189 sscanf(&op[1],
"%d.%d", &w, &h);
195 sscanf(&op[1],
"%d.%d", &w, &h);
200 sscanf(&op[1],
"%d.%d", &w, &h);
205 nred = strlen(op) - 1;
206 for (j = 0; j < nred; j++)
207 level[j] = op[j + 1] -
'0';
208 for (j = nred; j < 4; j++)
216 sscanf(&op[1],
"%d", &fact);
222 sscanf(&op[1],
"%d", &border);
234 pixDisplay(pix1, x, 0);
246 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
305 const char *sequence,
310 l_int32 nops, i, j, nred, fact, w, h, x, border, pdfout;
316 PROCNAME(
"pixMorphCompSequence");
319 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
321 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
325 sarraySplitString(sa, sequence,
"+");
327 pdfout = (dispsep < 0) ? 1 : 0;
331 return (
PIX *)ERROR_PTR(
"sequence not valid", procName, NULL);
344 for (i = 0; i < nops; i++) {
351 sscanf(&op[1],
"%d.%d", &w, &h);
357 sscanf(&op[1],
"%d.%d", &w, &h);
363 sscanf(&op[1],
"%d.%d", &w, &h);
368 sscanf(&op[1],
"%d.%d", &w, &h);
373 nred = strlen(op) - 1;
374 for (j = 0; j < nred; j++)
375 level[j] = op[j + 1] -
'0';
376 for (j = nred; j < 4; j++)
384 sscanf(&op[1],
"%d", &fact);
390 sscanf(&op[1],
"%d", &border);
402 pixDisplay(pix1, x, 0);
414 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
454 const char *sequence,
459 l_int32 nops, i, j, nred, fact, w, h, x, border, pdfout;
465 PROCNAME(
"pixMorphSequenceDwa");
468 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
470 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
474 sarraySplitString(sa, sequence,
"+");
476 pdfout = (dispsep < 0) ? 1 : 0;
480 return (
PIX *)ERROR_PTR(
"sequence not valid", procName, NULL);
493 for (i = 0; i < nops; i++) {
500 sscanf(&op[1],
"%d.%d", &w, &h);
506 sscanf(&op[1],
"%d.%d", &w, &h);
512 sscanf(&op[1],
"%d.%d", &w, &h);
517 sscanf(&op[1],
"%d.%d", &w, &h);
522 nred = strlen(op) - 1;
523 for (j = 0; j < nred; j++)
524 level[j] = op[j + 1] -
'0';
525 for (j = nred; j < 4; j++)
533 sscanf(&op[1],
"%d", &fact);
539 sscanf(&op[1],
"%d", &border);
551 pixDisplay(pix1, x, 0);
563 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
603 const char *sequence,
608 l_int32 nops, i, j, nred, fact, w, h, x, border, pdfout;
614 PROCNAME(
"pixMorphCompSequenceDwa");
617 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
619 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
623 sarraySplitString(sa, sequence,
"+");
625 pdfout = (dispsep < 0) ? 1 : 0;
629 return (
PIX *)ERROR_PTR(
"sequence not valid", procName, NULL);
642 for (i = 0; i < nops; i++) {
649 sscanf(&op[1],
"%d.%d", &w, &h);
655 sscanf(&op[1],
"%d.%d", &w, &h);
661 sscanf(&op[1],
"%d.%d", &w, &h);
666 sscanf(&op[1],
"%d.%d", &w, &h);
671 nred = strlen(op) - 1;
672 for (j = 0; j < nred; j++)
673 level[j] = op[j + 1] -
'0';
674 for (j = nred; j < 4; j++)
682 sscanf(&op[1],
"%d", &fact);
688 sscanf(&op[1],
"%d", &border);
700 pixDisplay(pix1, x, 0);
712 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
744 l_int32 nops, i, j, nred, fact, valid, w, h, netred, border;
746 l_int32 intlogbase2[5] = {1, 2, 3, 0, 4};
748 PROCNAME(
"morphSequenceVerify");
751 return ERROR_INT(
"sa not defined", procName, FALSE);
757 for (i = 0; i < nops; i++) {
770 if (sscanf(&op[1],
"%d.%d", &w, &h) != 2) {
775 if (w <= 0 || h <= 0) {
776 lept_stderr(
"*** op: %s; w = %d, h = %d; must both be > 0\n",
785 nred = strlen(op) - 1;
787 if (nred < 1 || nred > 4) {
789 "*** op = %s; num reduct = %d; must be in {1,2,3,4}\n",
794 for (j = 0; j < nred; j++) {
795 level[j] = op[j + 1] -
'0';
796 if (level[j] < 1 || level[j] > 4) {
797 lept_stderr(
"*** op = %s; level[%d] = %d is invalid\n",
806 for (j = 0; j < nred; j++) {
807 level[j] = op[j + 1] -
'0';
814 if (sscanf(&op[1],
"%d", &fact) != 1) {
819 if (fact != 2 && fact != 4 && fact != 8 && fact != 16) {
820 lept_stderr(
"*** op = %s; invalid fact = %d\n", op, fact);
824 netred -= intlogbase2[fact / 4];
829 if (sscanf(&op[1],
"%d", &fact) != 1) {
835 lept_stderr(
"*** op = %s; must be first op\n", op);
840 lept_stderr(
"*** op = %s; invalid fact = %d\n", op, fact);
854 if (border != 0 && netred != 0) {
855 lept_stderr(
"*** op = %s; border added but net reduction not 0\n", op);
915 const char *sequence,
921 l_int32 nops, i, valid, w, h, x, pdfout;
926 PROCNAME(
"pixGrayMorphSequence");
929 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
931 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
935 sarraySplitString(sa, sequence,
"+");
937 pdfout = (dispsep < 0) ? 1 : 0;
941 for (i = 0; i < nops; i++) {
954 if (sscanf(&op[1],
"%d.%d", &w, &h) != 2) {
959 if (w < 1 || (w & 1) == 0 || h < 1 || (h & 1) == 0 ) {
960 lept_stderr(
"*** op: %s; w = %d, h = %d; must both be odd\n",
969 if (op[1] !=
'w' && op[1] !=
'W' &&
970 op[1] !=
'b' && op[1] !=
'B') {
972 "*** op = %s; arg %c must be 'w' or 'b'\n", op, op[1]);
976 sscanf(&op[2],
"%d.%d", &w, &h);
977 if (w < 1 || (w & 1) == 0 || h < 1 || (h & 1) == 0 ) {
978 lept_stderr(
"*** op: %s; w = %d, h = %d; must both be odd\n",
993 return (
PIX *)ERROR_PTR(
"sequence invalid", procName, NULL);
1005 for (i = 0; i < nops; i++) {
1012 sscanf(&op[1],
"%d.%d", &w, &h);
1018 sscanf(&op[1],
"%d.%d", &w, &h);
1024 sscanf(&op[1],
"%d.%d", &w, &h);
1030 sscanf(&op[1],
"%d.%d", &w, &h);
1036 sscanf(&op[2],
"%d.%d", &w, &h);
1037 if (op[1] ==
'w' || op[1] ==
'W')
1038 pix2 =
pixTophat(pix1, w, h, L_TOPHAT_WHITE);
1040 pix2 =
pixTophat(pix1, w, h, L_TOPHAT_BLACK);
1051 pixDisplay(pix1, x, dispy);
1059 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
1118 const char *sequence,
1124 l_int32 nops, i, valid, w, h, x, pdfout;
1129 PROCNAME(
"pixColorMorphSequence");
1132 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1134 return (
PIX *)ERROR_PTR(
"sequence not defined", procName, NULL);
1138 sarraySplitString(sa, sequence,
"+");
1140 pdfout = (dispsep < 0) ? 1 : 0;
1144 for (i = 0; i < nops; i++) {
1157 if (sscanf(&op[1],
"%d.%d", &w, &h) != 2) {
1162 if (w < 1 || (w & 1) == 0 || h < 1 || (h & 1) == 0 ) {
1163 lept_stderr(
"*** op: %s; w = %d, h = %d; must both be odd\n",
1178 return (
PIX *)ERROR_PTR(
"sequence invalid", procName, NULL);
1190 for (i = 0; i < nops; i++) {
1197 sscanf(&op[1],
"%d.%d", &w, &h);
1203 sscanf(&op[1],
"%d.%d", &w, &h);
1209 sscanf(&op[1],
"%d.%d", &w, &h);
1215 sscanf(&op[1],
"%d.%d", &w, &h);
1227 pixDisplay(pix1, x, dispy);
1235 snprintf(fname,
sizeof(fname),
"/tmp/lept/seq_output_%d.pdf",
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
PIX * pixColorMorph(PIX *pixs, l_int32 type, l_int32 hsize, l_int32 vsize)
pixColorMorph()
PIX * pixCloseGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseGray()
PIX * pixDilateGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateGray()
PIX * pixOpenGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixOpenGray()
PIX * pixErodeGray(PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeGray()
PIX * pixOpenBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixOpenBrick()
PIX * pixOpenCompBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixOpenCompBrick()
PIX * pixCloseSafeCompBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseSafeCompBrick()
PIX * pixCloseSafeBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseSafeBrick()
PIX * pixErodeBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeBrick()
PIX * pixDilateBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateBrick()
PIX * pixDilateCompBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateCompBrick()
PIX * pixErodeCompBrick(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeCompBrick()
PIX * pixTophat(PIX *pixs, l_int32 hsize, l_int32 vsize, l_int32 type)
pixTophat()
PIX * pixErodeCompBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeCompBrickDwa()
PIX * pixOpenCompBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixOpenCompBrickDwa()
PIX * pixCloseCompBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseCompBrickDwa()
PIX * pixOpenBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixOpenBrickDwa()
PIX * pixCloseBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixCloseBrickDwa()
PIX * pixErodeBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixErodeBrickDwa()
PIX * pixDilateCompBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateCompBrickDwa()
PIX * pixDilateBrickDwa(PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize)
pixDilateBrickDwa()
PIX * pixMorphSequenceDwa(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphSequenceDwa()
PIX * pixMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphSequence()
l_int32 morphSequenceVerify(SARRAY *sa)
morphSequenceVerify()
PIX * pixColorMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep, l_int32 dispy)
pixColorMorphSequence()
PIX * pixMorphCompSequenceDwa(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphCompSequenceDwa()
PIX * pixGrayMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep, l_int32 dispy)
pixGrayMorphSequence()
PIX * pixMorphCompSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphCompSequence()
l_ok pixaConvertToPdf(PIXA *pixa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
pixaConvertToPdf()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
l_ok pixSwapAndDestroy(PIX **ppixd, PIX **ppixs)
pixSwapAndDestroy()
PIX * pixAddBorder(PIX *pixs, l_int32 npix, l_uint32 val)
pixAddBorder()
PIX * pixRemoveBorder(PIX *pixs, l_int32 npix)
pixRemoveBorder()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
PIX * pixExpandReplicate(PIX *pixs, l_int32 factor)
pixExpandReplicate()
void lept_stderr(const char *fmt,...)
lept_stderr()
char * stringRemoveChars(const char *src, const char *remchars)
stringRemoveChars()