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); }
int main(int argc, char **argv) { l_uint8 *data1, *data2; l_int32 i, n; size_t size1, size2; BOX *box; PIX *pix, *pix1, *pix2, *pix3; PIXA *pixa, *pixa1; PIXC *pixc, *pixc1, *pixc2; PIXAC *pixac, *pixac1, *pixac2; L_REGPARAMS *rp; SARRAY *sa; if (regTestSetup(argc, argv, &rp)) return 1; lept_mkdir("lept/comp"); pixac = pixacompCreate(1); pixa = pixaCreate(0); /* --- Read in the images --- */ pix1 = pixRead("marge.jpg"); pixc1 = pixcompCreateFromPix(pix1, IFF_JFIF_JPEG); pix2 = pixCreateFromPixcomp(pixc1); pixc2 = pixcompCreateFromPix(pix2, IFF_JFIF_JPEG); pix3 = pixCreateFromPixcomp(pixc2); regTestWritePixAndCheck(rp, pix3, IFF_JFIF_JPEG); /* 0 */ pixSaveTiledOutline(pix3, pixa, 1.0, 1, 30, 2, 32); pixacompAddPix(pixac, pix1, IFF_DEFAULT); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixcompDestroy(&pixc1); pixcompDestroy(&pixc2); pix = pixRead("feyn.tif"); pix1 = pixScaleToGray6(pix); pixc1 = pixcompCreateFromPix(pix1, IFF_JFIF_JPEG); pix2 = pixCreateFromPixcomp(pixc1); pixc2 = pixcompCreateFromPix(pix2, IFF_JFIF_JPEG); pix3 = pixCreateFromPixcomp(pixc2); regTestWritePixAndCheck(rp, pix3, IFF_JFIF_JPEG); /* 1 */ pixSaveTiledOutline(pix3, pixa, 1.0, 1, 30, 2, 32); pixacompAddPix(pixac, pix1, IFF_DEFAULT); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixcompDestroy(&pixc1); pixcompDestroy(&pixc2); box = boxCreate(1144, 611, 690, 180); pix1 = pixClipRectangle(pix, box, NULL); pixc1 = pixcompCreateFromPix(pix1, IFF_TIFF_G4); pix2 = pixCreateFromPixcomp(pixc1); pixc2 = pixcompCreateFromPix(pix2, IFF_TIFF_G4); pix3 = pixCreateFromPixcomp(pixc2); regTestWritePixAndCheck(rp, pix3, IFF_TIFF_G4); /* 2 */ pixSaveTiledOutline(pix3, pixa, 1.0, 0, 30, 2, 32); pixacompAddPix(pixac, pix1, IFF_DEFAULT); boxDestroy(&box); pixDestroy(&pix); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixcompDestroy(&pixc1); pixcompDestroy(&pixc2); pix1 = pixRead("weasel4.11c.png"); pixc1 = pixcompCreateFromPix(pix1, IFF_PNG); pix2 = pixCreateFromPixcomp(pixc1); pixc2 = pixcompCreateFromPix(pix2, IFF_PNG); pix3 = pixCreateFromPixcomp(pixc2); regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3 */ pixSaveTiledOutline(pix3, pixa, 1.0, 0, 30, 2, 32); pixacompAddPix(pixac, pix1, IFF_DEFAULT); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixcompDestroy(&pixc1); pixcompDestroy(&pixc2); /* --- Extract formatting info from compressed strings --- */ for (i = 0; i < 4; i++) { pixc = pixacompGetPixcomp(pixac, i, L_NOCOPY); get_format_data(i, pixc->data, pixc->size); } /* Save a tiled composite from the pixa */ pix1 = pixaDisplayTiledAndScaled(pixa, 32, 400, 4, 0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 4 */ pixDestroy(&pix1); /* Convert the pixac --> pixa and save a tiled composite */ pixa1 = pixaCreateFromPixacomp(pixac, L_COPY); pix1 = pixaDisplayTiledAndScaled(pixa1, 32, 400, 4, 0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 5 */ pixaDestroy(&pixa1); pixDestroy(&pix1); /* Make a pixacomp from files, and join */ sa = sarrayCreate(0); for (i = 0; i < 6; i++) sarrayAddString(sa, (char *)fnames[i], L_COPY); pixac1 = pixacompCreateFromSA(sa, IFF_DEFAULT); pixacompJoin(pixac1, pixac, 0, -1); pixa1 = pixaCreateFromPixacomp(pixac1, L_COPY); pix1 = pixaDisplayTiledAndScaled(pixa1, 32, 250, 10, 0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 6 */ pixacompDestroy(&pixac1); pixaDestroy(&pixa1); pixDestroy(&pix1); sarrayDestroy(&sa); /* Test serialized I/O */ pixacompWrite("/tmp/lept/comp/file1.pac", pixac); regTestCheckFile(rp, "/tmp/lept/comp/file1.pac"); /* 7 */ pixac1 = pixacompRead("/tmp/lept/comp/file1.pac"); pixacompWrite("/tmp/lept/comp/file2.pac", pixac1); regTestCheckFile(rp, "/tmp/lept/comp/file2.pac"); /* 8 */ regTestCompareFiles(rp, 7, 8); /* 9 */ pixac2 = pixacompRead("/tmp/lept/comp/file2.pac"); pixa1 = pixaCreateFromPixacomp(pixac2, L_COPY); pix1 = pixaDisplayTiledAndScaled(pixa1, 32, 250, 4, 0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 10 */ pixacompDestroy(&pixac1); pixacompDestroy(&pixac2); pixaDestroy(&pixa1); pixDestroy(&pix1); /* Test serialized pixacomp I/O to and from memory */ pixacompWriteMem(&data1, &size1, pixac); pixac1 = pixacompReadMem(data1, size1); pixacompWriteMem(&data2, &size2, pixac1); pixac2 = pixacompReadMem(data2, size2); pixacompWrite("/tmp/lept/comp/file3.pac", pixac1); regTestCheckFile(rp, "/tmp/lept/comp/file3.pac"); /* 11 */ pixacompWrite("/tmp/lept/comp/file4.pac", pixac2); regTestCheckFile(rp, "/tmp/lept/comp/file4.pac"); /* 12 */ regTestCompareFiles(rp, 11, 12); /* 13 */ pixacompDestroy(&pixac1); pixacompDestroy(&pixac2); lept_free(data1); lept_free(data2); pixaDestroy(&pixa); pixacompDestroy(&pixac); return regTestCleanup(rp); }
main(int argc, char **argv) { l_int32 i, nbins, ival; l_float64 pi, angle, val, sum; L_DNA *da1, *da2, *da3, *da4, *da5; L_DNAA *daa1, *daa2; GPLOT *gplot; NUMA *na, *nahisto, *nax; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pi = 3.1415926535; da1 = l_dnaCreate(50); for (i = 0; i < 5000; i++) { angle = 0.02293 * i * pi; val = 999. * sin(angle); l_dnaAddNumber(da1, val); } /* Conversion to Numa; I/O for Dna */ na = l_dnaConvertToNuma(da1); da2 = numaConvertToDna(na); l_dnaWrite("/tmp/dna1.da", da1); l_dnaWrite("/tmp/dna2.da", da2); da3 = l_dnaRead("/tmp/dna2.da"); l_dnaWrite("/tmp/dna3.da", da3); regTestCheckFile(rp, "/tmp/dna1.da"); /* 0 */ regTestCheckFile(rp, "/tmp/dna2.da"); /* 1 */ regTestCheckFile(rp, "/tmp/dna3.da"); /* 2 */ regTestCompareFiles(rp, 1, 2); /* 3 */ /* I/O for Dnaa */ daa1 = l_dnaaCreate(3); l_dnaaAddDna(daa1, da1, L_INSERT); l_dnaaAddDna(daa1, da2, L_INSERT); l_dnaaAddDna(daa1, da3, L_INSERT); l_dnaaWrite("/tmp/dnaa1.daa", daa1); daa2 = l_dnaaRead("/tmp/dnaa1.daa"); l_dnaaWrite("/tmp/dnaa2.daa", daa2); regTestCheckFile(rp, "/tmp/dnaa1.daa"); /* 4 */ regTestCheckFile(rp, "/tmp/dnaa2.daa"); /* 5 */ regTestCompareFiles(rp, 4, 5); /* 6 */ l_dnaaDestroy(&daa1); l_dnaaDestroy(&daa2); /* Just for fun -- is the numa ok? */ nahisto = numaMakeHistogramClipped(na, 12, 2000); nbins = numaGetCount(nahisto); nax = numaMakeSequence(0, 1, nbins); gplot = gplotCreate("/tmp/historoot", GPLOT_PNG, "Histo example", "i", "histo[i]"); gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine"); gplotMakeOutput(gplot); #ifndef _WIN32 sleep(1); #else Sleep(1000); #endif /* _WIN32 */ regTestCheckFile(rp, "/tmp/historoot.png"); /* 7 */ gplotDestroy(&gplot); numaDestroy(&na); numaDestroy(&nax); numaDestroy(&nahisto); /* Handling precision of int32 in double */ da4 = l_dnaCreate(25); for (i = 0; i < 1000; i++) l_dnaAddNumber(da4, 1928374 * i); l_dnaWrite("/tmp/dna4.da", da4); da5 = l_dnaRead("/tmp/dna4.da"); sum = 0; for (i = 0; i < 1000; i++) { l_dnaGetIValue(da5, i, &ival); sum += L_ABS(ival - i * 1928374); /* we better be adding 0 each time */ } regTestCompareValues(rp, sum, 0.0, 0.0); /* 8 */ l_dnaDestroy(&da4); l_dnaDestroy(&da5); return regTestCleanup(rp); }
main(int argc, char **argv) { char *str; l_int32 i, j, same, ok; l_float32 sum, avediff, rmsdiff; L_KERNEL *kel1, *kel2, *kel3, *kel4, *kelx, *kely; BOX *box; PIX *pix, *pixs, *pixb, *pixg, *pixr, *pixd, *pixp, *pixt; PIX *pixt1, *pixt2, *pixt3; PIXA *pixa; SARRAY *sa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixa = pixaCreate(0); /* Test creating from a string */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = kernelDisplayInPix(kel1, 41, 2); pixWrite("/tmp/pixkern.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/pixkern.png"); /* 0 */ pixSaveTiled(pixd, pixa, 1, 1, 20, 8); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test read/write for kernel. Note that both get * compared to the same golden file, which is * overwritten with a copy of /tmp/kern2.kel */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); kernelWrite("/tmp/kern1.kel", kel1); regTestCheckFile(rp, "/tmp/kern1.kel"); /* 1 */ kel2 = kernelRead("/tmp/kern1.kel"); kernelWrite("/tmp/kern2.kel", kel2); regTestCheckFile(rp, "/tmp/kern2.kel"); /* 2 */ regTestCompareFiles(rp, 1, 2); /* 3 */ kernelDestroy(&kel1); kernelDestroy(&kel2); /* Test creating from a file */ sa = sarrayCreate(0); sarrayAddString(sa, (char *)"# small 3x3 kernel", L_COPY); sarrayAddString(sa, (char *)"3 5", L_COPY); sarrayAddString(sa, (char *)"1 2", L_COPY); sarrayAddString(sa, (char *)"20.5 50 80 50 20", L_COPY); sarrayAddString(sa, (char *)"82. 120 180 120 80", L_COPY); sarrayAddString(sa, (char *)"22.1 50 80 50 20", L_COPY); str = sarrayToString(sa, 1); l_binaryWrite("/tmp/kernfile.kel", "w", str, strlen(str)); kel2 = kernelCreateFromFile("/tmp/kernfile.kel"); pixd = kernelDisplayInPix(kel2, 41, 2); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker1.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker1.png"); /* 4 */ pixDestroy(&pixd); sarrayDestroy(&sa); lept_free(str); kernelDestroy(&kel2); /* Test creating from a pix */ pixt = pixCreate(5, 3, 8); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 0, 50); pixSetPixel(pixt, 2, 0, 80); pixSetPixel(pixt, 3, 0, 50); pixSetPixel(pixt, 4, 0, 20); pixSetPixel(pixt, 0, 1, 80); pixSetPixel(pixt, 1, 1, 120); pixSetPixel(pixt, 2, 1, 180); pixSetPixel(pixt, 3, 1, 120); pixSetPixel(pixt, 4, 1, 80); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 2, 50); pixSetPixel(pixt, 2, 2, 80); pixSetPixel(pixt, 3, 2, 50); pixSetPixel(pixt, 4, 2, 20); kel3 = kernelCreateFromPix(pixt, 1, 2); pixd = kernelDisplayInPix(kel3, 41, 2); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker2.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker2.png"); /* 5 */ pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel3); /* Test convolution with kel1 */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); pixSaveTiled(pixg, pixa, 1, 1, 20, 0); kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = pixConvolve(pixg, kel1, 8, 1); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker3.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker3.png"); /* 6 */ pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test convolution with flat rectangular kel; also test * block convolution with tiling. */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); kel2 = makeFlatKernel(11, 11, 5, 5); pixd = pixConvolve(pixg, kel2, 8, 1); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker4.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker4.png"); /* 7 */ pixt = pixBlockconv(pixg, 5, 5); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5.png"); /* 8 */ if (rp->display) pixCompareGray(pixd, pixt, L_COMPARE_ABS_DIFF, GPLOT_X11, NULL, NULL, NULL, NULL); pixt2 = pixBlockconvTiled(pixg, 5, 5, 3, 6); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5a.png", pixt2, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5a.png"); /* 9 */ pixDestroy(&pixt2); ok = TRUE; for (i = 1; i <= 7; i++) { for (j = 1; j <= 7; j++) { if (i == 1 && j == 1) continue; pixt2 = pixBlockconvTiled(pixg, 5, 5, j, i); pixEqual(pixt2, pixd, &same); if (!same) { fprintf(stderr," Error for nx = %d, ny = %d\n", j, i); ok = FALSE; } pixDestroy(&pixt2); } } if (ok) fprintf(stderr, "OK: Tiled results identical to pixConvolve()\n"); else fprintf(stderr, "ERROR: Tiled results not identical to pixConvolve()\n"); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel2); /* Do another flat rectangular test; this time with white at edge. * About 1% of the pixels near the image edge differ by 1 between * the pixConvolve() and pixBlockconv(). For what it's worth, * pixConvolve() gives the more accurate result; namely, 255 for * pixels at the edge. */ pix = pixRead("pageseg1.tif"); box = boxCreate(100, 100, 2260, 3160); pixb = pixClipRectangle(pix, box, NULL); pixs = pixScaleToGray4(pixb); kel3 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt = pixConvolve(pixs, kel3, 8, 1); fprintf(stderr, "Generic convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt, pixa, 1, 1, 20, 0); pixWrite("/tmp/conv1.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/conv1.png"); /* 10 */ startTimer(); pixt2 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Flat block convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv2.png", pixt2, IFF_PNG); /* ditto */ regTestCheckFile(rp, "/tmp/conv2.png"); /* 11 */ pixCompareGray(pixt, pixt2, L_COMPARE_ABS_DIFF, GPLOT_PNG, NULL, &avediff, &rmsdiff, NULL); #ifndef _WIN32 sleep(1); /* give gnuplot time to write out the file */ #else Sleep(1000); #endif /* _WIN32 */ pixp = pixRead("/tmp/grayroot.png"); pixSaveTiled(pixp, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv3.png", pixp, IFF_PNG); regTestCheckFile(rp, "/tmp/conv3.png"); /* 12 */ fprintf(stderr, "Ave diff = %6.4f, RMS diff = %6.4f\n", avediff, rmsdiff); if (avediff <= 0.01) fprintf(stderr, "OK: avediff = %6.4f <= 0.01\n", avediff); else fprintf(stderr, "Bad?: avediff = %6.4f > 0.01\n", avediff); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixs); pixDestroy(&pixp); pixDestroy(&pix); pixDestroy(&pixb); boxDestroy(&box); kernelDestroy(&kel3); /* Do yet another set of flat rectangular tests, this time * on an RGB image */ pixs = pixRead("test24.jpg"); kel4 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt1 = pixConvolveRGB(pixs, kel4); fprintf(stderr, "Time 7x7 non-separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv4.jpg", pixt1, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv4.jpg"); /* 13 */ kelx = makeFlatKernel(1, 7, 0, 3); kely = makeFlatKernel(7, 1, 3, 0); startTimer(); pixt2 = pixConvolveRGBSep(pixs, kelx, kely); fprintf(stderr, "Time 7x1,1x7 separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv5.jpg", pixt2, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv5.jpg"); /* 14 */ startTimer(); pixt3 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Time 7x7 blockconv: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv6.jpg", pixt3, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv6.jpg"); /* 15 */ regTestComparePix(rp, pixt1, pixt2); /* 16 */ regTestCompareSimilarPix(rp, pixt2, pixt3, 15, 0.0005, 0); /* 17 */ pixDestroy(&pixs); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); kernelDestroy(&kel4); kernelDestroy(&kelx); kernelDestroy(&kely); /* Test generation and convolution with gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeGaussianKernel(5, 5, 3.0, 5.0); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 1); pixt2 = pixConvolve(pixs, kel1, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker6.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker6.png"); /* 18 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kel1, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); /* Test generation and convolution with separable gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); makeGaussianKernelSep(5, 5, 3.0, 5.0, &kelx, &kely); kernelGetSum(kelx, &sum); fprintf(stderr, "Sum for x gaussian kernel = %f\n", sum); kernelGetSum(kely, &sum); fprintf(stderr, "Sum for y gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kelx", kelx); kernelWrite("/tmp/gauss.kely", kely); pixt = pixConvolveSep(pixs, kelx, kely, 8, 1); pixt2 = pixConvolveSep(pixs, kelx, kely, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker7.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker7.png"); /* 19 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kelx, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixt = kernelDisplayInPix(kely, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kelx); kernelDestroy(&kely); pixDestroy(&pixs); /* Test generation and convolution with diff of gaussians kernel */ /* pixt = pixRead("marge.jpg"); pixs = pixConvertRGBToLuminance(pixt); pixDestroy(&pixt); */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeDoGKernel(7, 7, 1.5, 2.7); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for DoG kernel = %f\n", sum); kernelWrite("/tmp/dog.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 0); /* pixInvert(pixt, pixt); */ pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker8.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker8.png"); /* 20 */ pixDestroy(&pixt); pixt = kernelDisplayInPix(kel1, 20, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixWrite("/tmp/kernel.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); regTestCleanup(rp); return 0; }
/* * Test both vertical and horizontal projections on this image. * We rotate the image by 90 degrees for the horizontal projection, * so that the two results should be identical. */ void TestProjection(L_REGPARAMS *rp, PIX *pixs) { l_int32 outline; NUMA *na1, *na2, *na3, *na4, *na5, *na6; NUMA *na7, *na8, *na9, *na10, *na11, *na12; PIX *pixd, *pixt; PIXA *pixa; outline = 2; pixColumnStats(pixs, &na1, &na3, &na5, &na7, &na9, &na11); pixd = pixRotateOrth(pixs, 1); pixRowStats(pixd, &na2, &na4, &na6, &na8, &na10, &na12); /* The png plot files are written to "/tmp/proj.0.png", etc. * These temp files are overwritten each time this * function is called. */ gplotSimple1(na1, GPLOT_PNG, "/tmp/proj.0", "Mean value"); gplotSimple1(na2, GPLOT_PNG, "/tmp/proj.1", "Mean value"); gplotSimple1(na3, GPLOT_PNG, "/tmp/proj.2", "Median value"); gplotSimple1(na4, GPLOT_PNG, "/tmp/proj.3", "Median value"); gplotSimple1(na5, GPLOT_PNG, "/tmp/proj.4", "Mode value"); gplotSimple1(na6, GPLOT_PNG, "/tmp/proj.5", "Mode value"); gplotSimple1(na7, GPLOT_PNG, "/tmp/proj.6", "Mode count"); gplotSimple1(na8, GPLOT_PNG, "/tmp/proj.7", "Mode count"); gplotSimple1(na9, GPLOT_PNG, "/tmp/proj.8", "Variance"); gplotSimple1(na10, GPLOT_PNG, "/tmp/proj.9", "Variance"); gplotSimple1(na11, GPLOT_PNG, "/tmp/proj.10", "Square Root Variance"); gplotSimple1(na12, GPLOT_PNG, "/tmp/proj.11", "Square Root Variance"); #ifndef _WIN32 sleep(1); #else Sleep(1000); #endif /* _WIN32 */ /* Each of the 12 plot files is read into a pix and then: * (1) saved into a pixa for display * (2) saved as a golden file (generate stage) or compared * to the existing golden file (testing stage) */ pixa = pixaCreate(13); pixSaveTiledOutline(pixs, pixa, 1, 1, 30, outline, 32); pixt = pixRead("/tmp/proj.0.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 0 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.1.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 1 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.2.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 2 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.3.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 3 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.4.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 4 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.5.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 5 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.6.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 6 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.7.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 7 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.8.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 8 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.9.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 9 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.10.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 10 */ pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32); pixDestroy(&pixt); pixt = pixRead("/tmp/proj.11.png"); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 11 */ pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32); pixDestroy(&pixt); /* The pixa is composited into a pix and 'goldened'/tested */ pixt = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 12 */ pixDisplayWithTitle(pixt, 100, 0, NULL, rp->display); pixDestroy(&pixt); pixaDestroy(&pixa); /* The 12 plot files are tested in pairs for identity */ regTestCompareFiles(rp, 0, 1); regTestCompareFiles(rp, 2, 3); regTestCompareFiles(rp, 4, 5); regTestCompareFiles(rp, 6, 7); regTestCompareFiles(rp, 8, 9); regTestCompareFiles(rp, 10, 11); pixDestroy(&pixd); numaDestroy(&na1); numaDestroy(&na2); numaDestroy(&na3); numaDestroy(&na4); numaDestroy(&na5); numaDestroy(&na6); numaDestroy(&na7); numaDestroy(&na8); numaDestroy(&na9); numaDestroy(&na10); numaDestroy(&na11); numaDestroy(&na12); return; }
int main(int argc, char **argv) { l_int32 i, n; l_float32 pi, angle, val; BOX *box; BOXA *boxa, *boxa1, *boxa2; NUMA *na1, *na2; PIX *pix, *pix1, *pix2; PIXA *pixa1, *pixa2, *pixa3, *pixa4; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; lept_rmfile("/tmp/regout/insert3.ba"); lept_rmfile("/tmp/regout/insert4.ba"); lept_rmfile("/tmp/regout/insert6.pa"); lept_rmfile("/tmp/regout/insert7.pa"); lept_rmfile("/tmp/regout/insert9.pa"); lept_rmfile("/tmp/regout/insert10.pa"); /* ----------------- Test numa operations -------------------- */ pi = 3.1415926535; na1 = numaCreate(500); for (i = 0; i < 500; i++) { angle = 0.02293 * i * pi; val = (l_float32)sin(angle); numaAddNumber(na1, val); } numaWrite("/tmp/regout/insert0.na", na1); na2 = numaCopy(na1); n = numaGetCount(na2); for (i = 0; i < n; i++) { numaGetFValue(na2, i, &val); numaRemoveNumber(na2, i); numaInsertNumber(na2, i, val); } numaWrite("/tmp/regout/insert1.na", na2); regTestCheckFile(rp, "/tmp/regout/insert0.na"); /* 0 */ regTestCheckFile(rp, "/tmp/regout/insert1.na"); /* 1 */ regTestCompareFiles(rp, 0, 1); /* 2 */ numaDestroy(&na1); numaDestroy(&na2); /* ----------------- Test boxa operations -------------------- */ pix1 = pixRead("feyn.tif"); box = boxCreate(1138, 1666, 1070, 380); pix2 = pixClipRectangle(pix1, box, NULL); boxDestroy(&box); boxa1 = pixConnComp(pix2, NULL, 8); boxaWrite("/tmp/regout/insert3.ba", boxa1); boxa2 = boxaCopy(boxa1, L_COPY); n = boxaGetCount(boxa2); for (i = 0; i < n; i++) { boxaRemoveBoxAndSave(boxa2, i, &box); boxaInsertBox(boxa2, i, box); } boxaWrite("/tmp/regout/insert4.ba", boxa2); regTestCheckFile(rp, "/tmp/regout/insert3.ba"); /* 3 */ regTestCheckFile(rp, "/tmp/regout/insert4.ba"); /* 4 */ regTestCompareFiles(rp, 3, 4); /* 5 */ pixDestroy(&pix1); pixDestroy(&pix2); boxaDestroy(&boxa1); boxaDestroy(&boxa2); /* ----------------- Test pixa operations -------------------- */ pix1 = pixRead("feyn.tif"); box = boxCreate(1138, 1666, 1070, 380); pix2 = pixClipRectangle(pix1, box, NULL); boxDestroy(&box); boxa = pixConnComp(pix2, &pixa1, 8); boxaDestroy(&boxa); pixaWrite("/tmp/regout/insert6.pa", pixa1); regTestCheckFile(rp, "/tmp/regout/insert6.pa"); /* 6 */ pixDestroy(&pix1); pixDestroy(&pix2); /* Remove and insert each one */ pixa2 = pixaCopy(pixa1, L_COPY); n = pixaGetCount(pixa2); for (i = 0; i < n; i++) { pixaRemovePixAndSave(pixa2, i, &pix, &box); pixaInsertPix(pixa2, i, pix, box); } pixaWrite("/tmp/regout/insert7.pa", pixa2); regTestCheckFile(rp, "/tmp/regout/insert7.pa"); /* 7 */ regTestCompareFiles(rp, 6, 7); /* 8 */ /* Move the last to the beginning; do it n times */ pixa3 = pixaCopy(pixa2, L_COPY); for (i = 0; i < n; i++) { pix = pixaGetPix(pixa3, n - 1, L_CLONE); box = pixaGetBox(pixa3, n - 1, L_CLONE); pixaInsertPix(pixa3, 0, pix, box); pixaRemovePix(pixa3, n); } pixaWrite("/tmp/regout/insert9.pa", pixa3); regTestCheckFile(rp, "/tmp/regout/insert9.pa"); /* 9 */ /* Move the first one to the end; do it n times */ pixa4 = pixaCopy(pixa3, L_COPY); for (i = 0; i < n; i++) { pix = pixaGetPix(pixa4, 0, L_CLONE); box = pixaGetBox(pixa4, 0, L_CLONE); pixaInsertPix(pixa4, n, pix, box); /* make sure insert works at end */ pixaRemovePix(pixa4, 0); } pixaWrite("/tmp/regout/insert10.pa", pixa4); regTestCheckFile(rp, "/tmp/regout/insert10.pa"); /* 10 */ regTestCompareFiles(rp, 9, 10); /* 11 */ pixaDestroy(&pixa1); pixaDestroy(&pixa2); pixaDestroy(&pixa3); pixaDestroy(&pixa4); return regTestCleanup(rp); }
l_int32 main(int argc, char **argv) { l_int32 i, n; l_float32 a, b, c; L_DEWARP *dew, *dew2; DPIX *dpix1, *dpix2, *dpix3; FPIX *fpix1, *fpix2, *fpix3; NUMA *nax, *nafit; PIX *pixs, *pixn, *pixg, *pixb, *pixt1, *pixt2; PIX *pixs2, *pixn2, *pixg2, *pixb2; PTA *pta, *ptad; PTAA *ptaa1, *ptaa2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("1555-7.jpg"); /* Normalize for varying background and binarize */ pixn = pixBackgroundNormSimple(pixs, NULL, NULL); pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2); pixb = pixThresholdToBinary(pixg, 130); pixDestroy(&pixn); pixDestroy(&pixg); regTestWritePixAndCheck(rp, pixb, IFF_PNG); /* 0 */ pixDisplayWithTitle(pixb, 0, 0, "binarized input", rp->display); /* Get the textline centers */ ptaa1 = pixGetTextlineCenters(pixb, 0); pixt1 = pixCreateTemplate(pixs); pixt2 = pixDisplayPtaa(pixt1, ptaa1); regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 1 */ pixDisplayWithTitle(pixt2, 0, 500, "textline centers", rp->display); pixDestroy(&pixt1); /* Remove short lines */ ptaa2 = ptaaRemoveShortLines(pixb, ptaa1, 0.8, 0); /* Fit to quadratic */ n = ptaaGetCount(ptaa2); for (i = 0; i < n; i++) { pta = ptaaGetPta(ptaa2, i, L_CLONE); ptaGetArrays(pta, &nax, NULL); ptaGetQuadraticLSF(pta, &a, &b, &c, &nafit); ptad = ptaCreateFromNuma(nax, nafit); pixDisplayPta(pixt2, pixt2, ptad); ptaDestroy(&pta); ptaDestroy(&ptad); numaDestroy(&nax); numaDestroy(&nafit); } regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 2 */ pixDisplayWithTitle(pixt2, 300, 500, "fitted lines superimposed", rp->display); ptaaDestroy(&ptaa1); ptaaDestroy(&ptaa2); pixDestroy(&pixt2); /* Run with only vertical disparity correction */ if ((dew = dewarpCreate(pixb, 7, 30, 15, 0)) == NULL) return ERROR_INT("\n\n\n FAILURE !!! \n\n\n", rp->testname, 1); dewarpBuildModel(dew, 0); dewarpApplyDisparity(dew, pixb, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 3 */ pixDisplayWithTitle(dew->pixd, 400, 0, "fixed for vert disparity", rp->display); dewarpDestroy(&dew); /* Run with both vertical and horizontal disparity correction */ if ((dew = dewarpCreate(pixb, 7, 30, 15, 1)) == NULL) return ERROR_INT("\n\n\n FAILURE !!! \n\n\n", rp->testname, 1); dewarpBuildModel(dew, 0); dewarpApplyDisparity(dew, pixb, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 4 */ pixDisplayWithTitle(dew->pixd, 800, 0, "fixed for both disparities", rp->display); /* Read another image, normalize background and binarize */ pixs2 = pixRead("1555-3.jpg"); pixn2 = pixBackgroundNormSimple(pixs2, NULL, NULL); pixg2 = pixConvertRGBToGray(pixn2, 0.5, 0.3, 0.2); pixb2 = pixThresholdToBinary(pixg2, 130); pixDestroy(&pixn2); pixDestroy(&pixg2); regTestWritePixAndCheck(rp, pixb, IFF_PNG); /* 5 */ pixDisplayWithTitle(pixb, 0, 400, "binarized input (2)", rp->display); /* Minimize and re-apply previous disparity to this image */ dewarpMinimize(dew); dewarpApplyDisparity(dew, pixb2, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 6 */ pixDisplayWithTitle(dew->pixd, 400, 400, "fixed (2) for both disparities", rp->display); /* Write and read back minimized dewarp struct */ dewarpWrite("/tmp/dewarp.7.dew", dew); regTestCheckFile(rp, "/tmp/dewarp.7.dew"); /* 7 */ dew2 = dewarpRead("/tmp/dewarp.7.dew"); dewarpWrite("/tmp/dewarp.8.dew", dew2); regTestCheckFile(rp, "/tmp/dewarp.8.dew"); /* 8 */ regTestCompareFiles(rp, 7, 8); /* 9 */ /* Apply dew2 to pixb2 */ dewarpApplyDisparity(dew2, pixb2, 0); regTestWritePixAndCheck(rp, dew2->pixd, IFF_PNG); /* 10 */ pixDisplayWithTitle(dew->pixd, 800, 400, "fixed (3) for both disparities", rp->display); /* Minimize, repopulate disparity arrays, and apply again */ dewarpMinimize(dew2); dewarpApplyDisparity(dew2, pixb2, 0); regTestWritePixAndCheck(rp, dew2->pixd, IFF_PNG); /* 11 */ regTestCompareFiles(rp, 10, 11); /* 12 */ pixDisplayWithTitle(dew->pixd, 900, 400, "fixed (4) for both disparities", rp->display); /* Test a few of the fpix functions */ fpix1 = fpixClone(dew->sampvdispar); fpixWrite("/tmp/sampv.13.fpix", fpix1); regTestCheckFile(rp, "/tmp/sampv.13.fpix"); /* 13 */ fpix2 = fpixRead("/tmp/sampv.13.fpix"); fpixWrite("/tmp/sampv.14.fpix", fpix2); regTestCheckFile(rp, "/tmp/sampv.14.fpix"); /* 14 */ regTestCompareFiles(rp, 13, 14); /* 15 */ fpix3 = fpixScaleByInteger(fpix2, 30); pixt1 = fpixRenderContours(fpix3, -2., 2.0, 0.2); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 16 */ pixDisplayWithTitle(pixt1, 0, 800, "v. disparity contours", rp->display); fpixDestroy(&fpix1); fpixDestroy(&fpix2); fpixDestroy(&fpix3); pixDestroy(&pixt1); /* Test a few of the dpix functions */ dpix1 = fpixConvertToDPix(dew->sampvdispar); dpixWrite("/tmp/sampv.17.dpix", dpix1); regTestCheckFile(rp, "/tmp/sampv.17.dpix"); /* 17 */ dpix2 = dpixRead("/tmp/sampv.17.dpix"); dpixWrite("/tmp/sampv.18.dpix", dpix2); regTestCheckFile(rp, "/tmp/sampv.18.dpix"); /* 18 */ regTestCompareFiles(rp, 17, 18); /* 19 */ dpix3 = dpixScaleByInteger(dpix2, 30); fpix3 = dpixConvertToFPix(dpix3); pixt1 = fpixRenderContours(fpix3, -2., 2.0, 0.2); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 20 */ pixDisplayWithTitle(pixt1, 400, 800, "v. disparity contours", rp->display); regTestCompareFiles(rp, 16, 20); /* 21 */ dpixDestroy(&dpix1); dpixDestroy(&dpix2); dpixDestroy(&dpix3); fpixDestroy(&fpix3); pixDestroy(&pixt1); dewarpDestroy(&dew); dewarpDestroy(&dew2); pixDestroy(&pixs); pixDestroy(&pixb); pixDestroy(&pixs2); pixDestroy(&pixb2); regTestCleanup(rp); return 0; }