main(int argc, char **argv) { PIX *pix; SEL *sel; SELA *sela1, *sela2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* selaRead() / selaWrite() */ sela1 = selaAddBasic(NULL); selaWrite("/tmp/sel.0.sela", sela1); regTestCheckFile(rp, "/tmp/sel.0.sela"); /* 0 */ sela2 = selaRead("/tmp/sel.0.sela"); selaWrite("/tmp/sel.1.sela", sela2); regTestCheckFile(rp, "/tmp/sel.1.sela"); /* 1 */ regTestCompareFiles(rp, 0, 1); /* 2 */ selaDestroy(&sela1); selaDestroy(&sela2); /* Create from file and display result */ sela1 = selaCreateFromFile("flipsels.txt"); pix = selaDisplayInPix(sela1, 31, 3, 15, 4); regTestWritePixAndCheck(rp, pix, IFF_PNG); /* 3 */ pixDisplayWithTitle(pix, 100, 100, NULL, rp->display); selaWrite("/tmp/sel.3.sela", sela1); regTestCheckFile(rp, "/tmp/sel.3.sela"); /* 4 */ pixDestroy(&pix); selaDestroy(&sela1); /* Create the same set of Sels from compiled strings and compare */ sela2 = selaCreate(4); sel = selCreateFromString(textsel1, 5, 6, "textsel1"); selaAddSel(sela2, sel, NULL, 0); sel = selCreateFromString(textsel2, 5, 6, "textsel2"); selaAddSel(sela2, sel, NULL, 0); sel = selCreateFromString(textsel3, 5, 6, "textsel3"); selaAddSel(sela2, sel, NULL, 0); sel = selCreateFromString(textsel4, 5, 6, "textsel4"); selaAddSel(sela2, sel, NULL, 0); selaWrite("/tmp/sel.4.sela", sela2); regTestCheckFile(rp, "/tmp/sel.4.sela"); /* 5 */ regTestCompareFiles(rp, 4, 5); /* 6 */ selaDestroy(&sela2); return regTestCleanup(rp); }
main(int argc, char **argv) { PIX *pixd; SEL *sel1, *sel2, *sel3, *sel4; SELA *sela; static char mainName[] = "livre_orient"; sel1 = selCreateFromString(textsel1, 5, 6, NULL); sel2 = selCreateFromString(textsel2, 5, 6, NULL); sel3 = selCreateFromString(textsel3, 5, 6, NULL); sel4 = selCreateFromString(textsel4, 5, 6, NULL); sela = selaCreate(4); selaAddSel(sela, sel1, "textsel1", L_INSERT); selaAddSel(sela, sel2, "textsel2", L_INSERT); selaAddSel(sela, sel3, "textsel3", L_INSERT); selaAddSel(sela, sel4, "textsel4", L_INSERT); pixd = selaDisplayInPix(sela, 28, 3, 30, 4); pixWrite("/tmp/orient.png", pixd, IFF_PNG); pixDisplay(pixd, 100, 100); pixDestroy(&pixd); selaDestroy(&sela); return 0; }
int main(int argc, char **argv) { l_int32 i, nsels, same1, same2, ok; char *filein, *selname; PIX *pixs, *pixref, *pixt1, *pixt2, *pixt3, *pixt4; SEL *sel; SELA *sela; static char mainName[] = "fhmtauto_reg"; if (argc != 2) return ERROR_INT(" Syntax: fhmtauto_reg filein", mainName, 1); filein = argv[1]; if ((pixs = pixRead(filein)) == NULL) return ERROR_INT("pixs not made", mainName, 1); sela = selaAddHitMiss(NULL); nsels = selaGetCount(sela); ok = TRUE; for (i = 0; i < nsels; i++) { sel = selaGetSel(sela, i); selname = selGetName(sel); pixref = pixHMT(NULL, pixs, sel); pixt1 = pixAddBorder(pixs, 32, 0); pixt2 = pixFHMTGen_1(NULL, pixt1, selname); pixt3 = pixRemoveBorder(pixt2, 32); pixt4 = pixHMTDwa_1(NULL, pixs, selname); pixEqual(pixref, pixt3, &same1); pixEqual(pixref, pixt4, &same2); if (same1 && same2) fprintf(stderr, "hmt are identical for sel %d (%s)\n", i, selname); else { fprintf(stderr, "hmt differ for sel %d (%s)\n", i, selname); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); } if (ok) fprintf(stderr, "\n ******** All hmt are correct *******\n"); else fprintf(stderr, "\n ******** ERROR in at least one hmt *******\n"); pixDestroy(&pixs); selaDestroy(&sela); return 0; }
int main(int argc, char **argv) { SEL *sel1, *sel2, *sel3, *sel4; SELA *sela; PIX *pix, *pixd; PIXA *pixa; static char mainName[] = "flipselgen"; if (argc != 1) return ERROR_INT(" Syntax: flipselgen", mainName, 1); sela = selaCreate(0); sel1 = selCreateFromString(textsel1, 5, 6, "flipsel1"); sel2 = selCreateFromString(textsel2, 5, 6, "flipsel2"); sel3 = selCreateFromString(textsel3, 5, 6, "flipsel3"); sel4 = selCreateFromString(textsel4, 5, 6, "flipsel4"); selaAddSel(sela, sel1, NULL, 0); selaAddSel(sela, sel2, NULL, 0); selaAddSel(sela, sel3, NULL, 0); selaAddSel(sela, sel4, NULL, 0); pixa = pixaCreate(4); pix = selDisplayInPix(sel1, 23, 2); pixDisplayWithTitle(pix, 100, 100, "sel1", DFLAG); pixaAddPix(pixa, pix, L_INSERT); pix = selDisplayInPix(sel2, 23, 2); pixDisplayWithTitle(pix, 275, 100, "sel2", DFLAG); pixaAddPix(pixa, pix, L_INSERT); pix = selDisplayInPix(sel3, 23, 2); pixDisplayWithTitle(pix, 450, 100, "sel3", DFLAG); pixaAddPix(pixa, pix, L_INSERT); pix = selDisplayInPix(sel4, 23, 2); pixDisplayWithTitle(pix, 625, 100, "sel4", DFLAG); pixaAddPix(pixa, pix, L_INSERT); pixd = pixaDisplayTiled(pixa, 800, 0, 15); pixDisplayWithTitle(pixd, 100, 300, "allsels", DFLAG); pixDestroy(&pixd); pixaDestroy(&pixa); if (fhmtautogen(sela, INDEX, NULL)) return ERROR_INT(" Generation failed", mainName, 1); selaDestroy(&sela); return 0; }
/*! * pixThin() * * Input: pixs (1 bpp) * type (L_THIN_FG, L_THIN_BG) * connectivity (4 or 8) * maxiters (max number of iters allowed; use 0 to iterate * until completion) * Return: pixd, or null on error * * Notes: * (1) See "Connectivity-preserving morphological image transformations," * Dan S. Bloomberg, in SPIE Visual Communications and Image * Processing, Conference 1606, pp. 320-334, November 1991, * Boston, MA. A web version is available at * http://www.leptonica.com/papers/conn.pdf * (2) We implement here two of the best iterative * morphological thinning algorithms, for 4 c.c and 8 c.c. * Each iteration uses a mixture of parallel operations * (using several different 3x3 Sels) and serial operations. * Specifically, each thinning iteration consists of * four sequential thinnings from each of four directions. * Each of these thinnings is a parallel composite * operation, where the union of a set of HMTs are set * subtracted from the input. For 4-cc thinning, we * use 3 HMTs in parallel, and for 8-cc thinning we use 4 HMTs. * (3) A "good" thinning algorithm is one that generates a skeleton * that is near the medial axis and has neither pruned * real branches nor left extra dendritic branches. * (4) To thin the foreground, which is the usual situation, * use type == L_THIN_FG. Thickening the foreground is equivalent * to thinning the background (type == L_THIN_BG), where the * opposite connectivity gets preserved. For example, to thicken * the fg using 4-connectivity, we thin the bg using Sels that * preserve 8-connectivity. */ PIX * pixThin(PIX *pixs, l_int32 type, l_int32 connectivity, l_int32 maxiters) { PIX *pixd; SEL *sel; SELA *sela; PROCNAME("pixThin"); if (!pixs) return (PIX *)ERROR_PTR("pixs not defined", procName, NULL); if (pixGetDepth(pixs) != 1) return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, NULL); if (type != L_THIN_FG && type != L_THIN_BG) return (PIX *)ERROR_PTR("invalid fg/bg type", procName, NULL); if (connectivity != 4 && connectivity != 8) return (PIX *)ERROR_PTR("connectivity not 4 or 8", procName, NULL); if (maxiters == 0) maxiters = 10000; sela = selaCreate(4); if (connectivity == 4) { sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); selaAddSel(sela, sel, NULL, 0); } else { /* connectivity == 8 */ sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); selaAddSel(sela, sel, NULL, 0); } pixd = pixThinGeneral(pixs, type, sela, maxiters); selaDestroy(&sela); return pixd; }
int main(int argc, char **argv) { char *filename; l_int32 index; SELA *sela; static char mainName[] = "fmorphautogen"; if (argc != 2 && argc != 3) return ERROR_INT(" Syntax: fmorphautogen index <filename>", mainName, 1); index = atoi(argv[1]); filename = NULL; if (argc == 3) filename = argv[2]; sela = selaAddBasic(NULL); if (fmorphautogen(sela, index, filename)) return 1; selaDestroy(&sela); return 0; }
main(int argc, char **argv) { l_int32 i, nsels, same, xorcount; char *selname; PIX *pixs, *pixs1, *pixt1, *pixt2, *pixt3; SEL *sel; SELA *sela; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; if ((pixs = pixRead("feyn-fract.tif")) == NULL) { rp->success = FALSE; regTestCleanup(rp); return 1; } sela = selaAddDwaLinear(NULL); nsels = selaGetCount(sela); for (i = 0; i < nsels; i++) { sel = selaGetSel(sela, i); selname = selGetName(sel); /* --------- dilation ----------*/ pixt1 = pixDilate(NULL, pixs, sel); pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_DILATE, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "dilations are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "dilations differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- erosion with asymmetric b.c ----------*/ resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixErode(NULL, pixs, sel); pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_ERODE, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "erosions are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "erosions differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- erosion with symmetric b.c ----------*/ resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixErode(NULL, pixs, sel); pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_ERODE, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "erosions are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "erosions differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- opening with asymmetric b.c ----------*/ resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixOpen(NULL, pixs, sel); pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_OPEN, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "openings are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "openings differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- opening with symmetric b.c ----------*/ resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixOpen(NULL, pixs, sel); pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_OPEN, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "openings are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "openings differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- safe closing with asymmetric b.c ----------*/ resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixCloseSafe(NULL, pixs, sel); /* must use safe version */ pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_CLOSE, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "closings are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "closings differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); /* --------- safe closing with symmetric b.c ----------*/ resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC); fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC); pixt1 = pixClose(NULL, pixs, sel); /* safe version not required */ pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_CLOSE, selname); pixEqual(pixt1, pixt2, &same); if (same == 1) { fprintf(stderr, "closings are identical for sel %d (%s)\n", i, selname); } else { rp->success = FALSE; fprintf(rp->fp, "closings differ for sel %d (%s)\n", i, selname); pixt3 = pixXor(NULL, pixt1, pixt2); pixCountPixels(pixt3, &xorcount, NULL); fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount); pixDestroy(&pixt3); } pixDestroy(&pixt1); pixDestroy(&pixt2); } selaDestroy(&sela); pixDestroy(&pixs); return regTestCleanup(rp); }
/*! * pixThinExamples() * * Input: pixs (1 bpp) * type (L_THIN_FG, L_THIN_BG) * index (into specific examples; valid 1-9; see notes) * maxiters (max number of iters allowed; use 0 to iterate * until completion) * selfile (<optional> filename for output sel display) * Return: pixd, or null on error * * Notes: * (1) See notes in pixThin(). The examples are taken from * the paper referenced there. * (2) Here we allow specific sets of HMTs to be used in * parallel for thinning from each of four directions. * One iteration consists of four such parallel thins. * (3) The examples are indexed as follows: * Thinning (e.g., run to completion): * index = 1 sel_4_1, sel_4_5, sel_4_6 * index = 2 sel_4_1, sel_4_7, sel_4_7_rot * index = 3 sel_48_1, sel_48_1_rot, sel_48_2 * index = 4 sel_8_2, sel_8_3, sel_48_2 * index = 5 sel_8_1, sel_8_5, sel_8_6 * index = 6 sel_8_2, sel_8_3, sel_8_8, sel_8_9 * index = 7 sel_8_5, sel_8_6, sel_8_7, sel_8_7_rot * Thickening: * index = 8 sel_4_2, sel_4_3 (e.g,, do just a few iterations) * index = 9 sel_8_4 (e.g., do just a few iterations) */ PIX * pixThinExamples(PIX *pixs, l_int32 type, l_int32 index, l_int32 maxiters, const char *selfile) { PIX *pixd, *pixt; SEL *sel; SELA *sela; PROCNAME("pixThinExamples"); if (!pixs) return (PIX *)ERROR_PTR("pixs not defined", procName, NULL); if (pixGetDepth(pixs) != 1) return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, NULL); if (type != L_THIN_FG && type != L_THIN_BG) return (PIX *)ERROR_PTR("invalid fg/bg type", procName, NULL); if (index < 1 || index > 9) return (PIX *)ERROR_PTR("invalid index", procName, NULL); if (maxiters == 0) maxiters = 10000; switch(index) { case 1: sela = selaCreate(3); sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_5, 3, 3, "sel_4_5"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_6, 3, 3, "sel_4_6"); selaAddSel(sela, sel, NULL, 0); break; case 2: sela = selaCreate(3); sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_7, 3, 3, "sel_4_7"); selaAddSel(sela, sel, NULL, 0); sel = selRotateOrth(sel, 1); selaAddSel(sela, sel, "sel_4_7_rot", 0); break; case 3: sela = selaCreate(3); sel = selCreateFromString(sel_48_1, 3, 3, "sel_48_1"); selaAddSel(sela, sel, NULL, 0); sel = selRotateOrth(sel, 1); selaAddSel(sela, sel, "sel_48_1_rot", 0); sel = selCreateFromString(sel_48_2, 3, 3, "sel_48_2"); selaAddSel(sela, sel, NULL, 0); break; case 4: sela = selaCreate(3); sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_48_2, 3, 3, "sel_48_2"); selaAddSel(sela, sel, NULL, 0); break; case 5: sela = selaCreate(3); sel = selCreateFromString(sel_8_1, 3, 3, "sel_8_1"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); selaAddSel(sela, sel, NULL, 0); break; case 6: sela = selaCreate(4); sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_8, 3, 3, "sel_8_8"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_9, 3, 3, "sel_8_9"); selaAddSel(sela, sel, NULL, 0); break; case 7: sela = selaCreate(4); sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_8_7, 3, 3, "sel_8_7"); selaAddSel(sela, sel, NULL, 0); sel = selRotateOrth(sel, 1); selaAddSel(sela, sel, "sel_8_7_rot", 0); break; case 8: /* thicken for this one; just a few iterations */ sela = selaCreate(2); sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); selaAddSel(sela, sel, NULL, 0); sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); selaAddSel(sela, sel, NULL, 0); pixt = pixThinGeneral(pixs, type, sela, maxiters); pixd = pixRemoveBorderConnComps(pixt, 4); pixDestroy(&pixt); break; case 9: /* thicken for this one; just a few iterations */ sela = selaCreate(1); sel = selCreateFromString(sel_8_4, 3, 3, "sel_8_4"); selaAddSel(sela, sel, NULL, 0); pixt = pixThinGeneral(pixs, type, sela, maxiters); pixd = pixRemoveBorderConnComps(pixt, 4); pixDestroy(&pixt); break; default: return (PIX *)ERROR_PTR("invalid index", procName, NULL); } if (index <= 7) pixd = pixThinGeneral(pixs, type, sela, maxiters); /* Optionally display the sels */ if (selfile) { pixt = selaDisplayInPix(sela, 35, 3, 15, 4); pixWrite(selfile, pixt, IFF_PNG); pixDestroy(&pixt); } selaDestroy(&sela); return pixd; }
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; }
int main(int argc, char **argv) { BOX *box; PIX *pix, *pixs, *pixd, *pixt; PIXA *pixa; SEL *sel, *sel1, *sel2, *sel3; SELA *sela4, *sela8, *sela48; static char mainName[] = "ccthin1_reg"; if (argc != 1) return ERROR_INT(" Syntax: ccthin1_reg", mainName, 1); /* Generate and display all of the 4-cc sels */ sela4 = selaCreate(9); sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_4, 3, 3, "sel_4_4"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_5, 3, 3, "sel_4_5"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_6, 3, 3, "sel_4_6"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_7, 3, 3, "sel_4_7"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_8, 3, 3, "sel_4_8"); selaAddSel(sela4, sel, NULL, 0); sel = selCreateFromString(sel_4_9, 3, 3, "sel_4_9"); selaAddSel(sela4, sel, NULL, 0); pixt = selaDisplayInPix(sela4, 35, 3, 15, 3); pixWrite("/tmp/junkallsel4.png", pixt, IFF_PNG); pixDestroy(&pixt); selaDestroy(&sela4); /* Generate and display all of the 8-cc sels */ sela8 = selaCreate(9); sel = selCreateFromString(sel_8_1, 3, 3, "sel_8_1"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_4, 3, 3, "sel_8_4"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_7, 3, 3, "sel_8_7"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_8, 3, 3, "sel_8_8"); selaAddSel(sela8, sel, NULL, 0); sel = selCreateFromString(sel_8_9, 3, 3, "sel_8_9"); selaAddSel(sela8, sel, NULL, 0); pixt = selaDisplayInPix(sela8, 35, 3, 15, 3); pixWrite("/tmp/junkallsel8.png", pixt, IFF_PNG); pixDestroy(&pixt); selaDestroy(&sela8); /* Generate and display all of the 4 and 8-cc preserving sels */ sela48 = selaCreate(3); sel = selCreateFromString(sel_48_1, 3, 3, "sel_48_1"); selaAddSel(sela48, sel, NULL, 0); sel = selCreateFromString(sel_48_2, 3, 3, "sel_48_2"); selaAddSel(sela48, sel, NULL, 0); pixt = selaDisplayInPix(sela48, 35, 3, 15, 4); pixWrite("/tmp/junkallsel48.png", pixt, IFF_PNG); pixDestroy(&pixt); selaDestroy(&sela48); /* Generate and display three of the 4-cc sels and their rotations */ sela4 = selaCreate(3); sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela4, sel, NULL, 0); selaAddSel(sela4, sel1, "sel_4_1_90", 0); selaAddSel(sela4, sel2, "sel_4_1_180", 0); selaAddSel(sela4, sel3, "sel_4_1_270", 0); sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela4, sel, NULL, 0); selaAddSel(sela4, sel1, "sel_4_2_90", 0); selaAddSel(sela4, sel2, "sel_4_2_180", 0); selaAddSel(sela4, sel3, "sel_4_2_270", 0); sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela4, sel, NULL, 0); selaAddSel(sela4, sel1, "sel_4_3_90", 0); selaAddSel(sela4, sel2, "sel_4_3_180", 0); selaAddSel(sela4, sel3, "sel_4_3_270", 0); pixt = selaDisplayInPix(sela4, 35, 3, 15, 4); pixWrite("/tmp/junksel4.png", pixt, IFF_PNG); pixDestroy(&pixt); selaDestroy(&sela4); /* Generate and display four of the 8-cc sels and their rotations */ sela8 = selaCreate(4); sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela8, sel, NULL, 0); selaAddSel(sela8, sel1, "sel_8_2_90", 0); selaAddSel(sela8, sel2, "sel_8_2_180", 0); selaAddSel(sela8, sel3, "sel_8_2_270", 0); sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela8, sel, NULL, 0); selaAddSel(sela8, sel1, "sel_8_3_90", 0); selaAddSel(sela8, sel2, "sel_8_3_180", 0); selaAddSel(sela8, sel3, "sel_8_3_270", 0); sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela8, sel, NULL, 0); selaAddSel(sela8, sel1, "sel_8_5_90", 0); selaAddSel(sela8, sel2, "sel_8_5_180", 0); selaAddSel(sela8, sel3, "sel_8_5_270", 0); sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); sel1 = selRotateOrth(sel, 1); sel2 = selRotateOrth(sel, 2); sel3 = selRotateOrth(sel, 3); selaAddSel(sela8, sel, NULL, 0); selaAddSel(sela8, sel1, "sel_8_6_90", 0); selaAddSel(sela8, sel2, "sel_8_6_180", 0); selaAddSel(sela8, sel3, "sel_8_6_270", 0); pixt = selaDisplayInPix(sela8, 35, 3, 15, 4); pixWrite("/tmp/junksel8.png", pixt, IFF_PNG); pixDestroy(&pixt); selaDestroy(&sela8); /* Test the best 4 and 8 cc thinning */ pixDisplayWrite(NULL, 0); pix = pixRead("feyn.tif"); box = boxCreate(683, 799, 970, 479); pixs = pixClipRectangle(pix, box, NULL); pixDisplayWrite(pixs, 1); pixt = pixThin(pixs, L_THIN_FG, 4, 0); pixDisplayWrite(pixt, 1); pixDestroy(&pixt); pixt = pixThin(pixs, L_THIN_BG, 4, 0); pixDisplayWrite(pixt, 1); pixDestroy(&pixt); pixt = pixThin(pixs, L_THIN_FG, 8, 0); pixDisplayWrite(pixt, 1); pixDestroy(&pixt); pixt = pixThin(pixs, L_THIN_BG, 8, 0); pixDisplayWrite(pixt, 1); pixDestroy(&pixt); /* Display tiled */ pixa = pixaReadFiles("/tmp/display", "file"); pixd = pixaDisplayTiledAndScaled(pixa, 8, 500, 1, 0, 25, 2); pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); pixDestroy(&pix); pixDestroy(&pixs); boxDestroy(&box); pixDisplayMultiple("/tmp/display/file*"); return 0; }
int main(int argc, char **argv) { char *selname; l_int32 i, j, nsels, sx, sy; l_float32 fact, time; GPLOT *gplot; NUMA *na1, *na2, *na3, *na4, *nac1, *nac2, *nac3, *nac4, *nax; PIX *pixs, *pixt; PIXA *pixa; SEL *sel; SELA *selalinear; static char mainName[] = "dwamorph2_reg"; if (argc != 1) return ERROR_INT(" Syntax: dwamorph2_reg", mainName, 1); pixs = pixRead("feyn-fract.tif"); pixt = pixCreateTemplate(pixs); selalinear = selaAddDwaLinear(NULL); nsels = selaGetCount(selalinear); fact = 1000. / (l_float32)NTIMES; /* converts to time in msec */ na1 = numaCreate(64); na2 = numaCreate(64); na3 = numaCreate(64); na4 = numaCreate(64); lept_mkdir("lept/morph"); /* --------- dilation ----------*/ for (i = 0; i < nsels / 2; i++) { sel = selaGetSel(selalinear, i); selGetParameters(sel, &sy, &sx, NULL, NULL); selname = selGetName(sel); fprintf(stderr, " %d .", i); startTimer(); for (j = 0; j < NTIMES; j++) pixDilate(pixt, pixs, sel); time = fact * stopTimer(); numaAddNumber(na1, time); startTimer(); for (j = 0; j < NTIMES; j++) pixDilateCompBrick(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na2, time); startTimer(); for (j = 0; j < NTIMES; j++) pixMorphDwa_3(pixt, pixs, L_MORPH_DILATE, selname); time = fact * stopTimer(); numaAddNumber(na3, time); startTimer(); for (j = 0; j < NTIMES; j++) pixDilateCompBrickDwa(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na4, time); } nax = numaMakeSequence(2, 1, nsels / 2); nac1 = numaWindowedMean(na1, HALFWIDTH); nac2 = numaWindowedMean(na2, HALFWIDTH); nac3 = numaWindowedMean(na3, HALFWIDTH); nac4 = numaWindowedMean(na4, HALFWIDTH); gplot = gplotCreate("/tmp/lept/morph/dilate", GPLOT_PNG, "Dilation time vs sel size", "size", "time (ms)"); gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nac1); numaDestroy(&nac2); numaDestroy(&nac3); numaDestroy(&nac4); /* --------- erosion ----------*/ numaEmpty(na1); numaEmpty(na2); numaEmpty(na3); numaEmpty(na4); for (i = 0; i < nsels / 2; i++) { sel = selaGetSel(selalinear, i); selGetParameters(sel, &sy, &sx, NULL, NULL); selname = selGetName(sel); fprintf(stderr, " %d .", i); startTimer(); for (j = 0; j < NTIMES; j++) pixErode(pixt, pixs, sel); time = fact * stopTimer(); numaAddNumber(na1, time); startTimer(); for (j = 0; j < NTIMES; j++) pixErodeCompBrick(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na2, time); startTimer(); for (j = 0; j < NTIMES; j++) pixMorphDwa_3(pixt, pixs, L_MORPH_ERODE, selname); time = fact * stopTimer(); numaAddNumber(na3, time); startTimer(); for (j = 0; j < NTIMES; j++) pixErodeCompBrickDwa(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na4, time); } nac1 = numaWindowedMean(na1, HALFWIDTH); nac2 = numaWindowedMean(na2, HALFWIDTH); nac3 = numaWindowedMean(na3, HALFWIDTH); nac4 = numaWindowedMean(na4, HALFWIDTH); gplot = gplotCreate("/tmp/lept/morph/erode", GPLOT_PNG, "Erosion time vs sel size", "size", "time (ms)"); gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nac1); numaDestroy(&nac2); numaDestroy(&nac3); numaDestroy(&nac4); /* --------- opening ----------*/ numaEmpty(na1); numaEmpty(na2); numaEmpty(na3); numaEmpty(na4); for (i = 0; i < nsels / 2; i++) { sel = selaGetSel(selalinear, i); selGetParameters(sel, &sy, &sx, NULL, NULL); selname = selGetName(sel); fprintf(stderr, " %d .", i); startTimer(); for (j = 0; j < NTIMES; j++) pixOpen(pixt, pixs, sel); time = fact * stopTimer(); numaAddNumber(na1, time); startTimer(); for (j = 0; j < NTIMES; j++) pixOpenCompBrick(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na2, time); startTimer(); for (j = 0; j < NTIMES; j++) pixMorphDwa_3(pixt, pixs, L_MORPH_OPEN, selname); time = fact * stopTimer(); numaAddNumber(na3, time); startTimer(); for (j = 0; j < NTIMES; j++) pixOpenCompBrickDwa(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na4, time); } nac1 = numaWindowedMean(na1, HALFWIDTH); nac2 = numaWindowedMean(na2, HALFWIDTH); nac3 = numaWindowedMean(na3, HALFWIDTH); nac4 = numaWindowedMean(na4, HALFWIDTH); gplot = gplotCreate("/tmp/lept/morph/open", GPLOT_PNG, "Opening time vs sel size", "size", "time (ms)"); gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nac1); numaDestroy(&nac2); numaDestroy(&nac3); numaDestroy(&nac4); /* --------- closing ----------*/ numaEmpty(na1); numaEmpty(na2); numaEmpty(na3); numaEmpty(na4); for (i = 0; i < nsels / 2; i++) { sel = selaGetSel(selalinear, i); selGetParameters(sel, &sy, &sx, NULL, NULL); selname = selGetName(sel); fprintf(stderr, " %d .", i); startTimer(); for (j = 0; j < NTIMES; j++) pixClose(pixt, pixs, sel); time = fact * stopTimer(); numaAddNumber(na1, time); startTimer(); for (j = 0; j < NTIMES; j++) pixCloseCompBrick(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na2, time); startTimer(); for (j = 0; j < NTIMES; j++) pixMorphDwa_3(pixt, pixs, L_MORPH_CLOSE, selname); time = fact * stopTimer(); numaAddNumber(na3, time); startTimer(); for (j = 0; j < NTIMES; j++) pixCloseCompBrickDwa(pixt, pixs, sx, sy); time = fact * stopTimer(); numaAddNumber(na4, time); } nac1 = numaWindowedMean(na1, HALFWIDTH); nac2 = numaWindowedMean(na2, HALFWIDTH); nac3 = numaWindowedMean(na3, HALFWIDTH); nac4 = numaWindowedMean(na4, HALFWIDTH); gplot = gplotCreate("/tmp/lept/morph/close", GPLOT_PNG, "Closing time vs sel size", "size", "time (ms)"); gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); gplotMakeOutput(gplot); #ifndef _WIN32 sleep(1); #else Sleep(1000); #endif /* _WIN32 */ gplotDestroy(&gplot); numaDestroy(&nac1); numaDestroy(&nac2); numaDestroy(&nac3); numaDestroy(&nac4); numaDestroy(&na1); numaDestroy(&na2); numaDestroy(&na3); numaDestroy(&na4); numaDestroy(&nax); selaDestroy(&selalinear); pixDestroy(&pixt); pixDestroy(&pixs); /* Display the results together */ pixa = pixaCreate(0); pixs = pixRead("/tmp/lept/morph/dilate.png"); pixaAddPix(pixa, pixs, L_INSERT); pixs = pixRead("/tmp/lept/morph/erode.png"); pixaAddPix(pixa, pixs, L_INSERT); pixs = pixRead("/tmp/lept/morph/open.png"); pixaAddPix(pixa, pixs, L_INSERT); pixs = pixRead("/tmp/lept/morph/close.png"); pixaAddPix(pixa, pixs, L_INSERT); pixt = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 40, 3); pixWrite("/tmp/lept/morph/timings.png", pixt, IFF_PNG); pixDisplay(pixt, 100, 100); pixDestroy(&pixt); pixaDestroy(&pixa); return 0; }
main(int argc, char **argv) { char *selnameh, *selnamev; l_int32 ok, same, w, h, i, bordercolor, extraborder; l_int32 width[3] = {21, 1, 21}; l_int32 height[3] = {1, 7, 7}; PIX *pixs, *pixref; PIX *pixt0, *pixt1, *pixt2, *pixt3, *pixt4; SEL *sel; SELA *sela; static char mainName[] = "binmorph3_reg"; if (argc != 1) exit(ERROR_INT(" Syntax: binmorph3_reg", mainName, 1)); if ((pixs = pixRead("feyn.tif")) == NULL) exit(ERROR_INT("pix not made", mainName, 1)); #if TEST_SYMMETRIC resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC); #endif /* TEST_SYMMETRIC */ for (i = 0; i < 3; i++) { w = width[i]; h = height[i]; sel = selCreateBrick(h, w, h / 2, w / 2, SEL_HIT); selnameh = NULL; selnamev = NULL; /* Get the selnames for horiz and vert */ sela = selaAddBasic(NULL); if (w > 1) { if ((selnameh = selaGetBrickName(sela, w, 1)) == NULL) { selaDestroy(&sela); return ERROR_INT("dwa hor sel not defined", mainName, 1); } } if (h > 1) { if ((selnamev = selaGetBrickName(sela, 1, h)) == NULL) { selaDestroy(&sela); return ERROR_INT("dwa vert sel not defined", mainName, 1); } } fprintf(stderr, "w = %d, h = %d, selh = %s, selv = %s\n", w, h, selnameh, selnamev); ok = TRUE; selaDestroy(&sela); /* ----------------- Dilation ----------------- */ fprintf(stderr, "Testing dilation\n"); pixref = pixDilate(NULL, pixs, sel); pixt1 = pixDilateBrickDwa(NULL, pixs, w, h); pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixDestroy(&pixt1); if (w > 1) pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_DILATE, selnameh); else pixt1 = pixClone(pixs); if (h > 1) pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_DILATE, selnamev); else pixt2 = pixClone(pixt1); pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixAddBorder(pixs, 32, 0); if (w > 1) pixt2 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_DILATE, selnameh); else pixt2 = pixClone(pixt1); if (h > 1) pixt3 = pixFMorphopGen_1(NULL, pixt2, L_MORPH_DILATE, selnamev); else pixt3 = pixClone(pixt2); pixt4 = pixRemoveBorder(pixt3, 32); pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); /* ----------------- Erosion ----------------- */ fprintf(stderr, "Testing erosion\n"); pixref = pixErode(NULL, pixs, sel); pixt1 = pixErodeBrickDwa(NULL, pixs, w, h); pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixDestroy(&pixt1); if (w > 1) pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_ERODE, selnameh); else pixt1 = pixClone(pixs); if (h > 1) pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_ERODE, selnamev); else pixt2 = pixClone(pixt1); pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixAddBorder(pixs, 32, 0); if (w > 1) pixt2 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_ERODE, selnameh); else pixt2 = pixClone(pixt1); if (h > 1) pixt3 = pixFMorphopGen_1(NULL, pixt2, L_MORPH_ERODE, selnamev); else pixt3 = pixClone(pixt2); pixt4 = pixRemoveBorder(pixt3, 32); pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); /* ----------------- Opening ----------------- */ fprintf(stderr, "Testing opening\n"); pixref = pixOpen(NULL, pixs, sel); pixt1 = pixOpenBrickDwa(NULL, pixs, w, h); pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixDestroy(&pixt1); if (h == 1) pixt2 = pixMorphDwa_1(NULL, pixs, L_MORPH_OPEN, selnameh); else if (w == 1) pixt2 = pixMorphDwa_1(NULL, pixs, L_MORPH_OPEN, selnamev); else { pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_ERODE, selnameh); pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_ERODE, selnamev); pixMorphDwa_1(pixt1, pixt2, L_MORPH_DILATE, selnameh); pixMorphDwa_1(pixt2, pixt1, L_MORPH_DILATE, selnamev); pixDestroy(&pixt1); } pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } pixDestroy(&pixt2); pixt1 = pixAddBorder(pixs, 32, 0); if (h == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_OPEN, selnameh); else if (w == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_OPEN, selnamev); else { pixt2 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_ERODE, selnameh); pixt3 = pixFMorphopGen_1(NULL, pixt2, L_MORPH_ERODE, selnamev); pixFMorphopGen_1(pixt2, pixt3, L_MORPH_DILATE, selnameh); pixFMorphopGen_1(pixt3, pixt2, L_MORPH_DILATE, selnamev); pixDestroy(&pixt2); } pixt4 = pixRemoveBorder(pixt3, 32); pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt3); pixDestroy(&pixt4); /* ----------------- Closing ----------------- */ fprintf(stderr, "Testing closing\n"); pixref = pixClose(NULL, pixs, sel); /* Note: L_MORPH_CLOSE for h==1 or w==1 gives safe closing, * so we can't use it here. */ if (h == 1) { pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_DILATE, selnameh); pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_ERODE, selnameh); } else if (w == 1) { pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_DILATE, selnamev); pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_ERODE, selnamev); } else { pixt1 = pixMorphDwa_1(NULL, pixs, L_MORPH_DILATE, selnameh); pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_DILATE, selnamev); pixMorphDwa_1(pixt1, pixt2, L_MORPH_ERODE, selnameh); pixMorphDwa_1(pixt2, pixt1, L_MORPH_ERODE, selnamev); } pixDestroy(&pixt1); pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } pixDestroy(&pixt2); /* Note: by adding only 32 pixels of border, we get * the normal closing operation, even when calling * with L_MORPH_CLOSE, because it requires 32 pixels * of border to be safe. */ pixt1 = pixAddBorder(pixs, 32, 0); if (h == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_CLOSE, selnameh); else if (w == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_CLOSE, selnamev); else { pixt2 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_DILATE, selnameh); pixt3 = pixFMorphopGen_1(NULL, pixt2, L_MORPH_DILATE, selnamev); pixFMorphopGen_1(pixt2, pixt3, L_MORPH_ERODE, selnameh); pixFMorphopGen_1(pixt3, pixt2, L_MORPH_ERODE, selnamev); pixDestroy(&pixt2); } pixt4 = pixRemoveBorder(pixt3, 32); pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt3); pixDestroy(&pixt4); /* ------------- Safe Closing ----------------- */ fprintf(stderr, "Testing safe closing\n"); pixref = pixCloseSafe(NULL, pixs, sel); pixt0 = pixCloseSafeBrick(NULL, pixs, w, h); pixEqual(pixref, pixt0, &same); if (!same) { fprintf(stderr, "pixref != pixt0 !\n"); ok = FALSE; } pixDestroy(&pixt0); pixt1 = pixCloseBrickDwa(NULL, pixs, w, h); pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixDestroy(&pixt1); bordercolor = getMorphBorderPixelColor(L_MORPH_ERODE, 1); if (bordercolor == 0) /* asymmetric b.c. */ extraborder = 32; else /* symmetric b.c. */ extraborder = 0; /* Note: for safe closing we need 64 border pixels. * However, when we implement a separable Sel * with pixMorphDwa_*(), we must do dilation and * erosion explicitly, and these functions only * add/remove a 32-pixel border. Thus, for that * case we must add an additional 32-pixel border * before doing the operations. That is the reason * why the implementation in morphdwa.c adds the * 64 bit border and then uses the lower-level * pixFMorphopGen_*() functions. */ if (h == 1) pixt3 = pixMorphDwa_1(NULL, pixs, L_MORPH_CLOSE, selnameh); else if (w == 1) pixt3 = pixMorphDwa_1(NULL, pixs, L_MORPH_CLOSE, selnamev); else { pixt0 = pixAddBorder(pixs, extraborder, 0); pixt1 = pixMorphDwa_1(NULL, pixt0, L_MORPH_DILATE, selnameh); pixt2 = pixMorphDwa_1(NULL, pixt1, L_MORPH_DILATE, selnamev); pixMorphDwa_1(pixt1, pixt2, L_MORPH_ERODE, selnameh); pixMorphDwa_1(pixt2, pixt1, L_MORPH_ERODE, selnamev); pixt3 = pixRemoveBorder(pixt2, extraborder); pixDestroy(&pixt0); pixDestroy(&pixt1); pixDestroy(&pixt2); } pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } pixDestroy(&pixt3); pixt1 = pixAddBorder(pixs, 32 + extraborder, 0); if (h == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_CLOSE, selnameh); else if (w == 1) pixt3 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_CLOSE, selnamev); else { pixt2 = pixFMorphopGen_1(NULL, pixt1, L_MORPH_DILATE, selnameh); pixt3 = pixFMorphopGen_1(NULL, pixt2, L_MORPH_DILATE, selnamev); pixFMorphopGen_1(pixt2, pixt3, L_MORPH_ERODE, selnameh); pixFMorphopGen_1(pixt3, pixt2, L_MORPH_ERODE, selnamev); pixDestroy(&pixt2); } pixt4 = pixRemoveBorder(pixt3, 32 + extraborder); pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt3); pixDestroy(&pixt4); if (ok) fprintf(stderr, "All morph tests OK!\n"); selDestroy(&sel); lept_free(selnameh); lept_free(selnamev); } pixDestroy(&pixs); return 0; }