int main(int argc, char **argv) { char buffer1[256]; char buffer2[256]; l_int32 i, same, same2, factor1, factor2, diff, success; PIX *pixs, *pixsd, *pixt1, *pixt2, *pixt3; static char mainName[] = "binmorph2_reg"; if (argc != 1) return ERROR_INT(" Syntax: binmorph2_reg", mainName, 1); pixs = pixRead("rabi.png"); pixsd = pixMorphCompSequence(pixs, "d5.5", 0); success = TRUE; for (i = 1; i < MAX_SEL_SIZE; i++) { /* Check if the size is exactly decomposable */ selectComposableSizes(i, &factor1, &factor2); diff = factor1 * factor2 - i; fprintf(stderr, "%d: (%d, %d): %d\n", i, factor1, factor2, diff); /* Carry out operations on identical sized Sels: dilation */ sprintf(buffer1, "d%d.%d", i + diff, i + diff); sprintf(buffer2, "d%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... erosion */ sprintf(buffer1, "e%d.%d", i + diff, i + diff); sprintf(buffer2, "e%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... opening */ sprintf(buffer1, "o%d.%d", i + diff, i + diff); sprintf(buffer2, "o%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... closing */ sprintf(buffer1, "c%d.%d", i + diff, i + diff); sprintf(buffer2, "c%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); } pixDestroy(&pixs); pixDestroy(&pixsd); if (success) fprintf(stderr, "\n---------- Success: no errors ----------\n"); else fprintf(stderr, "\n---------- Failure: error(s) found -----------\n"); return 0; }
main(int argc, char **argv) { char *str; char buffer1[256]; char buffer2[256]; l_int32 i, same, same2, factor1, factor2, diff, success; PIX *pixs, *pixsd, *pixt1, *pixt2, *pixt3; SEL *sel1, *sel2; static char mainName[] = "binmorph2_reg"; #if 1 pixs = pixRead("rabi.png"); pixsd = pixMorphCompSequence(pixs, "d5.5", 0); success = TRUE; for (i = 1; i < MAX_SEL_SIZE; i++) { /* Check if the size is exactly decomposable */ selectComposableSizes(i, &factor1, &factor2); diff = factor1 * factor2 - i; fprintf(stderr, "%d: (%d, %d): %d\n", i, factor1, factor2, diff); /* Carry out operations on identical sized Sels: dilation */ sprintf(buffer1, "d%d.%d", i + diff, i + diff); sprintf(buffer2, "d%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... erosion */ sprintf(buffer1, "e%d.%d", i + diff, i + diff); sprintf(buffer2, "e%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... opening */ sprintf(buffer1, "o%d.%d", i + diff, i + diff); sprintf(buffer2, "o%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ... closing */ sprintf(buffer1, "c%d.%d", i + diff, i + diff); sprintf(buffer2, "c%d.%d", i, i); pixt1 = pixMorphSequence(pixsd, buffer1, 0); pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); pixEqual(pixt1, pixt2, &same); if (i < 64) { pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); pixEqual(pixt1, pixt3, &same2); } else { pixt3 = NULL; same2 = TRUE; } if (same && same2) writeResult(buffer1, 1); else { writeResult(buffer1, 0); success = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); } pixDestroy(&pixs); pixDestroy(&pixsd); if (success) fprintf(stderr, "\n---------- Success: no errors ----------\n"); else fprintf(stderr, "\n---------- Failure: error(s) found -----------\n"); #endif #if 0 for (i = 1; i < 400; i++) { selectComposableSizes(i, &factor1, &factor2); diff = factor1 * factor2 - i; fprintf(stderr, "%d: (%d, %d): %d\n", i, factor1, factor2, diff); selectComposableSels(i, L_HORIZ, &sel1, &sel2); selDestroy(&sel1); selDestroy(&sel2); } #endif #if 0 selectComposableSels(68, L_HORIZ, &sel1, &sel2); /* 17, 4 */ str = selPrintToString(sel2); fprintf(stderr, str); selDestroy(&sel1); selDestroy(&sel2); FREE(str); selectComposableSels(70, L_HORIZ, &sel1, &sel2); /* 10, 7 */ str = selPrintToString(sel2); selDestroy(&sel1); selDestroy(&sel2); fprintf(stderr, str); FREE(str); selectComposableSels(85, L_HORIZ, &sel1, &sel2); /* 17, 5 */ str = selPrintToString(sel2); selDestroy(&sel1); selDestroy(&sel2); fprintf(stderr, str); FREE(str); selectComposableSels(96, L_HORIZ, &sel1, &sel2); /* 12, 8 */ str = selPrintToString(sel2); selDestroy(&sel1); selDestroy(&sel2); fprintf(stderr, str); FREE(str); { SELA *sela; sela = selaAddBasic(NULL); selaWrite("/tmp/junksela.sela", sela); selaDestroy(&sela); } #endif return 0; }
main(int argc, char **argv) { char *infile; PIX *pixs, *pixg, *pixc, *pixd; static char mainName[] = "morphseq_reg"; if (argc != 1) return ERROR_INT(" Syntax: morphseq_reg", mainName, 1); pixs = pixRead("feyn.tif"); /* 1 bpp */ pixd = pixMorphSequence(pixs, SEQUENCE1, -1); pixDestroy(&pixd); pixd = pixMorphSequence(pixs, SEQUENCE1, DISPLAY_SEPARATION); pixWrite("/tmp/morphseq1.png", pixd, IFF_PNG); pixDestroy(&pixd); pixd = pixMorphCompSequence(pixs, SEQUENCE2, -2); pixDestroy(&pixd); pixd = pixMorphCompSequence(pixs, SEQUENCE2, DISPLAY_SEPARATION); pixWrite("/tmp/morphseq2.png", pixd, IFF_PNG); pixDestroy(&pixd); pixd = pixMorphSequenceDwa(pixs, SEQUENCE2, -3); pixDestroy(&pixd); pixd = pixMorphSequenceDwa(pixs, SEQUENCE2, DISPLAY_SEPARATION); pixWrite("/tmp/morphseq3.png", pixd, IFF_PNG); pixDestroy(&pixd); pixd = pixMorphCompSequenceDwa(pixs, SEQUENCE2, -4); pixDestroy(&pixd); pixd = pixMorphCompSequenceDwa(pixs, SEQUENCE2, DISPLAY_SEPARATION); pixWrite("/tmp/morphseq4.png", pixd, IFF_PNG); pixDestroy(&pixd); /* 8 bpp */ pixg = pixScaleToGray(pixs, 0.25); pixd = pixGrayMorphSequence(pixg, SEQUENCE3, -5, 150); pixDestroy(&pixd); pixd = pixGrayMorphSequence(pixg, SEQUENCE3, DISPLAY_SEPARATION, 150); pixWrite("/tmp/morphseq5.png", pixd, IFF_PNG); pixDestroy(&pixd); pixd = pixGrayMorphSequence(pixg, SEQUENCE4, -6, 300); pixWrite("/tmp/morphseq6.png", pixd, IFF_PNG); pixDestroy(&pixd); /* 32 bpp */ pixc = pixRead("wyom.jpg"); pixd = pixColorMorphSequence(pixc, SEQUENCE5, -7, 150); pixDestroy(&pixd); pixd = pixColorMorphSequence(pixc, SEQUENCE5, DISPLAY_SEPARATION, 450); pixWrite("/tmp/morphseq7.png", pixd, IFF_PNG); pixDestroy(&pixc); pixDestroy(&pixd); /* Syntax error handling */ fprintf(stderr, " ------------ Error messages follow ------------------\n"); pixd = pixMorphSequence(pixs, BAD_SEQUENCE, 50); /* fails; returns null */ pixd = pixGrayMorphSequence(pixg, BAD_SEQUENCE, 50, 0); /* this fails */ pixDestroy(&pixg); pixDestroy(&pixs); return 0; }