main(int argc, char **argv) { l_int32 i, index; l_float32 cputime, epo; char *filein, *fileout; PIX *pixs, *pixd; SEL *sel; SELA *sela; static char mainName[] = "morphtest1"; if (argc != 3) exit(ERROR_INT(" Syntax: morphtest1 filein fileout", mainName, 1)); filein = argv[1]; fileout = argv[2]; if ((pixs = pixRead(filein)) == NULL) exit(ERROR_INT("pix not made", mainName, 1)); sela = selaAddBasic(NULL); /* ------------------------ Timing -------------------------------*/ #if 1 selaFindSelByName(sela, "sel_9h", &index, &sel); selWriteStream(stderr, sel); pixd = pixCreateTemplate(pixs); startTimer(); for (i = 0; i < NTIMES; i++) { pixDilate(pixd, pixs, sel); /* if ((i % 10) == 0) fprintf(stderr, "%d iters\n", i); */ } cputime = stopTimer(); /* Get the elementary pixel operations/sec */ epo = BASIC_OPS * SEL_SIZE * NTIMES * IMAGE_SIZE /(cputime * CPU_SPEED); fprintf(stderr, "Time: %7.3f sec\n", cputime); fprintf(stderr, "Speed: %7.3f epo/cycle\n", epo); pixWrite(fileout, pixd, IFF_PNG); pixDestroy(&pixd); #endif /* ------------------ Example operation from repository --------------*/ #if 1 /* Select a structuring element */ selaFindSelByName(sela, "sel_50h", &index, &sel); selWriteStream(stderr, sel); /* Do these operations. See below for other ops * that can be substituted here. */ pixd = pixOpen(NULL, pixs, sel); pixXor(pixd, pixd, pixs); pixWrite(fileout, pixd, IFF_PNG); pixDestroy(&pixd); #endif pixDestroy(&pixs); exit(0); }
int QfwToolBox::insertItem(int index, QWidget *widget, const QString &text) { if (!widget) return -1; connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*))); Page c; c.widget = widget; c.button = new QPushButton(this); c.button->setBackgroundRole(QPalette::Window); c.button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); c.button->setFocusPolicy(Qt::NoFocus); c.button->setCheckable(true); QString style( "text-align: left;" "background-color: lightgray;" "border-style: solid;" "border-width: 1px;" "border-color: darkgray;" "height: 20px;" ); QPixmap pixOpen(branch_open); QPixmap pixClose(branch_closed); QIcon bIcon; bIcon.addPixmap( pixClose, QIcon::Normal, QIcon::Off ); bIcon.addPixmap( pixOpen, QIcon::Active, QIcon::On ); c.setIcon(bIcon); c.button->setStyleSheet(style); connect(c.button, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); c.sv = new QFrame(this); QVBoxLayout* verticalLayout = new QVBoxLayout(c.sv); verticalLayout->setMargin(0); verticalLayout->addWidget(widget); c.sv->hide(); c.sv->setFrameStyle(QFrame::NoFrame); c.setText(text); if (index < 0 || index >= (int)this->pageList.count()) { index = this->pageList.count(); this->pageList.append(c); this->layout->addWidget(c.button); this->layout->addWidget(c.sv); } else { this->pageList.insert(index, c); this->relayout(); } c.button->show(); return index; }
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); }
return 0; } /* ==================================================================== */ /* -------------------------------------------------------------------- * * Repository for selecting various operations * * that might be used * * -------------------------------------------------------------------- */ #if 0 pixd = pixCreateTemplate(pixs); pixd = pixDilate(NULL, pixs, sel); pixd = pixErode(NULL, pixs, sel); pixd = pixOpen(NULL, pixs, sel); pixd = pixClose(NULL, pixs, sel); pixDilate(pixd, pixs, sel); pixErode(pixd, pixs, sel); pixOpen(pixd, pixs, sel); pixClose(pixd, pixs, sel); pixAnd(pixd, pixd, pixs); pixOr(pixd, pixd, pixs); pixXor(pixd, pixd, pixs); pixSubtract(pixd, pixd, pixs); pixInvert(pixd, pixs); pixd = pixAnd(NULL, pixd, pixs); pixd = pixOr(NULL, pixd, pixs);
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; }
/*! * \brief pixItalicWords() * * \param[in] pixs 1 bpp * \param[in] boxaw [optional] word bounding boxes; can be NULL * \param[in] pixw [optional] word box mask; can be NULL * \param[out] pboxa boxa of italic words * \param[in] debugflag 1 for debug output; 0 otherwise * \return 0 if OK, 1 on error * * <pre> * Notes: * (1) You can input the bounding boxes for the words in one of * two forms: as bounding boxes (%boxaw) or as a word mask with * the word bounding boxes filled (%pixw). For example, * to compute %pixw, you can use pixWordMaskByDilation(). * (2) Alternatively, you can set both of these inputs to NULL, * in which case the word mask is generated here. This is * done by dilating and closing the input image to connect * letters within a word, while leaving the words separated. * The parameters are chosen under the assumption that the * input is 10 to 12 pt text, scanned at about 300 ppi. * (3) sel_ital1 and sel_ital2 detect the right edges that are * nearly vertical, at approximately the angle of italic * strokes. We use the right edge to avoid getting seeds * from lower-case 'y'. The typical italic slant has a smaller * angle with the vertical than the 'W', so in most cases we * will not trigger on the slanted lines in the 'W'. * (4) Note that sel_ital2 is shorter than sel_ital1. It is * more appropriate for a typical font scanned at 200 ppi. * </pre> */ l_int32 pixItalicWords(PIX *pixs, BOXA *boxaw, PIX *pixw, BOXA **pboxa, l_int32 debugflag) { char opstring[32]; l_int32 size; BOXA *boxa; PIX *pixsd, *pixm, *pixd; SEL *sel_ital1, *sel_ital2, *sel_ital3; PROCNAME("pixItalicWords"); if (!pixs) return ERROR_INT("pixs not defined", procName, 1); if (!pboxa) return ERROR_INT("&boxa not defined", procName, 1); if (boxaw && pixw) return ERROR_INT("both boxaw and pixw are defined", procName, 1); sel_ital1 = selCreateFromString(str_ital1, 13, 6, NULL); sel_ital2 = selCreateFromString(str_ital2, 10, 6, NULL); sel_ital3 = selCreateFromString(str_ital3, 4, 2, NULL); /* Make the italic seed: extract with HMT; remove noise. * The noise removal close/open is important to exclude * situations where a small slanted line accidentally * matches sel_ital1. */ pixsd = pixHMT(NULL, pixs, sel_ital1); pixClose(pixsd, pixsd, sel_ital3); pixOpen(pixsd, pixsd, sel_ital3); /* Make the word mask. Use input boxes or mask if given. */ size = 0; /* init */ if (boxaw) { pixm = pixCreateTemplate(pixs); pixMaskBoxa(pixm, pixm, boxaw, L_SET_PIXELS); } else if (pixw) { pixm = pixClone(pixw); } else { pixWordMaskByDilation(pixs, NULL, &size, NULL); L_INFO("dilation size = %d\n", procName, size); snprintf(opstring, sizeof(opstring), "d1.5 + c%d.1", size); pixm = pixMorphSequence(pixs, opstring, 0); } /* Binary reconstruction to fill in those word mask * components for which there is at least one seed pixel. */ pixd = pixSeedfillBinary(NULL, pixsd, pixm, 8); boxa = pixConnComp(pixd, NULL, 8); *pboxa = boxa; if (debugflag) { /* Save results at at 2x reduction */ lept_mkdir("lept/ital"); l_int32 res, upper; BOXA *boxat; GPLOT *gplot; NUMA *na; PIXA *pad; PIX *pix1, *pix2, *pix3; pad = pixaCreate(0); boxat = pixConnComp(pixm, NULL, 8); boxaWrite("/tmp/lept/ital/ital.ba", boxat); pixSaveTiledOutline(pixs, pad, 0.5, 1, 20, 2, 32); /* orig */ pixSaveTiledOutline(pixsd, pad, 0.5, 1, 20, 2, 0); /* seed */ pix1 = pixConvertTo32(pixm); pixRenderBoxaArb(pix1, boxat, 3, 255, 0, 0); pixSaveTiledOutline(pix1, pad, 0.5, 1, 20, 2, 0); /* mask + outline */ pixDestroy(&pix1); pixSaveTiledOutline(pixd, pad, 0.5, 1, 20, 2, 0); /* ital mask */ pix1 = pixConvertTo32(pixs); pixRenderBoxaArb(pix1, boxa, 3, 255, 0, 0); pixSaveTiledOutline(pix1, pad, 0.5, 1, 20, 2, 0); /* orig + outline */ pixDestroy(&pix1); pix1 = pixCreateTemplate(pixs); pix2 = pixSetBlackOrWhiteBoxa(pix1, boxa, L_SET_BLACK); pixCopy(pix1, pixs); pix3 = pixDilateBrick(NULL, pixs, 3, 3); pixCombineMasked(pix1, pix3, pix2); pixSaveTiledOutline(pix1, pad, 0.5, 1, 20, 2, 0); /* ital bolded */ pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pix2 = pixaDisplay(pad, 0, 0); pixWrite("/tmp/lept/ital/ital.png", pix2, IFF_PNG); pixDestroy(&pix2); /* Assuming the image represents 6 inches of actual page width, * the pixs resolution is approximately * (width of pixs in pixels) / 6 * and the images have been saved at half this resolution. */ res = pixGetWidth(pixs) / 12; L_INFO("resolution = %d\n", procName, res); l_pdfSetDateAndVersion(0); pixaConvertToPdf(pad, res, 1.0, L_FLATE_ENCODE, 75, "Italic Finder", "/tmp/lept/ital/ital.pdf"); l_pdfSetDateAndVersion(1); pixaDestroy(&pad); boxaDestroy(&boxat); /* Plot histogram of horizontal white run sizes. A small * initial vertical dilation removes most runs that are neither * inter-character nor inter-word. The larger first peak is * from inter-character runs, and the smaller second peak is * from inter-word runs. */ pix1 = pixDilateBrick(NULL, pixs, 1, 15); upper = L_MAX(30, 3 * size); na = pixRunHistogramMorph(pix1, L_RUN_OFF, L_HORIZ, upper); pixDestroy(&pix1); gplot = gplotCreate("/tmp/lept/ital/runhisto", GPLOT_PNG, "Histogram of horizontal runs of white pixels, vs length", "run length", "number of runs"); gplotAddPlot(gplot, NULL, na, GPLOT_LINES, "plot1"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&na); } selDestroy(&sel_ital1); selDestroy(&sel_ital2); selDestroy(&sel_ital3); pixDestroy(&pixsd); pixDestroy(&pixm); pixDestroy(&pixd); 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; }
main(int argc, char **argv) { l_int32 i, ok, same; char sequence[512]; PIX *pixs, *pixref; PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6; PIX *pixt7, *pixt8, *pixt9, *pixt10, *pixt11; PIX *pixt12, *pixt13, *pixt14; SEL *sel; static char mainName[] = "binmorph1_reg"; if (argc != 1) exit(ERROR_INT(" Syntax: binmorph1_reg", mainName, 1)); if ((pixs = pixRead("feyn.tif")) == NULL) exit(ERROR_INT("pix not made", mainName, 1)); #if TEST_SYMMETRIC /* This works properly if there is an added border */ resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC); #if 1 pixt1 = pixAddBorder(pixs, 32, 0); pixTransferAllData(pixs, &pixt1, 0, 0); #endif #endif /* TEST_SYMMETRIC */ /* This is our test sel */ sel = selCreateBrick(HEIGHT, WIDTH, HEIGHT / 2, WIDTH / 2, SEL_HIT); /* Dilation */ fprintf(stderr, "Testing dilation\n"); ok = TRUE; pixref = pixDilate(NULL, pixs, sel); /* new one */ pixt1 = pixCreateTemplate(pixs); pixDilate(pixt1, pixs, sel); /* existing one */ pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixt2 = pixCopy(NULL, pixs); pixDilate(pixt2, pixt2, sel); /* in-place */ pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } sprintf(sequence, "d%d.%d", WIDTH, HEIGHT); pixt3 = pixMorphSequence(pixs, sequence, 0); /* sequence, atomic */ pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } sprintf(sequence, "d%d.1 + d1.%d", WIDTH, HEIGHT); pixt4 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable */ pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixt5 = pixDilateBrick(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt5, &same); if (!same) { fprintf(stderr, "pixref != pixt5 !\n"); ok = FALSE; } pixt6 = pixCreateTemplate(pixs); pixDilateBrick(pixt6, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt6, &same); if (!same) { fprintf(stderr, "pixref != pixt6 !\n"); ok = FALSE; } pixt7 = pixCopy(NULL, pixs); pixDilateBrick(pixt7, pixt7, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt7, &same); if (!same) { fprintf(stderr, "pixref != pixt7 !\n"); ok = FALSE; } pixt8 = pixDilateBrickDwa(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt8, &same); if (!same) { fprintf(stderr, "pixref != pixt8 !\n"); ok = FALSE; } pixt9 = pixCreateTemplate(pixs); pixDilateBrickDwa(pixt9, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt9, &same); if (!same) { fprintf(stderr, "pixref != pixt9 !\n"); ok = FALSE; } pixt10 = pixCopy(NULL, pixs); pixDilateBrickDwa(pixt10, pixt10, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt10, &same); if (!same) { fprintf(stderr, "pixref != pixt10 !\n"); ok = FALSE; } pixt11 = pixCreateTemplate(pixs); pixDilateCompBrickDwa(pixt11, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt11, &same); if (!same) { fprintf(stderr, "pixref != pixt11 !\n"); ok = FALSE; } sprintf(sequence, "d%d.%d", WIDTH, HEIGHT); pixt12 = pixMorphCompSequence(pixs, sequence, 0); /* comp sequence */ pixEqual(pixref, pixt12, &same); if (!same) { fprintf(stderr, "pixref != pixt12!\n"); ok = FALSE; } pixt13 = pixMorphSequenceDwa(pixs, sequence, 0); /* dwa sequence */ pixEqual(pixref, pixt13, &same); if (!same) { fprintf(stderr, "pixref != pixt13!\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); pixDestroy(&pixt7); pixDestroy(&pixt8); pixDestroy(&pixt9); pixDestroy(&pixt10); pixDestroy(&pixt11); pixDestroy(&pixt12); pixDestroy(&pixt13); /* Erosion */ fprintf(stderr, "Testing erosion\n"); pixref = pixErode(NULL, pixs, sel); /* new one */ pixt1 = pixCreateTemplate(pixs); pixErode(pixt1, pixs, sel); /* existing one */ pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixt2 = pixCopy(NULL, pixs); pixErode(pixt2, pixt2, sel); /* in-place */ pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } sprintf(sequence, "e%d.%d", WIDTH, HEIGHT); pixt3 = pixMorphSequence(pixs, sequence, 0); /* sequence, atomic */ pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } sprintf(sequence, "e%d.1 + e1.%d", WIDTH, HEIGHT); pixt4 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable */ pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixt5 = pixErodeBrick(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt5, &same); if (!same) { fprintf(stderr, "pixref != pixt5 !\n"); ok = FALSE; } pixt6 = pixCreateTemplate(pixs); pixErodeBrick(pixt6, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt6, &same); if (!same) { fprintf(stderr, "pixref != pixt6 !\n"); ok = FALSE; } pixt7 = pixCopy(NULL, pixs); pixErodeBrick(pixt7, pixt7, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt7, &same); if (!same) { fprintf(stderr, "pixref != pixt7 !\n"); ok = FALSE; } pixt8 = pixErodeBrickDwa(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt8, &same); if (!same) { fprintf(stderr, "pixref != pixt8 !\n"); ok = FALSE; } pixt9 = pixCreateTemplate(pixs); pixErodeBrickDwa(pixt9, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt9, &same); if (!same) { fprintf(stderr, "pixref != pixt9 !\n"); ok = FALSE; } pixt10 = pixCopy(NULL, pixs); pixErodeBrickDwa(pixt10, pixt10, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt10, &same); if (!same) { fprintf(stderr, "pixref != pixt10 !\n"); ok = FALSE; } pixt11 = pixCreateTemplate(pixs); pixErodeCompBrickDwa(pixt11, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt11, &same); if (!same) { fprintf(stderr, "pixref != pixt11 !\n"); ok = FALSE; } sprintf(sequence, "e%d.%d", WIDTH, HEIGHT); pixt12 = pixMorphCompSequence(pixs, sequence, 0); /* comp sequence */ pixEqual(pixref, pixt12, &same); if (!same) { fprintf(stderr, "pixref != pixt12!\n"); ok = FALSE; } pixt13 = pixMorphSequenceDwa(pixs, sequence, 0); /* dwa sequence */ pixEqual(pixref, pixt13, &same); if (!same) { fprintf(stderr, "pixref != pixt13!\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); pixDestroy(&pixt7); pixDestroy(&pixt8); pixDestroy(&pixt9); pixDestroy(&pixt10); pixDestroy(&pixt11); pixDestroy(&pixt12); pixDestroy(&pixt13); /* Opening */ fprintf(stderr, "Testing opening\n"); pixref = pixOpen(NULL, pixs, sel); /* new one */ pixt1 = pixCreateTemplate(pixs); pixOpen(pixt1, pixs, sel); /* existing one */ pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixt2 = pixCopy(NULL, pixs); pixOpen(pixt2, pixt2, sel); /* in-place */ pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } sprintf(sequence, "o%d.%d", WIDTH, HEIGHT); pixt3 = pixMorphSequence(pixs, sequence, 0); /* sequence, atomic */ pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } sprintf(sequence, "e%d.%d + d%d.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt4 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable */ pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } sprintf(sequence, "e%d.1 + e1.%d + d%d.1 + d1.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt5 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable^2 */ pixEqual(pixref, pixt5, &same); if (!same) { fprintf(stderr, "pixref != pixt5 !\n"); ok = FALSE; } pixt6 = pixOpenBrick(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt6, &same); if (!same) { fprintf(stderr, "pixref != pixt6 !\n"); ok = FALSE; } pixt7 = pixCreateTemplate(pixs); pixOpenBrick(pixt7, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt7, &same); if (!same) { fprintf(stderr, "pixref != pixt7 !\n"); ok = FALSE; } pixt8 = pixCopy(NULL, pixs); /* in-place */ pixOpenBrick(pixt8, pixt8, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt8, &same); if (!same) { fprintf(stderr, "pixref != pixt8 !\n"); ok = FALSE; } pixt9 = pixOpenBrickDwa(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt9, &same); if (!same) { fprintf(stderr, "pixref != pixt9 !\n"); ok = FALSE; } pixt10 = pixCreateTemplate(pixs); pixOpenBrickDwa(pixt10, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt10, &same); if (!same) { fprintf(stderr, "pixref != pixt10 !\n"); ok = FALSE; } pixt11 = pixCopy(NULL, pixs); pixOpenBrickDwa(pixt11, pixt11, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt11, &same); if (!same) { fprintf(stderr, "pixref != pixt11 !\n"); ok = FALSE; } sprintf(sequence, "o%d.%d", WIDTH, HEIGHT); pixt12 = pixMorphCompSequence(pixs, sequence, 0); /* comp sequence */ pixEqual(pixref, pixt12, &same); if (!same) { fprintf(stderr, "pixref != pixt12!\n"); ok = FALSE; } #if 0 pixWrite("/tmp/junkref.png", pixref, IFF_PNG); pixWrite("/tmp/junk12.png", pixt12, IFF_PNG); pixt13 = pixXor(NULL, pixref, pixt12); pixWrite("/tmp/junk12a.png", pixt13, IFF_PNG); pixDestroy(&pixt13); #endif pixt13 = pixMorphSequenceDwa(pixs, sequence, 0); /* dwa sequence */ pixEqual(pixref, pixt13, &same); if (!same) { fprintf(stderr, "pixref != pixt13!\n"); ok = FALSE; } pixt14 = pixCreateTemplate(pixs); pixOpenCompBrickDwa(pixt14, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt14, &same); if (!same) { fprintf(stderr, "pixref != pixt14 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); pixDestroy(&pixt7); pixDestroy(&pixt8); pixDestroy(&pixt9); pixDestroy(&pixt10); pixDestroy(&pixt11); pixDestroy(&pixt12); pixDestroy(&pixt13); pixDestroy(&pixt14); /* Closing */ fprintf(stderr, "Testing closing\n"); pixref = pixClose(NULL, pixs, sel); /* new one */ pixt1 = pixCreateTemplate(pixs); pixClose(pixt1, pixs, sel); /* existing one */ pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixt2 = pixCopy(NULL, pixs); pixClose(pixt2, pixt2, sel); /* in-place */ pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } sprintf(sequence, "d%d.%d + e%d.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt3 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable */ pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } sprintf(sequence, "d%d.1 + d1.%d + e%d.1 + e1.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt4 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable^2 */ pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } pixt5 = pixCloseBrick(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt5, &same); if (!same) { fprintf(stderr, "pixref != pixt5 !\n"); ok = FALSE; } pixt6 = pixCreateTemplate(pixs); pixCloseBrick(pixt6, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt6, &same); if (!same) { fprintf(stderr, "pixref != pixt6 !\n"); ok = FALSE; } pixt7 = pixCopy(NULL, pixs); /* in-place */ pixCloseBrick(pixt7, pixt7, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt7, &same); if (!same) { fprintf(stderr, "pixref != pixt7 !\n"); ok = FALSE; } pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); pixDestroy(&pixt7); /* Safe closing (using pix, not pixs) */ fprintf(stderr, "Testing safe closing\n"); pixref = pixCloseSafe(NULL, pixs, sel); /* new one */ pixt1 = pixCreateTemplate(pixs); pixCloseSafe(pixt1, pixs, sel); /* existing one */ pixEqual(pixref, pixt1, &same); if (!same) { fprintf(stderr, "pixref != pixt1 !\n"); ok = FALSE; } pixt2 = pixCopy(NULL, pixs); pixCloseSafe(pixt2, pixt2, sel); /* in-place */ pixEqual(pixref, pixt2, &same); if (!same) { fprintf(stderr, "pixref != pixt2 !\n"); ok = FALSE; } sprintf(sequence, "c%d.%d", WIDTH, HEIGHT); pixt3 = pixMorphSequence(pixs, sequence, 0); /* sequence, atomic */ pixEqual(pixref, pixt3, &same); if (!same) { fprintf(stderr, "pixref != pixt3 !\n"); ok = FALSE; } sprintf(sequence, "b32 + d%d.%d + e%d.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt4 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable */ pixEqual(pixref, pixt4, &same); if (!same) { fprintf(stderr, "pixref != pixt4 !\n"); ok = FALSE; } sprintf(sequence, "b32 + d%d.1 + d1.%d + e%d.1 + e1.%d", WIDTH, HEIGHT, WIDTH, HEIGHT); pixt5 = pixMorphSequence(pixs, sequence, 0); /* sequence, separable^2 */ pixEqual(pixref, pixt5, &same); if (!same) { fprintf(stderr, "pixref != pixt5 !\n"); ok = FALSE; } pixt6 = pixCloseSafeBrick(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt6, &same); if (!same) { fprintf(stderr, "pixref != pixt6 !\n"); ok = FALSE; } pixt7 = pixCreateTemplate(pixs); pixCloseSafeBrick(pixt7, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt7, &same); if (!same) { fprintf(stderr, "pixref != pixt7 !\n"); ok = FALSE; } pixt8 = pixCopy(NULL, pixs); /* in-place */ pixCloseSafeBrick(pixt8, pixt8, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt8, &same); if (!same) { fprintf(stderr, "pixref != pixt8 !\n"); ok = FALSE; } pixt9 = pixCloseBrickDwa(NULL, pixs, WIDTH, HEIGHT); /* new one */ pixEqual(pixref, pixt9, &same); if (!same) { fprintf(stderr, "pixref != pixt9 !\n"); ok = FALSE; } pixt10 = pixCreateTemplate(pixs); pixCloseBrickDwa(pixt10, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt10, &same); if (!same) { fprintf(stderr, "pixref != pixt10 !\n"); ok = FALSE; } pixt11 = pixCopy(NULL, pixs); pixCloseBrickDwa(pixt11, pixt11, WIDTH, HEIGHT); /* in-place */ pixEqual(pixref, pixt11, &same); if (!same) { fprintf(stderr, "pixref != pixt11 !\n"); ok = FALSE; } sprintf(sequence, "c%d.%d", WIDTH, HEIGHT); pixt12 = pixMorphCompSequence(pixs, sequence, 0); /* comp sequence */ pixEqual(pixref, pixt12, &same); if (!same) { fprintf(stderr, "pixref != pixt12!\n"); ok = FALSE; } pixt13 = pixMorphSequenceDwa(pixs, sequence, 0); /* dwa sequence */ pixEqual(pixref, pixt13, &same); if (!same) { fprintf(stderr, "pixref != pixt13!\n"); ok = FALSE; } pixt14 = pixCreateTemplate(pixs); pixCloseCompBrickDwa(pixt14, pixs, WIDTH, HEIGHT); /* existing one */ pixEqual(pixref, pixt14, &same); if (!same) { fprintf(stderr, "pixref != pixt14 !\n"); ok = FALSE; } #if 0 pixWrite("/tmp/junkref.png", pixref, IFF_PNG); pixWrite("/tmp/junk12.png", pixt12, IFF_PNG); pixt13 = pixXor(NULL, pixref, pixt12); pixWrite("/tmp/junk12a.png", pixt13, IFF_PNG); pixDestroy(&pixt13); #endif pixDestroy(&pixref); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); pixDestroy(&pixt7); pixDestroy(&pixt8); pixDestroy(&pixt9); pixDestroy(&pixt10); pixDestroy(&pixt11); pixDestroy(&pixt12); pixDestroy(&pixt13); pixDestroy(&pixt14); if (ok) fprintf(stderr, "All morph tests OK!\n"); pixDestroy(&pixs); selDestroy(&sel); exit(0); }