int main(int argc, char **argv) { l_int32 i, j; l_float32 f; PIX *pix1, *pix2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pix1 = pixCreate(500, 500, 8); pix2 = pixCreate(500, 500, 8); for (i = 0; i < 500; i++) { for (j = 0; j < 500; j++) { f = 128.0 + 26.3 * sin(0.0438 * (l_float32)i); f += 33.4 * cos(0.0712 * (l_float32)i); f += 18.6 * sin(0.0561 * (l_float32)j); f += 23.6 * cos(0.0327 * (l_float32)j); pixSetPixel(pix1, j, i, (l_int32)f); f = 128.0 + 26.3 * sin(0.0238 * (l_float32)i); f += 33.4 * cos(0.0312 * (l_float32)i); f += 18.6 * sin(0.0261 * (l_float32)j); f += 23.6 * cos(0.0207 * (l_float32)j); pixSetPixel(pix2, j, i, (l_int32)f); } } DoWatershed(rp, pix1); /* 0 - 11 */ DoWatershed(rp, pix2); /* 12 - 23 */ pixDestroy(&pix1); pixDestroy(&pix2); return regTestCleanup(rp); }
int main(int argc, char **argv) { L_REGPARAMS *rp; #if !HAVE_LIBJP2K fprintf(stderr, "jp2kio is not enabled\n" "libopenjp2 is required for jp2kio_reg\n" "See environ.h: #define HAVE_LIBJP2K\n" "See prog/Makefile: link in -lopenjp2\n\n"); return 0; #endif /* abort */ /* This test uses libjpeg */ #if !HAVE_LIBJPEG fprintf(stderr, "libjpeg is required for jp2kio_reg\n\n"); return 0; #endif /* abort */ if (regTestSetup(argc, argv, &rp)) return 1; lept_mkdir("lept"); DoJp2kTest1(rp, "karen8.jpg"); DoJp2kTest1(rp, "test24.jpg"); return regTestCleanup(rp); }
int main(int argc, char **argv) { PIX *pixs, *pixd; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("stampede2.jpg"); pixa = pixaCreate(0); pixSaveTiled(pixs, pixa, 1.0, 1, 20, 8); AddTestSet(pixa, pixs, L_SOBEL_EDGE, 18, 40, 40, 0.7, -25, 280, 128); AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 18, 40, 40, 0.7, -25, 280, 128); AddTestSet(pixa, pixs, L_SOBEL_EDGE, 10, 40, 40, 0.7, -15, 305, 128); AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 10, 40, 40, 0.7, -15, 305, 128); AddTestSet(pixa, pixs, L_SOBEL_EDGE, 15, 40, 40, 0.6, -45, 285, 158); AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 15, 40, 40, 0.6, -45, 285, 158); pixDestroy(&pixs); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 0 */ pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixaDestroy(&pixa); return regTestCleanup(rp); }
main(int argc, char **argv) { PIX *pixs; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; fprintf(stderr, "\nTest binary image:\n"); pixs = pixRead(BINARY_IMAGE); RotateOrthTest(pixs, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest 4 bpp colormapped image:\n"); pixs = pixRead(FOUR_BPP_IMAGE); RotateOrthTest(pixs, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest grayscale image:\n"); pixs = pixRead(GRAYSCALE_IMAGE); RotateOrthTest(pixs, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest colormap image:\n"); pixs = pixRead(COLORMAP_IMAGE); RotateOrthTest(pixs, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest rgb image:\n"); pixs = pixRead(RGB_IMAGE); RotateOrthTest(pixs, rp); pixDestroy(&pixs); return regTestCleanup(rp); }
int main(int argc, char **argv) { L_REGPARAMS *rp; #if !HAVE_LIBWEBP fprintf(stderr, "webpio is not enabled\n" "libwebp is required for webpio_reg\n" "See environ.h: #define HAVE_LIBWEBP\n" "See prog/Makefile: link in -lwebp\n\n"); return 0; #endif /* abort */ /* This test uses libjpeg */ #if !HAVE_LIBJPEG fprintf(stderr, "libjpeg is required for webpio_reg\n\n"); return 0; #endif /* abort */ if (regTestSetup(argc, argv, &rp)) return 1; DoWebpTest1(rp, "weasel2.4c.png"); DoWebpTest1(rp, "weasel8.240c.png"); DoWebpTest1(rp, "karen8.jpg"); DoWebpTest1(rp, "test24.jpg"); DoWebpTest2(rp, "test24.jpg", 50, 0, 43.217, 0.1); DoWebpTest2(rp, "test24.jpg", 75, 0, 45.759, 0.1); DoWebpTest2(rp, "test24.jpg", 90, 0, 52.066, 0.1); DoWebpTest2(rp, "test24.jpg", 100, 0, 57.879, 0.1); DoWebpTest2(rp, "test24.jpg", 0, 1, 1000.0, 0.1); return regTestCleanup(rp); }
l_int32 main(int argc, char **argv) { l_uint32 *colors; l_int32 ncolors; PIX *pix1, *pix2, *pix3; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* Find the most populated colors */ pix1 = pixRead("fish24.jpg"); pixGetMostPopulatedColors(pix1, 2, 3, 10, &colors, NULL); pix2 = pixDisplayColorArray(colors, 10, 190, 5, 1); pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */ lept_free(colors); pixDestroy(&pix2); /* Do a simple color quantization with sigbits = 2 */ pix2 = pixSimpleColorQuantize(pix1, 2, 3, 10); pixDisplayWithTitle(pix2, 0, 400, NULL, rp->display); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */ pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_TO_FULL_COLOR); regTestComparePix(rp, pix2, pix3); /* 2 */ pixNumColors(pix3, 1, &ncolors); regTestCompareValues(rp, ncolors, 10, 0.0); /* 3 */ pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* Do a simple color quantization with sigbits = 3 */ pix1 = pixRead("wyom.jpg"); pixNumColors(pix1, 1, &ncolors); /* >255, so should give 0 */ regTestCompareValues(rp, ncolors, 0, 0.0); /* 4 */ pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20); pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 5 */ ncolors = pixcmapGetCount(pixGetColormap(pix2)); regTestCompareValues(rp, ncolors, 20, 0.0); /* 6 */ pixDestroy(&pix1); pixDestroy(&pix2); /* Find the number of perceptually significant gray intensities */ pix1 = pixRead("marge.jpg"); pix2 = pixConvertTo8(pix1, 0); pixNumSignificantGrayColors(pix2, 20, 236, 0.0001, 1, &ncolors); regTestCompareValues(rp, ncolors, 219, 0.0); /* 7 */ pixDestroy(&pix1); pixDestroy(&pix2); return regTestCleanup(rp); }
l_int32 main(int argc, char **argv) { PIX *pixs, *pixd; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; fprintf(stderr, "Test binary image:\n"); pixs = pixRead(BINARY_IMAGE); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 2 bpp cmapped image with filled cmap:\n"); pixs = pixRead(TWO_BPP_IMAGE); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 4 bpp cmapped image with unfilled cmap:\n"); pixs = pixRead(FOUR_BPP_IMAGE1); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 4 bpp cmapped image with filled cmap:\n"); pixs = pixRead(FOUR_BPP_IMAGE2); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 8 bpp grayscale image:\n"); pixs = pixRead(EIGHT_BPP_IMAGE); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 8 bpp grayscale cmap image:\n"); pixs = pixRead(EIGHT_BPP_CMAP_IMAGE1); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); fprintf(stderr, "Test 8 bpp color cmap image:\n"); pixs = pixRead(EIGHT_BPP_CMAP_IMAGE2); pixd = pixOctreeColorQuant(pixs, 200, 0); RotateTest(pixs, 0.25, rp); pixDestroy(&pixs); pixDestroy(&pixd); fprintf(stderr, "Test rgb image:\n"); pixs = pixRead(RGB_IMAGE); RotateTest(pixs, 1.0, rp); pixDestroy(&pixs); return regTestCleanup(rp); }
main(int argc, char **argv) { l_int32 i, ival, n; l_float32 f, val; GPLOT *gplot; NUMA *na1, *na2, *na3; PIX *pixt; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* Generate a 1D signal and plot it */ na1 = numaCreate(500); for (i = 0; i < 500; i++) { f = 48.3 * sin(0.13 * (l_float32)i); f += 63.4 * cos(0.21 * (l_float32)i); numaAddNumber(na1, f); } gplot = gplotCreate("/tmp/extrema", GPLOT_PNG, "Extrema test", "x", "y"); gplotAddPlot(gplot, NULL, na1, GPLOT_LINES, "plot 1"); /* Find the local min and max and plot them */ na2 = numaFindExtrema(na1, 38.3); n = numaGetCount(na2); na3 = numaCreate(n); for (i = 0; i < n; i++) { numaGetIValue(na2, i, &ival); numaGetFValue(na1, ival, &val); numaAddNumber(na3, val); } gplotAddPlot(gplot, na2, na3, GPLOT_POINTS, "plot 2"); gplotMakeOutput(gplot); #ifndef _WIN32 sleep(1); #else Sleep(1000); #endif /* _WIN32 */ regTestCheckFile(rp, "/tmp/extrema.png"); /* 0 */ pixt = pixRead("/tmp/extrema.png"); pixDisplayWithTitle(pixt, 100, 100, "Extrema test", rp->display); pixDestroy(&pixt); gplotDestroy(&gplot); numaDestroy(&na1); numaDestroy(&na2); numaDestroy(&na3); return regTestCleanup(rp); }
main(int argc, char **argv) { l_int32 i, k, x, y, w, h; BOX *box; BOXA *boxa1, *boxa2; PIX *pix1, *pix2, *pixd; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; for (k = 0; k < 7; k++) { srand(45617); pixa = pixaCreate(2); boxa1 = boxaCreate(0); for (i = 0; i < 500; i++) { x = (l_int32)(600.0 * (l_float64)rand() / (l_float64)RAND_MAX); y = (l_int32)(600.0 * (l_float64)rand() / (l_float64)RAND_MAX); w = (l_int32) (1.0 + maxsize[k] * (l_float64)rand() / (l_float64)RAND_MAX); h = (l_int32) (1.0 + maxsize[k] * (l_float64)rand() / (l_float64)RAND_MAX); box = boxCreate(x, y, w, h); boxaAddBox(boxa1, box, L_INSERT); } pix1 = pixCreate(660, 660, 1); pixRenderBoxa(pix1, boxa1, 1, L_SET_PIXELS); pixaAddPix(pixa, pix1, L_INSERT); boxa2 = boxaCombineOverlaps(boxa1); pix2 = pixCreate(660, 660, 1); pixRenderBoxa(pix2, boxa2, 1, L_SET_PIXELS); pixaAddPix(pixa, pix2, L_INSERT); pixd = pixaDisplayTiledInRows(pixa, 1, 1500, 1.0, 0, 50, 2); pixDisplayWithTitle(pixd, 100, 100 + 100 * k, NULL, rp->display); regTestWritePixAndCheck(rp, pixd, IFF_PNG); fprintf(stderr, "%d: n_init = %d, n_final = %d\n", k, boxaGetCount(boxa1), boxaGetCount(boxa2)); pixDestroy(&pixd); boxaDestroy(&boxa1); boxaDestroy(&boxa2); pixaDestroy(&pixa); } regTestCleanup(rp); return 0; }
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) { PIX *pixs; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("feyn-fract.tif"); TestAll(rp, pixs, FALSE); TestAll(rp, pixs, TRUE); pixDestroy(&pixs); return regTestCleanup(rp); }
l_int32 main(int argc, char **argv) { l_int32 i; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; for (i = 0; i < 3; i++) TestBoxa(rp, i); for (i = 0; i < 3; i++) PlotBoxa(rp, i); return regTestCleanup(rp); }
int main(int argc, char **argv) { BOX *box; PIX *pixt1, *pixt2, *pix1, *pix2, *pix3; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixt1 = pixRead("feyn.tif"); /* 300 ppi */ box = boxCreate(19, 774, 2247, 2025); pix1 = pixClipRectangle(pixt1, box, NULL); pixDestroy(&pixt1); pixt1 = pixRead("lucasta.150.jpg"); pixt2 = pixConvertTo1(pixt1, 128); /* 150 ppi */ pix2 = pixScale(pixt2, 2.2, 2.2); /* 300 ppi */ pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixRead("zanotti-78.jpg"); pixt2 = pixConvertTo1(pixt1, 128); /* 150 ppi */ pix3 = pixScale(pixt2, 2.0, 2.0); /* 300 ppi */ pixDestroy(&pixt1); pixDestroy(&pixt2); boxDestroy(&box); /* Make word boxes using pixWordMaskByDilation() */ MakeWordBoxes1(pix1, 20, rp); /* 0 */ MakeWordBoxes1(pix2, 20, rp); /* 1 */ MakeWordBoxes1(pix3, 20, rp); /* 2 */ /* Make word boxes using the higher-level functions * pixGetWordsInTextlines() and pixGetWordBoxesInTextlines() */ MakeWordBoxes2(pix1, 1, rp); /* 3, 4 */ MakeWordBoxes2(pix2, 1, rp); /* 5, 6 */ MakeWordBoxes2(pix3, 1, rp); /* 7, 8 */ /* Make word boxes using the higher-level functions * pixGetWordsInTextlines() and pixGetWordBoxesInTextlines() */ MakeWordBoxes2(pix1, 2, rp); /* 9, 10 */ MakeWordBoxes2(pix2, 2, rp); /* 11, 12 */ MakeWordBoxes2(pix3, 2, rp); /* 13, 14 */ pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); return regTestCleanup(rp); }
int main(int argc, char **argv) { l_int32 i; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; for (i = 0; i < 4; i++) { /* if (i != 2) continue; */ TestImage(image[i], i, rp); } return regTestCleanup(rp); }
main(int argc, char **argv) { char buf[256]; l_int32 i, j, k, index, conn, depth, bc; BOX *box; PIX *pix, *pixs, *pixd; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pix = pixRead("feyn.tif"); box = boxCreate(383, 338, 1480, 1050); pixs = pixClipRectangle(pix, box, NULL); regTestWritePixAndCheck(rp, pixs, IFF_PNG); /* 0 */ for (i = 0; i < 2; i++) { conn = 4 + 4 * i; for (j = 0; j < 2; j++) { depth = 8 + 8 * j; for (k = 0; k < 2; k++) { bc = k + 1; index = 4 * i + 2 * j + k; fprintf(stderr, "Set %d\n", index); if (DEBUG) { fprintf(stderr, "%d: conn = %d, depth = %d, bc = %d\n", rp->index + 1, conn, depth, bc); } pixa = pixaCreate(0); pixSaveTiled(pixs, pixa, 1, 1, 20, 8); TestDistance(pixa, pixs, conn, depth, bc, rp); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 0, 0, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pixd); } } } boxDestroy(&box); pixDestroy(&pix); pixDestroy(&pixs); regTestCleanup(rp); return 0; }
main(int argc, char **argv) { l_int32 patno, red; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; for (patno = 0; patno < 2; patno++) { for (red = 4; red <= 16; red *= 2) { if (patno == 1 && red == 16) continue; GeneratePattern(patno, red, rp); } } regTestCleanup(rp); return 0; }
main(int argc, char **argv) { l_int32 i, j; PIX *pixs, *pixt, *pixd; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("test8.jpg"); pixt = pixCopy(NULL, pixs); /* Copy, in-place and one COLUMN at a time, from the right side to the left side. */ for (j = 0; j < 200; j++) pixRasterop(pixs, 20 + j, 20, 1, 250, PIX_SRC, pixs, 250 + j, 20); pixDisplayWithTitle(pixs, 50, 50, "in-place copy", rp->display); /* Copy, in-place and one ROW at a time, from the right side to the left side. */ for (i = 0; i < 250; i++) pixRasterop(pixt, 20, 20 + i, 200, 1, PIX_SRC, pixt, 250, 20 + i); /* Test */ regTestComparePix(rp, pixs, pixt); /* 0 */ pixDestroy(&pixs); pixDestroy(&pixt); /* Show the mirrored border, which uses the general pixRasterop() on an image in-place. */ pixs = pixRead("test8.jpg"); pixt = pixRemoveBorder(pixs, 40); pixd = pixAddMirroredBorder(pixt, 40, 40, 40, 40); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 1 */ pixDisplayWithTitle(pixd, 650, 50, "mirrored border", rp->display); pixDestroy(&pixs); pixDestroy(&pixt); pixDestroy(&pixd); return regTestCleanup(rp); }
int main(int argc, char **argv) { PIX *pixs; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("rock.png"); DoTestsOnImage(pixs, rp, 2000); /* 0 - 16 */ pixDestroy(&pixs); pixs = pixRead("church.png"); DoTestsOnImage(pixs, rp, 1500); /* 17 - 33 */ pixDestroy(&pixs); pixs = pixRead("color-wheel-hue.jpg"); DoTestsOnImage(pixs, rp, 1000); /* 34 - 50 */ pixDestroy(&pixs); return regTestCleanup(rp); }
main(int argc, char **argv) { PIX *pixs, *pixt1, *pixt2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("w91frag.jpg"); PixTest3(pixs, 3, 0.20, 2, 3, 0, rp); PixTest3(pixs, 6, 0.20, 100, 100, 1, rp); PixTest3(pixs, 10, 0.40, 10, 10, 2, rp); PixTest3(pixs, 10, 0.40, 20, 20, 3, rp); PixTest3(pixs, 20, 0.34, 30, 30, 4, rp); pixt1 = PixTest1(pixs, 7, 0.34, rp); pixt2 = PixTest2(pixs, 7, 0.34, 4, 4, rp); regTestComparePix(rp, pixt1, pixt2); pixDestroy(&pixt1); pixDestroy(&pixt2); /* Do combination of contrast norm and sauvola */ pixt1 = pixContrastNorm(NULL, pixs, 100, 100, 55, 1, 1); pixSauvolaBinarizeTiled(pixt1, 8, 0.34, 1, 1, NULL, &pixt2); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); regTestWritePixAndCheck(rp, pixt2, IFF_PNG); pixDisplayWithTitle(pixt1, 100, 500, NULL, rp->display); pixDisplayWithTitle(pixt2, 700, 500, NULL, rp->display); pixDestroy(&pixt1); pixDestroy(&pixt2); regTestCleanup(rp); pixDestroy(&pixs); return 0; }
main(int argc, char **argv) { l_int32 count, success, display; FILE *fp; PIX *pixs; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &fp, &display, &success, &rp)) return 1; count = 0; fprintf(stderr, "\nTest binary image:\n"); pixs = pixRead(BINARY_IMAGE); RotateOrthTest(pixs, &count, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest 4 bpp colormapped image:\n"); pixs = pixRead(FOUR_BPP_IMAGE); RotateOrthTest(pixs, &count, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest grayscale image:\n"); pixs = pixRead(GRAYSCALE_IMAGE); RotateOrthTest(pixs, &count, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest colormap image:\n"); pixs = pixRead(COLORMAP_IMAGE); RotateOrthTest(pixs, &count, rp); pixDestroy(&pixs); fprintf(stderr, "\nTest rgb image:\n"); pixs = pixRead(RGB_IMAGE); RotateOrthTest(pixs, &count, rp); pixDestroy(&pixs); regTestCleanup(argc, argv, fp, success, rp); return 0; }
main(int argc, char **argv) { PIX *pixs, *pixg1, *pixg2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* Use for input two different images */ pixs = pixRead("projectionstats.jpg"); pixg1 = pixConvertTo8(pixs, 0); pixDestroy(&pixs); pixs = pixRead("feyn.tif"); pixg2 = pixScaleToGray4(pixs); pixDestroy(&pixs); TestProjection(rp, pixg1); TestProjection(rp, pixg2); pixDestroy(&pixg1); pixDestroy(&pixg2); regTestCleanup(rp); return 0; }
int main(int argc, char **argv) { l_int32 success, failure; L_REGPARAMS *rp; #if !HAVE_LIBPNG || !HAVE_LIBZ fprintf(stderr, "libpng & libz are required for testing pngio_reg\n"); return 1; #endif /* abort */ if (regTestSetup(argc, argv, &rp)) return 1; /* --------- Part 1: Test lossless r/w to file ---------*/ failure = FALSE; success = TRUE; fprintf(stderr, "Test bmp 1 bpp file:\n"); if (ioFormatTest(FILE_1BPP)) success = FALSE; fprintf(stderr, "\nTest 2 bpp file:\n"); if (ioFormatTest(FILE_2BPP)) success = FALSE; fprintf(stderr, "\nTest 2 bpp file with cmap:\n"); if (ioFormatTest(FILE_2BPP_C)) success = FALSE; fprintf(stderr, "\nTest 4 bpp file:\n"); if (ioFormatTest(FILE_4BPP)) success = FALSE; fprintf(stderr, "\nTest 4 bpp file with cmap:\n"); if (ioFormatTest(FILE_4BPP_C)) success = FALSE; fprintf(stderr, "\nTest 8 bpp grayscale file with cmap:\n"); if (ioFormatTest(FILE_8BPP)) success = FALSE; fprintf(stderr, "\nTest 8 bpp color file with cmap:\n"); if (ioFormatTest(FILE_8BPP_C)) success = FALSE; fprintf(stderr, "\nTest 16 bpp file:\n"); if (ioFormatTest(FILE_16BPP)) success = FALSE; fprintf(stderr, "\nTest 32 bpp RGB file:\n"); if (ioFormatTest(FILE_32BPP)) success = FALSE; fprintf(stderr, "\nTest 32 bpp RGBA file:\n"); if (ioFormatTest(FILE_32BPP_ALPHA)) success = FALSE; fprintf(stderr, "\nTest spp = 1, cmap with alpha file:\n"); if (ioFormatTest(FILE_CMAP_ALPHA)) success = FALSE; fprintf(stderr, "\nTest spp = 1, cmap with alpha (small alpha array):\n"); if (ioFormatTest(FILE_CMAP_ALPHA2)) success = FALSE; fprintf(stderr, "\nTest spp = 1, fully transparent with alpha file:\n"); if (ioFormatTest(FILE_TRANS_ALPHA)) success = FALSE; fprintf(stderr, "\nTest spp = 2, gray with alpha file:\n"); if (ioFormatTest(FILE_GRAY_ALPHA)) success = FALSE; if (success) { fprintf(stderr, "\n ********** Success on lossless r/w to file *********\n\n"); } else { fprintf(stderr, "\n ******* Failure on at least one r/w to file ******\n\n"); } if (!success) failure = TRUE; /* ------------ Part 2: Test lossless r/w to memory ------------ */ pixDisplayWrite(NULL, -1); success = TRUE; if (test_mem_png(FILE_1BPP)) success = FALSE; if (test_mem_png(FILE_2BPP)) success = FALSE; if (test_mem_png(FILE_2BPP_C)) success = FALSE; if (test_mem_png(FILE_4BPP)) success = FALSE; if (test_mem_png(FILE_4BPP_C)) success = FALSE; if (test_mem_png(FILE_8BPP)) success = FALSE; if (test_mem_png(FILE_8BPP_C)) success = FALSE; if (test_mem_png(FILE_16BPP)) success = FALSE; if (test_mem_png(FILE_32BPP)) success = FALSE; if (test_mem_png(FILE_32BPP_ALPHA)) success = FALSE; if (test_mem_png(FILE_CMAP_ALPHA)) success = FALSE; if (test_mem_png(FILE_CMAP_ALPHA2)) success = FALSE; if (test_mem_png(FILE_TRANS_ALPHA)) success = FALSE; if (test_mem_png(FILE_GRAY_ALPHA)) success = FALSE; if (success) { fprintf(stderr, "\n ****** Success on lossless r/w to memory *****\n"); } else { fprintf(stderr, "\n ******* Failure on at least one r/w to memory ******\n"); } if (!success) failure = TRUE; /* ------------ Part 3: Test lossless 1 and 8 bpp r/w ------------ */ fprintf(stderr, "\nTest lossless 1 and 8 bpp r/w\n"); success = TRUE; if (test_1bpp_trans(rp) == 0) success = FALSE; if (test_1bpp_color(rp) == 0) success = FALSE; if (test_1bpp_gray(rp) == 0) success = FALSE; if (test_1bpp_bw1(rp) == 0) success = FALSE; if (test_1bpp_bw2(rp) == 0) success = FALSE; if (test_8bpp_trans(rp) == 0) success = FALSE; if (success) { fprintf(stderr, "\n ******* Success on 1 and 8 bpp lossless *******\n\n"); } else { fprintf(stderr, "\n ******* Failure on 1 and 8 bpp lossless *******\n\n"); } if (!success) failure = TRUE; /* -------------- Part 4: Read header information -------------- */ success = TRUE; if (get_header_data(FILE_1BPP)) success = FALSE; if (get_header_data(FILE_2BPP)) success = FALSE; if (get_header_data(FILE_2BPP_C)) success = FALSE; if (get_header_data(FILE_4BPP)) success = FALSE; if (get_header_data(FILE_4BPP_C)) success = FALSE; if (get_header_data(FILE_8BPP)) success = FALSE; if (get_header_data(FILE_8BPP_C)) success = FALSE; if (get_header_data(FILE_16BPP)) success = FALSE; if (get_header_data(FILE_32BPP)) success = FALSE; if (get_header_data(FILE_32BPP_ALPHA)) success = FALSE; if (get_header_data(FILE_CMAP_ALPHA)) success = FALSE; if (get_header_data(FILE_CMAP_ALPHA2)) success = FALSE; if (get_header_data(FILE_TRANS_ALPHA)) success = FALSE; if (get_header_data(FILE_GRAY_ALPHA)) success = FALSE; if (success) { fprintf(stderr, "\n ******* Success on reading headers *******\n\n"); } else { fprintf(stderr, "\n ******* Failure on reading headers *******\n\n"); } if (!success) failure = TRUE; if (!failure) { fprintf(stderr, " ******* Success on all tests *******\n\n"); } else { fprintf(stderr, " ******* Failure on at least one test *******\n\n"); } if (failure) rp->success = FALSE; return regTestCleanup(rp); }
int main(int argc, char **argv) { l_int32 i, n, binsize, binstart, nbins; l_float32 pi, val, angle, xval, yval, x0, y0, startval, fbinsize; l_float32 minval, maxval, meanval, median, variance, rankval, rank, rmsdev; GPLOT *gplot; NUMA *na, *nahisto, *nax, *nay, *nap, *nasx, *nasy; NUMA *nadx, *nady, *nafx, *nafy, *na1, *na2, *na3, *na4; PIX *pixs, *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pixd; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; lept_mkdir("lept/numa1"); /* -------------------------------------------------------------------* * Histograms * * -------------------------------------------------------------------*/ pi = 3.1415926535; na = numaCreate(5000); for (i = 0; i < 500000; i++) { angle = 0.02293 * i * pi; val = (l_float32)(999. * sin(angle)); numaAddNumber(na, val); } nahisto = numaMakeHistogramClipped(na, 6, 2000); nbins = numaGetCount(nahisto); nax = numaMakeSequence(0, 1, nbins); gplot = gplotCreate("/tmp/lept/numa1/histo1", GPLOT_PNG, "example histo 1", "i", "histo[i]"); gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nax); numaDestroy(&nahisto); nahisto = numaMakeHistogram(na, 1000, &binsize, &binstart); nbins = numaGetCount(nahisto); nax = numaMakeSequence(binstart, binsize, nbins); fprintf(stderr, " binsize = %d, binstart = %d\n", binsize, binstart); gplot = gplotCreate("/tmp/lept/numa1/histo2", GPLOT_PNG, "example histo 2", "i", "histo[i]"); gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nax); numaDestroy(&nahisto); nahisto = numaMakeHistogram(na, 1000, &binsize, NULL); nbins = numaGetCount(nahisto); nax = numaMakeSequence(0, binsize, nbins); fprintf(stderr, " binsize = %d, binstart = %d\n", binsize, 0); gplot = gplotCreate("/tmp/lept/numa1/histo3", GPLOT_PNG, "example histo 3", "i", "histo[i]"); gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nax); numaDestroy(&nahisto); nahisto = numaMakeHistogramAuto(na, 1000); nbins = numaGetCount(nahisto); numaGetParameters(nahisto, &startval, &fbinsize); nax = numaMakeSequence(startval, fbinsize, nbins); fprintf(stderr, " binsize = %7.4f, binstart = %8.3f\n", fbinsize, startval); gplot = gplotCreate("/tmp/lept/numa1/histo4", GPLOT_PNG, "example histo 4", "i", "histo[i]"); gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine"); gplotMakeOutput(gplot); gplotDestroy(&gplot); pix1 = pixRead("/tmp/lept/numa1/histo1.png"); pix2 = pixRead("/tmp/lept/numa1/histo2.png"); pix3 = pixRead("/tmp/lept/numa1/histo3.png"); pix4 = pixRead("/tmp/lept/numa1/histo4.png"); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 0 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */ regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 2 */ regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 3 */ pixa = pixaCreate(4); pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); pixaAddPix(pixa, pix3, L_INSERT); pixaAddPix(pixa, pix4, L_INSERT); if (rp->display) { pixd = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 20, 2); pixDisplayWithTitle(pixd, 0, 0, NULL, 1); pixDestroy(&pixd); } pixaDestroy(&pixa); numaDestroy(&nax); numaDestroy(&nahisto); numaGetStatsUsingHistogram(na, 2000, &minval, &maxval, &meanval, &variance, &median, 0.80, &rankval, &nahisto); rmsdev = sqrt((l_float64)variance); numaHistogramGetRankFromVal(nahisto, rankval, &rank); regTestCompareValues(rp, -999.00, minval, 0.1); /* 4 */ regTestCompareValues(rp, 999.00, maxval, 0.1); /* 5 */ regTestCompareValues(rp, 0.055, meanval, 0.001); /* 6 */ regTestCompareValues(rp, 0.30, median, 0.005); /* 7 */ regTestCompareValues(rp, 706.41, rmsdev, 0.1); /* 8 */ regTestCompareValues(rp, 808.15, rankval, 0.1); /* 9 */ regTestCompareValues(rp, 0.800, rank, 0.01); /* 10 */ if (rp->display) { fprintf(stderr, "Sin histogram: \n" " min val = %7.3f -- should be -999.00\n" " max val = %7.3f -- should be 999.00\n" " mean val = %7.3f -- should be 0.055\n" " median = %7.3f -- should be 0.30\n" " rmsdev = %7.3f -- should be 706.41\n" " rank val = %7.3f -- should be 808.152\n" " rank = %7.3f -- should be 0.800\n", minval, maxval, meanval, median, rmsdev, rankval, rank); } numaDestroy(&nahisto); numaDestroy(&na); /* -------------------------------------------------------------------* * Interpolation * * -------------------------------------------------------------------*/ /* Test numaInterpolateEqxInterval() */ pixs = pixRead("test8.jpg"); na = pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1); nasy = numaGetPartialSums(na); gplotSimple1(nasy, GPLOT_PNG, "/tmp/lept/numa1/int1", "partial sums"); gplotSimple1(na, GPLOT_PNG, "/tmp/lept/numa1/int2", "simple test"); numaInterpolateEqxInterval(0.0, 1.0, na, L_LINEAR_INTERP, 0.0, 255.0, 15, &nax, &nay); gplot = gplotCreate("/tmp/lept/numa1/int3", GPLOT_PNG, "test interpolation", "pix val", "num pix"); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&na); numaDestroy(&nasy); numaDestroy(&nax); numaDestroy(&nay); pixDestroy(&pixs); /* Test numaInterpolateArbxInterval() */ pixs = pixRead("test8.jpg"); na = pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1); nasy = numaGetPartialSums(na); numaInsertNumber(nasy, 0, 0.0); nasx = numaMakeSequence(0.0, 1.0, 257); numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP, 10.0, 250.0, 23, &nax, &nay); gplot = gplotCreate("/tmp/lept/numa1/int4", GPLOT_PNG, "arbx interpolation", "pix val", "cum num pix"); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&na); numaDestroy(&nasx); numaDestroy(&nasy); numaDestroy(&nax); numaDestroy(&nay); pixDestroy(&pixs); /* Test numaInterpolateArbxVal() */ pixs = pixRead("test8.jpg"); na = pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1); nasy = numaGetPartialSums(na); numaInsertNumber(nasy, 0, 0.0); nasx = numaMakeSequence(0.0, 1.0, 257); nax = numaMakeSequence(15.0, (250.0 - 15.0) / 23.0, 24); n = numaGetCount(nax); nay = numaCreate(n); for (i = 0; i < n; i++) { numaGetFValue(nax, i, &xval); numaInterpolateArbxVal(nasx, nasy, L_QUADRATIC_INTERP, xval, &yval); numaAddNumber(nay, yval); } gplot = gplotCreate("/tmp/lept/numa1/int5", GPLOT_PNG, "arbx interpolation", "pix val", "cum num pix"); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&na); numaDestroy(&nasx); numaDestroy(&nasy); numaDestroy(&nax); numaDestroy(&nay); pixDestroy(&pixs); /* Test interpolation */ nasx = numaRead("testangle.na"); nasy = numaRead("testscore.na"); gplot = gplotCreate("/tmp/lept/numa1/int6", GPLOT_PNG, "arbx interpolation", "angle", "score"); numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP, -2.00, 0.0, 50, &nax, &nay); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "linear"); numaDestroy(&nax); numaDestroy(&nay); numaInterpolateArbxInterval(nasx, nasy, L_QUADRATIC_INTERP, -2.00, 0.0, 50, &nax, &nay); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "quadratic"); numaDestroy(&nax); numaDestroy(&nay); gplotMakeOutput(gplot); gplotDestroy(&gplot); gplot = gplotCreate("/tmp/lept/numa1/int7", GPLOT_PNG, "arbx interpolation", "angle", "score"); numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP, -1.2, -0.8, 50, &nax, &nay); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "quadratic"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaFitMax(nay, &yval, nax, &xval); if (rp->display) fprintf(stderr, "max = %f at loc = %f\n", yval, xval); pixa = pixaCreate(7); pix1 = pixRead("/tmp/lept/numa1/int1.png"); pix2 = pixRead("/tmp/lept/numa1/int2.png"); pix3 = pixRead("/tmp/lept/numa1/int3.png"); pix4 = pixRead("/tmp/lept/numa1/int4.png"); pix5 = pixRead("/tmp/lept/numa1/int5.png"); pix6 = pixRead("/tmp/lept/numa1/int6.png"); pix7 = pixRead("/tmp/lept/numa1/int7.png"); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 11 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 12 */ regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 13 */ regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 14 */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 15 */ regTestWritePixAndCheck(rp, pix6, IFF_PNG); /* 16 */ regTestWritePixAndCheck(rp, pix7, IFF_PNG); /* 17 */ pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); pixaAddPix(pixa, pix3, L_INSERT); pixaAddPix(pixa, pix4, L_INSERT); pixaAddPix(pixa, pix5, L_INSERT); pixaAddPix(pixa, pix6, L_INSERT); pixaAddPix(pixa, pix7, L_INSERT); if (rp->display) { pixd = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 20, 2); pixDisplayWithTitle(pixd, 300, 0, NULL, 1); pixDestroy(&pixd); } pixaDestroy(&pixa); numaDestroy(&nasx); numaDestroy(&nasy); numaDestroy(&nax); numaDestroy(&nay); /* -------------------------------------------------------------------* * Integration and differentiation * * -------------------------------------------------------------------*/ /* Test integration and differentiation */ nasx = numaRead("testangle.na"); nasy = numaRead("testscore.na"); /* ---------- Plot the derivative ---------- */ numaDifferentiateInterval(nasx, nasy, -2.0, 0.0, 50, &nadx, &nady); gplot = gplotCreate("/tmp/lept/numa1/diff1", GPLOT_PNG, "derivative", "angle", "slope"); gplotAddPlot(gplot, nadx, nady, GPLOT_LINES, "derivative"); gplotMakeOutput(gplot); gplotDestroy(&gplot); /* ---------- Plot the original function ----------- */ /* and the integral of the derivative; the two */ /* should be approximately the same. */ gplot = gplotCreate("/tmp/lept/numa1/diff2", GPLOT_PNG, "integ-diff", "angle", "val"); numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP, -2.00, 0.0, 50, &nafx, &nafy); gplotAddPlot(gplot, nafx, nafy, GPLOT_LINES, "function"); n = numaGetCount(nadx); numaGetFValue(nafx, 0, &x0); numaGetFValue(nafy, 0, &y0); nay = numaCreate(n); /* (Note: this tests robustness of the integrator: we go from * i = 0, and choose to have only 1 point in the interpolation * there, which is too small and causes the function to bomb out.) */ fprintf(stderr, "We must get a 'npts < 2' error here:\n"); for (i = 0; i < n; i++) { numaGetFValue(nadx, i, &xval); numaIntegrateInterval(nadx, nady, x0, xval, 2 * i + 1, &yval); numaAddNumber(nay, y0 + yval); } gplotAddPlot(gplot, nafx, nay, GPLOT_LINES, "anti-derivative"); gplotMakeOutput(gplot); gplotDestroy(&gplot); pixa = pixaCreate(2); pix1 = pixRead("/tmp/lept/numa1/diff1.png"); pix2 = pixRead("/tmp/lept/numa1/diff2.png"); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 18 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 19 */ pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); if (rp->display) { pixd = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 20, 2); pixDisplayWithTitle(pixd, 600, 0, NULL, 1); pixDestroy(&pixd); } pixaDestroy(&pixa); numaDestroy(&nasx); numaDestroy(&nasy); numaDestroy(&nafx); numaDestroy(&nafy); numaDestroy(&nadx); numaDestroy(&nady); numaDestroy(&nay); /* -------------------------------------------------------------------* * Rank extraction * * -------------------------------------------------------------------*/ /* Rank extraction with interpolation */ pixs = pixRead("test8.jpg"); nasy= pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1); numaMakeRankFromHistogram(0.0, 1.0, nasy, 350, &nax, &nay); gplot = gplotCreate("/tmp/lept/numa1/rank1", GPLOT_PNG, "test rank extractor", "pix val", "rank val"); gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1"); gplotMakeOutput(gplot); gplotDestroy(&gplot); numaDestroy(&nasy); numaDestroy(&nax); numaDestroy(&nay); pixDestroy(&pixs); /* Rank extraction, point by point */ pixs = pixRead("test8.jpg"); nap = numaCreate(200); pixGetRankValueMasked(pixs, NULL, 0, 0, 2, 0.0, &val, &na); for (i = 0; i < 101; i++) { rank = 0.01 * i; numaHistogramGetValFromRank(na, rank, &val); numaAddNumber(nap, val); } gplotSimple1(nap, GPLOT_PNG, "/tmp/lept/numa1/rank2", "rank value"); pixa = pixaCreate(2); pix1 = pixRead("/tmp/lept/numa1/rank1.png"); pix2 = pixRead("/tmp/lept/numa1/rank2.png"); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 20 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 21 */ pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); if (rp->display) { pixd = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 20, 2); pixDisplayWithTitle(pixd, 900, 0, NULL, 1); pixDestroy(&pixd); } pixaDestroy(&pixa); numaDestroy(&na); numaDestroy(&nap); pixDestroy(&pixs); /* -------------------------------------------------------------------* * Numa-morphology * * -------------------------------------------------------------------*/ na = numaRead("lyra.5.na"); gplotSimple1(na, GPLOT_PNG, "/tmp/lept/numa1/lyra1", "Original"); na1 = numaErode(na, 21); gplotSimple1(na1, GPLOT_PNG, "/tmp/lept/numa1/lyra2", "Erosion"); na2 = numaDilate(na, 21); gplotSimple1(na2, GPLOT_PNG, "/tmp/lept/numa1/lyra3", "Dilation"); na3 = numaOpen(na, 21); gplotSimple1(na3, GPLOT_PNG, "/tmp/lept/numa1/lyra4", "Opening"); na4 = numaClose(na, 21); gplotSimple1(na4, GPLOT_PNG, "/tmp/lept/numa1/lyra5", "Closing"); pixa = pixaCreate(2); pix1 = pixRead("/tmp/lept/numa1/lyra1.png"); pix2 = pixRead("/tmp/lept/numa1/lyra2.png"); pix3 = pixRead("/tmp/lept/numa1/lyra3.png"); pix4 = pixRead("/tmp/lept/numa1/lyra4.png"); pix5 = pixRead("/tmp/lept/numa1/lyra5.png"); pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); pixaAddPix(pixa, pix3, L_INSERT); pixaAddPix(pixa, pix4, L_INSERT); pixaAddPix(pixa, pix5, L_INSERT); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 22 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 23 */ regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 24 */ regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 25 */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 26 */ if (rp->display) { pixd = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 20, 2); pixDisplayWithTitle(pixd, 1200, 0, NULL, 1); pixDestroy(&pixd); } pixaDestroy(&pixa); numaDestroy(&na); numaDestroy(&na1); numaDestroy(&na2); numaDestroy(&na3); numaDestroy(&na4); pixaDestroy(&pixa); return regTestCleanup(rp); }
int main(int argc, char **argv) { l_uint8 *array1, *array2; l_int32 n1, n2, n3; size_t size1, size2; FILE *fp; BOXA *boxa1, *boxa2; PIX *pixs, *pix1; PIXA *pixa1; PIXCMAP *cmap; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("feyn.tif"); /* --------------------------------------------------------------- * * Test pixConnComp() and pixCountConnComp(), * * with output to both boxa and pixa * * --------------------------------------------------------------- */ /* First, test with 4-cc */ boxa1= pixConnComp(pixs, &pixa1, 4); n1 = boxaGetCount(boxa1); boxa2= pixConnComp(pixs, NULL, 4); n2 = boxaGetCount(boxa2); pixCountConnComp(pixs, 4, &n3); fprintf(stderr, "Number of 4 c.c.: n1 = %d; n2 = %d, n3 = %d\n", n1, n2, n3); regTestCompareValues(rp, n1, n2, 0); /* 0 */ regTestCompareValues(rp, n1, n3, 0); /* 1 */ regTestCompareValues(rp, n1, 4452, 0); /* 2 */ pix1 = pixaDisplay(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 3 */ regTestComparePix(rp, pixs, pix1); /* 4 */ pixaDestroy(&pixa1); boxaDestroy(&boxa1); boxaDestroy(&boxa2); pixDestroy(&pix1); /* Test with 8-cc */ boxa1= pixConnComp(pixs, &pixa1, 8); n1 = boxaGetCount(boxa1); boxa2= pixConnComp(pixs, NULL, 8); n2 = boxaGetCount(boxa2); pixCountConnComp(pixs, 8, &n3); fprintf(stderr, "Number of 8 c.c.: n1 = %d; n2 = %d, n3 = %d\n", n1, n2, n3); regTestCompareValues(rp, n1, n2, 0); /* 5 */ regTestCompareValues(rp, n1, n3, 0); /* 6 */ regTestCompareValues(rp, n1, 4305, 0); /* 7 */ pix1 = pixaDisplay(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 8 */ regTestComparePix(rp, pixs, pix1); /* 9 */ pixaDestroy(&pixa1); boxaDestroy(&boxa1); boxaDestroy(&boxa2); pixDestroy(&pix1); /* --------------------------------------------------------------- * * Test boxa I/O * * --------------------------------------------------------------- */ lept_mkdir("lept/conn"); boxa1 = pixConnComp(pixs, NULL, 4); fp = lept_fopen("/tmp/lept/conn/boxa1.ba", "wb+"); boxaWriteStream(fp, boxa1); lept_fclose(fp); fp = lept_fopen("/tmp/lept/conn/boxa1.ba", "rb"); boxa2 = boxaReadStream(fp); lept_fclose(fp); fp = lept_fopen("/tmp/lept/conn/boxa2.ba", "wb+"); boxaWriteStream(fp, boxa2); lept_fclose(fp); array1 = l_binaryRead("/tmp/lept/conn/boxa1.ba", &size1); array2 = l_binaryRead("/tmp/lept/conn/boxa2.ba", &size2); regTestCompareStrings(rp, array1, size1, array2, size2); /* 10 */ lept_free(array1); lept_free(array2); boxaDestroy(&boxa1); boxaDestroy(&boxa2); /* --------------------------------------------------------------- * * Just for fun, display each component as a random color in * * cmapped 8 bpp. Background is color 0; it is set to white. * * --------------------------------------------------------------- */ boxa1 = pixConnComp(pixs, &pixa1, 4); pix1 = pixaDisplayRandomCmap(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); cmap = pixGetColormap(pix1); pixcmapResetColor(cmap, 0, 255, 255, 255); /* reset background to white */ regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 11 */ if (rp->display) pixDisplay(pix1, 100, 100); boxaDestroy(&boxa1); pixDestroy(&pix1); pixaDestroy(&pixa1); pixDestroy(&pixs); return regTestCleanup(rp); }
int main(int argc, char **argv) { l_uint8 *data; l_int32 w, h, n1, n2, n, i, minval, maxval; l_int32 ncolors, rval, gval, bval, equal; l_int32 *rmap, *gmap, *bmap; l_uint32 color; l_float32 gamma; BOX *box; FILE *fp; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6; PIX *pixs, *pixb, *pixg, *pixc, *pixd; PIX *pixg2, *pixcs1, *pixcs2, *pixd1, *pixd2; PIXA *pixa, *pixa2, *pixa3; PIXCMAP *cmap, *cmap2; RGBA_QUAD *cta; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* ------------------------ (1) ----------------------------*/ /* Blend with a white background */ pix1 = pixRead("books_logo.png"); pixDisplayWithTitle(pix1, 100, 0, NULL, rp->display); pix2 = pixAlphaBlendUniform(pix1, 0xffffff00); pixDisplayWithTitle(pix2, 100, 150, NULL, rp->display); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 0 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */ /* Generate an alpha layer based on the white background */ pix3 = pixSetAlphaOverWhite(pix2); pixSetSpp(pix3, 3); pixWrite("/tmp/alphaops.2.png", pix3, IFF_PNG); /* without alpha */ regTestCheckFile(rp, "/tmp/alphaops.2.png"); /* 2 */ pixSetSpp(pix3, 4); regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3, with alpha */ pixDisplayWithTitle(pix3, 100, 300, NULL, rp->display); /* Render on a light yellow background */ pix4 = pixAlphaBlendUniform(pix3, 0xffffe000); regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 4 */ pixDisplayWithTitle(pix4, 100, 450, NULL, rp->display); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); /* ------------------------ (2) ----------------------------*/ lept_rmdir("alpha"); lept_mkdir("alpha"); /* Make the transparency (alpha) layer. * pixs is the mask. We turn it into a transparency (alpha) * layer by converting to 8 bpp. A small convolution fuzzes * the mask edges so that you don't see the pixels. */ pixs = pixRead("feyn-fract.tif"); pixGetDimensions(pixs, &w, &h, NULL); pixg = pixConvert1To8(NULL, pixs, 0, 255); pixg2 = pixBlockconvGray(pixg, NULL, 1, 1); regTestWritePixAndCheck(rp, pixg2, IFF_JFIF_JPEG); /* 5 */ pixDisplayWithTitle(pixg2, 0, 0, "alpha", rp->display); /* Make the viewable image. * pixc is the image that we see where the alpha layer is * opaque -- i.e., greater than 0. Scale it to the same * size as the mask. To visualize what this will look like * when displayed over a black background, create the black * background image, pixb, and do the blending with pixcs1 * explicitly using the alpha layer pixg2. */ pixc = pixRead("tetons.jpg"); pixcs1 = pixScaleToSize(pixc, w, h); regTestWritePixAndCheck(rp, pixcs1, IFF_JFIF_JPEG); /* 6 */ pixDisplayWithTitle(pixcs1, 300, 0, "viewable", rp->display); pixb = pixCreateTemplate(pixcs1); /* black */ pixd1 = pixBlendWithGrayMask(pixb, pixcs1, pixg2, 0, 0); regTestWritePixAndCheck(rp, pixd1, IFF_JFIF_JPEG); /* 7 */ pixDisplayWithTitle(pixd1, 600, 0, "alpha-blended 1", rp->display); /* Embed the alpha layer pixg2 into the color image pixc. * Write it out as is. Then clean pixcs1 (to 0) under the fully * transparent part of the alpha layer, and write that result * out as well. */ pixSetRGBComponent(pixcs1, pixg2, L_ALPHA_CHANNEL); pixWrite("/tmp/alpha/pixcs1.png", pixcs1, IFF_PNG); pixcs2 = pixSetUnderTransparency(pixcs1, 0, 0); pixWrite("/tmp/alpha/pixcs2.png", pixcs2, IFF_PNG); /* What will this look like over a black background? * Do the blending explicitly and display. It should * look identical to the blended result pixd1 before cleaning. */ pixd2 = pixBlendWithGrayMask(pixb, pixcs2, pixg2, 0, 0); regTestWritePixAndCheck(rp, pixd2, IFF_JFIF_JPEG); /* 8 */ pixDisplayWithTitle(pixd2, 0, 400, "alpha blended 2", rp->display); /* Read the two images back, ignoring the transparency layer. * The uncleaned image will come back identical to pixcs1. * However, the cleaned image will be black wherever * the alpha layer was fully transparent. It will * look the same when viewed through the alpha layer, * but have much better compression. */ pix1 = pixRead("/tmp/alpha/pixcs1.png"); /* just pixcs1 */ pix2 = pixRead("/tmp/alpha/pixcs2.png"); /* cleaned under transparent */ n1 = nbytesInFile("/tmp/alpha/pixcs1.png"); n2 = nbytesInFile("/tmp/alpha/pixcs2.png"); fprintf(stderr, " Original: %d bytes\n Cleaned: %d bytes\n", n1, n2); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 9 */ regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 10 */ pixDisplayWithTitle(pix1, 300, 400, "without alpha", rp->display); pixDisplayWithTitle(pix2, 600, 400, "cleaned under transparent", rp->display); pixa = pixaCreate(0); pixSaveTiled(pixg2, pixa, 1.0, 1, 20, 32); pixSaveTiled(pixcs1, pixa, 1.0, 1, 20, 0); pixSaveTiled(pix1, pixa, 1.0, 0, 20, 0); pixSaveTiled(pixd1, pixa, 1.0, 1, 20, 0); pixSaveTiled(pixd2, pixa, 1.0, 0, 20, 0); pixSaveTiled(pix2, pixa, 1.0, 1, 20, 0); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 11 */ pixDisplayWithTitle(pixd, 200, 200, "composite", rp->display); pixWrite("/tmp/alpha/alpha.png", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixb); pixDestroy(&pixg); pixDestroy(&pixg2); pixDestroy(&pixc); pixDestroy(&pixcs1); pixDestroy(&pixcs2); pixDestroy(&pixd); pixDestroy(&pixd1); pixDestroy(&pixd2); pixDestroy(&pix1); pixDestroy(&pix2); /* ------------------------ (3) ----------------------------*/ color = 0xffffa000; gamma = 1.0; minval = 0; maxval = 200; box = boxCreate(0, 85, 600, 100); pixa = pixaCreate(6); pix1 = pixRead("blend-green1.jpg"); pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixRead("blend-green2.png"); pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixRead("blend-green3.png"); pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixRead("blend-orange.jpg"); pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixRead("blend-yellow.jpg"); pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixRead("blend-red.png"); pixaAddPix(pixa, pix1, L_INSERT); n = pixaGetCount(pixa); pixa2 = pixaCreate(n); pixa3 = pixaCreate(n); for (i = 0; i < n; i++) { pix1 = pixaGetPix(pixa, i, L_CLONE); pix2 = DoBlendTest(pix1, box, color, gamma, minval, maxval, 1); regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 12, 14, ... 22 */ pixDisplayWithTitle(pix2, 150 * i, 0, NULL, rp->display); pixaAddPix(pixa2, pix2, L_INSERT); pix2 = DoBlendTest(pix1, box, color, gamma, minval, maxval, 2); regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 13, 15, ... 23 */ pixDisplayWithTitle(pix2, 150 * i, 200, NULL, rp->display); pixaAddPix(pixa3, pix2, L_INSERT); pixDestroy(&pix1); } if (rp->display) { pixaConvertToPdf(pixa2, 0, 0.75, L_FLATE_ENCODE, 0, "blend 1 test", "/tmp/alpha/blending1.pdf"); pixaConvertToPdf(pixa3, 0, 0.75, L_FLATE_ENCODE, 0, "blend 2 test", "/tmp/alpha/blending2.pdf"); } pixaDestroy(&pixa); pixaDestroy(&pixa2); pixaDestroy(&pixa3); boxDestroy(&box); /* ------------------------ (4) ----------------------------*/ /* Use one image as the alpha component for a second image */ pix1 = pixRead("test24.jpg"); pix2 = pixRead("marge.jpg"); pix3 = pixScale(pix2, 1.9, 2.2); pix4 = pixConvertTo8(pix3, 0); pixSetRGBComponent(pix1, pix4, L_ALPHA_CHANNEL); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 24 */ pixDisplayWithTitle(pix1, 600, 0, NULL, rp->display); /* Set the alpha value in a colormap to bval */ pix5 = pixOctreeColorQuant(pix1, 128, 0); cmap = pixGetColormap(pix5); pixcmapToArrays(cmap, &rmap, &gmap, &bmap, NULL); n = pixcmapGetCount(cmap); for (i = 0; i < n; i++) { pixcmapGetColor(cmap, i, &rval, &gval, &bval); cta = (RGBA_QUAD *)cmap->array; cta[i].alpha = bval; } /* Test binary serialization/deserialization of colormap with alpha */ pixcmapSerializeToMemory(cmap, 4, &ncolors, &data); cmap2 = pixcmapDeserializeFromMemory(data, 4, ncolors); CmapEqual(cmap, cmap2, &equal); regTestCompareValues(rp, TRUE, equal, 0.0); /* 25 */ pixcmapDestroy(&cmap2); lept_free(data); /* Test ascii serialization/deserialization of colormap with alpha */ fp = fopenWriteStream("/tmp/alpha/cmap.4", "w"); pixcmapWriteStream(fp, cmap); fclose(fp); fp = fopenReadStream("/tmp/alpha/cmap.4"); cmap2 = pixcmapReadStream(fp); fclose(fp); CmapEqual(cmap, cmap2, &equal); regTestCompareValues(rp, TRUE, equal, 0.0); /* 26 */ pixcmapDestroy(&cmap2); /* Test r/w for cmapped pix with non-opaque alpha */ pixDisplayWithTitle(pix5, 900, 0, NULL, rp->display); regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 27 */ pixWrite("/tmp/alpha/fourcomp.png", pix5, IFF_PNG); pix6 = pixRead("/tmp/alpha/fourcomp.png"); regTestComparePix(rp, pix5, pix6); /* 28 */ pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); lept_free(rmap); lept_free(gmap); lept_free(bmap); return regTestCleanup(rp); }
main(int argc, char **argv) { l_float32 scalefact; L_BMF *bmf, *bmftop; L_KERNEL *kel, *kelx, *kely; PIX *pixs, *pixg, *pixt, *pixd; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pix8; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* ----------------- Test on 8 bpp grayscale ---------------------*/ pixa = pixaCreate(5); bmf = bmfCreate("./fonts", 6); bmftop = bmfCreate("./fonts", 10); pixs = pixRead("lucasta-47.jpg"); pixg = pixScale(pixs, 0.4, 0.4); /* 8 bpp grayscale */ pix1 = pixConvertTo32(pixg); /* 32 bpp rgb */ AddTextAndSave(pixa, pix1, 1, bmf, textstr[0], L_ADD_BELOW, 0xff000000); pix2 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_RGB); AddTextAndSave(pixa, pix2, 0, bmf, textstr[1], L_ADD_BELOW, 0x00ff0000); pix3 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_BGR); AddTextAndSave(pixa, pix3, 0, bmf, textstr[2], L_ADD_BELOW, 0x0000ff00); pix4 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VRGB); AddTextAndSave(pixa, pix4, 0, bmf, textstr[3], L_ADD_BELOW, 0x00ff0000); pix5 = pixConvertGrayToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VBGR); AddTextAndSave(pixa, pix5, 0, bmf, textstr[4], L_ADD_BELOW, 0x0000ff00); pixt = pixaDisplay(pixa, 0, 0); pixd = pixAddSingleTextblock(pixt, bmftop, "Regression test for subpixel scaling: gray", 0xff00ff00, L_ADD_ABOVE, NULL); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 0 */ pixDisplayWithTitle(pixd, 50, 50, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixt); pixDestroy(&pixd); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); /* ----------------- Test on 32 bpp rgb ---------------------*/ pixa = pixaCreate(5); pixs = pixRead("fish24.jpg"); pix1 = pixScale(pixs, 0.4, 0.4); AddTextAndSave(pixa, pix1, 1, bmf, textstr[0], L_ADD_BELOW, 0xff000000); pix2 = pixConvertToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_RGB); AddTextAndSave(pixa, pix2, 0, bmf, textstr[1], L_ADD_BELOW, 0x00ff0000); pix3 = pixConvertToSubpixelRGB(pixs, 0.4, 0.35, L_SUBPIXEL_ORDER_BGR); AddTextAndSave(pixa, pix3, 0, bmf, textstr[2], L_ADD_BELOW, 0x0000ff00); pix4 = pixConvertToSubpixelRGB(pixs, 0.4, 0.45, L_SUBPIXEL_ORDER_VRGB); AddTextAndSave(pixa, pix4, 0, bmf, textstr[3], L_ADD_BELOW, 0x00ff0000); pix5 = pixConvertToSubpixelRGB(pixs, 0.4, 0.4, L_SUBPIXEL_ORDER_VBGR); AddTextAndSave(pixa, pix5, 0, bmf, textstr[4], L_ADD_BELOW, 0x0000ff00); pixt = pixaDisplay(pixa, 0, 0); pixd = pixAddSingleTextblock(pixt, bmftop, "Regression test for subpixel scaling: color", 0xff00ff00, L_ADD_ABOVE, NULL); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 1 */ pixDisplayWithTitle(pixd, 50, 350, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixt); pixDestroy(&pixd); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); bmfDestroy(&bmf); bmfDestroy(&bmftop); /* --------------- Test on images that are initially 1 bpp ------------*/ /* For these, it is better to apply a lowpass filter before scaling */ /* Normal scaling of 8 bpp grayscale */ scalefact = 800. / 2320.; pixs = pixRead("patent.png"); /* sharp, 300 ppi, 1 bpp image */ pix1 = pixConvertTo8(pixs, FALSE); /* use 8 bpp input */ pix2 = pixScale(pix1, scalefact, scalefact); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 2 */ /* Subpixel scaling; bad because there is very little aliasing. */ pix3 = pixConvertToSubpixelRGB(pix1, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3 */ /* Get same (bad) result doing subpixel rendering on RGB input */ pix4 = pixConvertTo32(pixs); pix5 = pixConvertToSubpixelRGB(pix4, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestComparePix(rp, pix3, pix5); /* 4 */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 5 */ /* Now apply a small lowpass filter before scaling. */ makeGaussianKernelSep(2, 2, 1.0, 1.0, &kelx, &kely); startTimer(); pix6 = pixConvolveSep(pix1, kelx, kely, 8, 1); /* normalized */ fprintf(stderr, "Time sep: %7.3f\n", stopTimer()); regTestWritePixAndCheck(rp, pix6, IFF_PNG); /* 6 */ /* Get same lowpass result with non-separated convolution */ kel = makeGaussianKernel(2, 2, 1.0, 1.0); startTimer(); pix7 = pixConvolve(pix1, kel, 8, 1); /* normalized */ fprintf(stderr, "Time non-sep: %7.3f\n", stopTimer()); regTestComparePix(rp, pix6, pix7); /* 7 */ /* Now do the subpixel scaling on this slightly blurred image */ pix8 = pixConvertToSubpixelRGB(pix6, scalefact, scalefact, L_SUBPIXEL_ORDER_RGB); regTestWritePixAndCheck(rp, pix8, IFF_PNG); /* 8 */ kernelDestroy(&kelx); kernelDestroy(&kely); kernelDestroy(&kel); pixDestroy(&pixs); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); pixDestroy(&pix7); pixDestroy(&pix8); return regTestCleanup(rp); }
int main(int argc, char **argv) { l_int32 i, j, k, w, h, w2, w4, w8, w16, w32, wpl; l_int32 count1, count2, count3; l_uint32 val32, val1, val2; l_uint32 *data1, *line1, *data2, *line2; void **lines1, **linet1, **linet2; PIX *pixs, *pix1, *pix2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("feyn-fract.tif"); pixGetDimensions(pixs, &w, &h, NULL); data1 = pixGetData(pixs); wpl = pixGetWpl(pixs); lines1 = pixGetLinePtrs(pixs, NULL); /* Get timing for the 3 different methods */ startTimer(); for (k = 0; k < 10; k++) { count1 = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (GET_DATA_BIT(lines1[i], j)) count1++; } } } fprintf(stderr, "Time with line ptrs = %5.3f sec, count1 = %d\n", stopTimer(), count1); startTimer(); for (k = 0; k < 10; k++) { count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; for (j = 0; j < w; j++) { if (l_getDataBit(line1, j)) count2++; } } } fprintf(stderr, "Time with l_get* = %5.3f sec, count2 = %d\n", stopTimer(), count2); startTimer(); for (k = 0; k < 10; k++) { count3 = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { pixGetPixel(pixs, j, i, &val32); count3 += val32; } } } fprintf(stderr, "Time with pixGetPixel() = %5.3f sec, count3 = %d\n", stopTimer(), count3); pix1 = pixCreateTemplate(pixs); linet1 = pixGetLinePtrs(pix1, NULL); pix2 = pixCreateTemplate(pixs); data2 = pixGetData(pix2); linet2 = pixGetLinePtrs(pix2, NULL); /* ------------------------------------------------- */ /* Test different methods for 1 bpp */ /* ------------------------------------------------- */ count1 = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { val1 = GET_DATA_BIT(lines1[i], j); count1 += val1; if (val1) SET_DATA_BIT(linet1[i], j); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w; j++) { val2 = l_getDataBit(line1, j); count2 += val2; if (val2) l_setDataBit(line2, j); } } CompareResults(pixs, pix1, pix2, count1, count2, "1 bpp", rp); /* ------------------------------------------------- */ /* Test different methods for 2 bpp */ /* ------------------------------------------------- */ count1 = 0; w2 = w / 2; for (i = 0; i < h; i++) { for (j = 0; j < w2; j++) { val1 = GET_DATA_DIBIT(lines1[i], j); count1 += val1; val1 += 0xbbbbbbbc; SET_DATA_DIBIT(linet1[i], j, val1); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w2; j++) { val2 = l_getDataDibit(line1, j); count2 += val2; val2 += 0xbbbbbbbc; l_setDataDibit(line2, j, val2); } } CompareResults(pixs, pix1, pix2, count1, count2, "2 bpp", rp); /* ------------------------------------------------- */ /* Test different methods for 4 bpp */ /* ------------------------------------------------- */ count1 = 0; w4 = w / 4; for (i = 0; i < h; i++) { for (j = 0; j < w4; j++) { val1 = GET_DATA_QBIT(lines1[i], j); count1 += val1; val1 += 0xbbbbbbb0; SET_DATA_QBIT(linet1[i], j, val1); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w4; j++) { val2 = l_getDataQbit(line1, j); count2 += val2; val2 += 0xbbbbbbb0; l_setDataQbit(line2, j, val2); } } CompareResults(pixs, pix1, pix2, count1, count2, "4 bpp", rp); /* ------------------------------------------------- */ /* Test different methods for 8 bpp */ /* ------------------------------------------------- */ count1 = 0; w8 = w / 8; for (i = 0; i < h; i++) { for (j = 0; j < w8; j++) { val1 = GET_DATA_BYTE(lines1[i], j); count1 += val1; val1 += 0xbbbbbb00; SET_DATA_BYTE(linet1[i], j, val1); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w8; j++) { val2 = l_getDataByte(line1, j); count2 += val2; val2 += 0xbbbbbb00; l_setDataByte(line2, j, val2); } } CompareResults(pixs, pix1, pix2, count1, count2, "8 bpp", rp); /* ------------------------------------------------- */ /* Test different methods for 16 bpp */ /* ------------------------------------------------- */ count1 = 0; w16 = w / 16; for (i = 0; i < h; i++) { for (j = 0; j < w16; j++) { val1 = GET_DATA_TWO_BYTES(lines1[i], j); count1 += val1; val1 += 0xbbbb0000; SET_DATA_TWO_BYTES(linet1[i], j, val1); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w16; j++) { val2 = l_getDataTwoBytes(line1, j); count2 += val2; val2 += 0xbbbb0000; l_setDataTwoBytes(line2, j, val2); } } CompareResults(pixs, pix1, pix2, count1, count2, "16 bpp", rp); /* ------------------------------------------------- */ /* Test different methods for 32 bpp */ /* ------------------------------------------------- */ count1 = 0; w32 = w / 32; for (i = 0; i < h; i++) { for (j = 0; j < w32; j++) { val1 = GET_DATA_FOUR_BYTES(lines1[i], j); count1 += val1 & 0xfff; SET_DATA_FOUR_BYTES(linet1[i], j, val1); } } count2 = 0; for (i = 0; i < h; i++) { line1 = data1 + i * wpl; line2 = data2 + i * wpl; for (j = 0; j < w32; j++) { val2 = l_getDataFourBytes(line1, j); count2 += val2 & 0xfff; l_setDataFourBytes(line2, j, val2); } } CompareResults(pixs, pix1, pix2, count1, count2, "32 bpp", rp); pixDestroy(&pixs); pixDestroy(&pix1); pixDestroy(&pix2); lept_free(lines1); lept_free(linet1); lept_free(linet2); return regTestCleanup(rp); }
int main(int argc, char **argv) { l_int32 success; PIX *pix; PIXA *pixa; L_REGPARAMS *rp; #if !HAVE_LIBGIF && !HAVE_LIBUNGIF fprintf(stderr, "gifio is not enabled\n" "libgif or libungif are required for gifio_reg\n" "See environ.h: #define HAVE_LIBGIF or HAVE_LIBUNGIF 1\n" "See prog/Makefile: link in -lgif or -lungif\n\n"); return 0; #endif /* abort */ if (regTestSetup(argc, argv, &rp)) return 1; /* Set up for display output */ pixa = (rp->display) ? pixaCreate(0) : NULL; lept_rmdir("lept/gif"); lept_mkdir("lept/gif"); /* ------------ Part 1: Test lossless r/w to file ------------*/ test_gif(FILE_1BPP, pixa, rp); test_gif(FILE_2BPP, pixa, rp); test_gif(FILE_4BPP, pixa, rp); test_gif(FILE_8BPP_1, pixa, rp); test_gif(FILE_8BPP_2, pixa, rp); test_gif(FILE_8BPP_3, pixa, rp); test_gif(FILE_16BPP, pixa, rp); test_gif(FILE_32BPP, pixa, rp); if (rp->success) { fprintf(stderr, "\n ****** Success on lossless r/w to file *****\n\n"); } else { fprintf(stderr, "\n ******* Failure on at least one r/w to file ******\n\n"); } if (rp->display) { pix = pixaDisplayTiledAndScaled(pixa, 32, 450, 3, 0, 20, 2); pixWrite("/tmp/lept/gif/giftest.jpg", pix, IFF_JFIF_JPEG); pixDisplay(pix, 100, 100); pixDestroy(&pix); pixaDestroy(&pixa); } /* ------------ Part 2: Test lossless r/w to memory ------------ */ success = TRUE; if (test_mem_gif(FILE_1BPP, 0)) success = FALSE; if (test_mem_gif(FILE_2BPP, 1)) success = FALSE; if (test_mem_gif(FILE_4BPP, 2)) success = FALSE; if (test_mem_gif(FILE_8BPP_1, 3)) success = FALSE; if (test_mem_gif(FILE_8BPP_2, 4)) success = FALSE; if (test_mem_gif(FILE_8BPP_3, 5)) success = FALSE; if (test_mem_gif(FILE_16BPP, 6)) success = FALSE; if (test_mem_gif(FILE_32BPP, 7)) success = FALSE; if (success) { fprintf(stderr, "\n ****** Success on lossless r/w to memory *****\n\n"); } else { fprintf(stderr, "\n ******* Failure on at least one r/w to memory ******\n\n"); } /* Success only if all tests are passed */ if (rp->success == TRUE) rp->success = success; return regTestCleanup(rp); }
int main(int argc, char **argv) { l_int32 w, h, wd, hd; l_float32 deg2rad, angle, conf; PIX *pixs, *pixb1, *pixb2, *pixr, *pixf, *pixd, *pixc; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; deg2rad = 3.1415926535 / 180.; pixa = pixaCreate(0); pixs = pixRead("feyn.tif"); pixSetOrClearBorder(pixs, 100, 250, 100, 0, PIX_CLR); pixb1 = pixReduceRankBinaryCascade(pixs, 2, 2, 0, 0); regTestWritePixAndCheck(rp, pixb1, IFF_PNG); /* 0 */ pixDisplayWithTitle(pixb1, 0, 100, NULL, rp->display); /* Add a border and locate and deskew a 40 degree rotation */ pixb2 = pixAddBorder(pixb1, BORDER, 0); pixGetDimensions(pixb2, &w, &h, NULL); pixSaveTiled(pixb2, pixa, 0.5, 1, 20, 8); pixr = pixRotateBySampling(pixb2, w / 2, h / 2, deg2rad * 40., L_BRING_IN_WHITE); regTestWritePixAndCheck(rp, pixr, IFF_PNG); /* 1 */ pixSaveTiled(pixr, pixa, 0.5, 0, 20, 0); pixFindSkewSweepAndSearchScorePivot(pixr, &angle, &conf, NULL, 1, 1, 0.0, 45.0, 2.0, 0.03, L_SHEAR_ABOUT_CENTER); fprintf(stderr, "Should be 40 degrees: angle = %7.3f, conf = %7.3f\n", angle, conf); pixf = pixRotateBySampling(pixr, w / 2, h / 2, deg2rad * angle, L_BRING_IN_WHITE); pixd = pixRemoveBorder(pixf, BORDER); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 2 */ pixSaveTiled(pixd, pixa, 0.5, 0, 20, 0); pixDestroy(&pixr); pixDestroy(&pixf); pixDestroy(&pixd); /* Do a rotation larger than 90 degrees using embedding; * Use 2 sets of measurements at 90 degrees to scan the * full range of possible rotation angles. */ pixGetDimensions(pixb1, &w, &h, NULL); pixr = pixRotate(pixb1, deg2rad * 37., L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h); regTestWritePixAndCheck(rp, pixr, IFF_PNG); /* 3 */ pixSaveTiled(pixr, pixa, 0.5, 1, 20, 0); startTimer(); pixFindSkewOrthogonalRange(pixr, &angle, &conf, 2, 1, 47.0, 1.0, 0.03, 0.0); fprintf(stderr, "Orth search time: %7.3f sec\n", stopTimer()); fprintf(stderr, "Should be about -128 degrees: angle = %7.3f\n", angle); pixd = pixRotate(pixr, deg2rad * angle, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 4 */ pixGetDimensions(pixd, &wd, &hd, NULL); pixc = pixCreate(w, h, 1); pixRasterop(pixc, 0, 0, w, h, PIX_SRC, pixd, (wd - w) / 2, (hd - h) / 2); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 5 */ pixSaveTiled(pixc, pixa, 0.5, 0, 20, 0); pixDestroy(&pixr); pixDestroy(&pixf); pixDestroy(&pixd); pixDestroy(&pixc); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 6 */ pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixDestroy(&pixs); pixDestroy(&pixb1); pixDestroy(&pixb2); pixaDestroy(&pixa); return regTestCleanup(rp); }
int main(int argc, char **argv) { char dilateseq[512], erodeseq[512]; char openseq[512], closeseq[512]; char wtophatseq[512], btophatseq[512]; l_int32 w, h; PIX *pixs, *pix1, *pix2, *pix3, *pix4, *pix5; PIXA *pixa; PIXACC *pacc; PIXCMAP *cmap; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("aneurisms8.jpg"); pixa = pixaCreate(0); /* =========================================================== */ /* -------- Test gray morph, including interpreter ------------ */ pix1 = pixDilateGray(pixs, WSIZE, HSIZE); sprintf(dilateseq, "D%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, dilateseq, 0, 0); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 0 */ regTestComparePix(rp, pix1, pix2); /* 1 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pix1 = pixErodeGray(pixs, WSIZE, HSIZE); sprintf(erodeseq, "E%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, erodeseq, 0, 100); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 2 */ regTestComparePix(rp, pix1, pix2); /* 3 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pix1 = pixOpenGray(pixs, WSIZE, HSIZE); sprintf(openseq, "O%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, openseq, 0, 200); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 4 */ regTestComparePix(rp, pix1, pix2); /* 5 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pix1 = pixCloseGray(pixs, WSIZE, HSIZE); sprintf(closeseq, "C%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, closeseq, 0, 300); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 6 */ regTestComparePix(rp, pix1, pix2); /* 7 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pix1 = pixTophat(pixs, WSIZE, HSIZE, L_TOPHAT_WHITE); sprintf(wtophatseq, "Tw%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, wtophatseq, 0, 400); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 8 */ regTestComparePix(rp, pix1, pix2); /* 9 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pix1 = pixTophat(pixs, WSIZE, HSIZE, L_TOPHAT_BLACK); sprintf(btophatseq, "Tb%d.%d", WSIZE, HSIZE); pix2 = pixGrayMorphSequence(pixs, btophatseq, 0, 500); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 10 */ regTestComparePix(rp, pix1, pix2); /* 11 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); /* ------------- Test erode/dilate duality -------------- */ pix1 = pixDilateGray(pixs, WSIZE, HSIZE); pix2 = pixInvert(NULL, pixs); pix3 = pixErodeGray(pix2, WSIZE, HSIZE); pixInvert(pix3, pix3); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 12 */ regTestComparePix(rp, pix1, pix3); /* 13 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); /* ------------- Test open/close duality -------------- */ pix1 = pixOpenGray(pixs, WSIZE, HSIZE); pix2 = pixInvert(NULL, pixs); pix3 = pixCloseGray(pix2, WSIZE, HSIZE); pixInvert(pix3, pix3); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 14 */ regTestComparePix(rp, pix1, pix3); /* 15 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); /* ------------- Test tophat duality -------------- */ pix1 = pixTophat(pixs, WSIZE, HSIZE, L_TOPHAT_WHITE); pix2 = pixInvert(NULL, pixs); pix3 = pixTophat(pix2, WSIZE, HSIZE, L_TOPHAT_BLACK); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 16 */ regTestComparePix(rp, pix1, pix3); /* 17 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); pix1 = pixGrayMorphSequence(pixs, "Tw9.5", 0, 100); pix2 = pixInvert(NULL, pixs); pix3 = pixGrayMorphSequence(pix2, "Tb9.5", 0, 300); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 18 */ regTestComparePix(rp, pix1, pix3); /* 19 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); /* ------------- Test opening/closing for large sels -------------- */ pix1 = pixGrayMorphSequence(pixs, "C9.9 + C19.19 + C29.29 + C39.39 + C49.49", 0, 100); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 20 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixGrayMorphSequence(pixs, "O9.9 + O19.19 + O29.29 + O39.39 + O49.49", 0, 400); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 21 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixaDisplayTiledInColumns(pixa, 4, 1.0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 22 */ pixDisplayWithTitle(pix1, 0, 0, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pix1); /* =========================================================== */ pixa = pixaCreate(0); /* ---------- Closing plus white tophat result ------------ * * Parameters: wsize, hsize = 9, 29 * * ---------------------------------------------------------*/ pix1 = pixCloseGray(pixs, 9, 9); pix2 = pixTophat(pix1, 9, 9, L_TOPHAT_WHITE); pix3 = pixGrayMorphSequence(pixs, "C9.9 + TW9.9", 0, 0); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 23 */ regTestComparePix(rp, pix2, pix3); /* 24 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixMaxDynamicRange(pix2, L_LINEAR_SCALE); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 25 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); pix1 = pixCloseGray(pixs, 29, 29); pix2 = pixTophat(pix1, 29, 29, L_TOPHAT_WHITE); pix3 = pixGrayMorphSequence(pixs, "C29.29 + Tw29.29", 0, 0); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 26 */ regTestComparePix(rp, pix2, pix3); /* 27 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = pixMaxDynamicRange(pix2, L_LINEAR_SCALE); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 28 */ pixaAddPix(pixa, pix1, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); /* --------- hdome with parameter height = 100 ------------*/ pix1 = pixHDome(pixs, 100, 4); pix2 = pixMaxDynamicRange(pix1, L_LINEAR_SCALE); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 29 */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 30 */ pixaAddPix(pixa, pix1, L_INSERT); pixaAddPix(pixa, pix2, L_INSERT); /* ----- Contrast enhancement with morph parameters 9, 9 -------*/ pixGetDimensions(pixs, &w, &h, NULL); pix1 = pixInitAccumulate(w, h, 0x8000); pixAccumulate(pix1, pixs, L_ARITH_ADD); pixMultConstAccumulate(pix1, 3., 0x8000); pix2 = pixOpenGray(pixs, 9, 9); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 31 */ pixaAddPix(pixa, pix2, L_INSERT); pixAccumulate(pix1, pix2, L_ARITH_SUBTRACT); pix2 = pixCloseGray(pixs, 9, 9); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 32 */ pixaAddPix(pixa, pix2, L_INSERT); pixAccumulate(pix1, pix2, L_ARITH_SUBTRACT); pix2 = pixFinalAccumulate(pix1, 0x8000, 8); regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 33 */ pixaAddPix(pixa, pix2, L_INSERT); pixDestroy(&pix1); /* Do the same thing with the Pixacc */ pacc = pixaccCreate(w, h, 1); pixaccAdd(pacc, pixs); pixaccMultConst(pacc, 3.); pix1 = pixOpenGray(pixs, 9, 9); pixaccSubtract(pacc, pix1); pixDestroy(&pix1); pix1 = pixCloseGray(pixs, 9, 9); pixaccSubtract(pacc, pix1); pixDestroy(&pix1); pix1 = pixaccFinal(pacc, 8); pixaccDestroy(&pacc); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 34 */ pixaAddPix(pixa, pix1, L_INSERT); regTestComparePix(rp, pix1, pix2); /* 35 */ pix1 = pixaDisplayTiledInColumns(pixa, 4, 1.0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 36 */ pixDisplayWithTitle(pix1, 1100, 0, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pix1); pixDestroy(&pixs); /* =========================================================== */ pixa = pixaCreate(0); /* ---- Tophat result on feynman stamp, to extract diagrams ----- */ pixs = pixRead("feynman-stamp.jpg"); pixGetDimensions(pixs, &w, &h, NULL); /* Make output image to hold five intermediate images */ pix1 = pixCreate(5 * w + 18, h + 6, 32); /* composite output image */ pixSetAllArbitrary(pix1, 0x0000ff00); /* set to blue */ /* Paste in the input image */ pix2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_FULL_COLOR); pixRasterop(pix1, 3, 3, w, h, PIX_SRC, pix2, 0, 0); /* 1st one */ regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 37 */ pixaAddPix(pixa, pix2, L_INSERT); /* Paste in the grayscale version */ cmap = pixGetColormap(pixs); if (cmap) pix2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE); else pix2 = pixConvertRGBToGray(pixs, 0.33, 0.34, 0.33); pix3 = pixConvertTo32(pix2); /* 8 --> 32 bpp */ pixRasterop(pix1, w + 6, 3, w, h, PIX_SRC, pix3, 0, 0); /* 2nd one */ regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 38 */ pixaAddPix(pixa, pix3, L_INSERT); /* Paste in a log dynamic range scaled version of the white tophat */ pix3 = pixTophat(pix2, 3, 3, L_TOPHAT_WHITE); pix4 = pixMaxDynamicRange(pix3, L_LOG_SCALE); pix5 = pixConvertTo32(pix4); pixRasterop(pix1, 2 * w + 9, 3, w, h, PIX_SRC, pix5, 0, 0); /* 3rd */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 39 */ pixaAddPix(pixa, pix5, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix4); /* Stretch the range and threshold to binary; paste it in */ pix2 = pixGammaTRC(NULL, pix3, 1.0, 0, 80); pix4 = pixThresholdToBinary(pix2, 70); pix5 = pixConvertTo32(pix4); pixRasterop(pix1, 3 * w + 12, 3, w, h, PIX_SRC, pix5, 0, 0); /* 4th */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 40 */ pixaAddPix(pixa, pix5, L_INSERT); pixDestroy(&pix2); pixDestroy(&pix3); /* Invert; this is the final result */ pixInvert(pix4, pix4); pix5 = pixConvertTo32(pix4); pixRasterop(pix1, 4 * w + 15, 3, w, h, PIX_SRC, pix5, 0, 0); /* 5th */ regTestWritePixAndCheck(rp, pix5, IFF_PNG); /* 41 */ pixaAddPix(pixa, pix5, L_INSERT); pixDestroy(&pix1); pixDestroy(&pix4); pix1 = pixaDisplayTiledInRows(pixa, 32, 1700, 1.0, 0, 20, 2); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 42 */ pixDisplayWithTitle(pix1, 0, 800, NULL, rp->display); pixaDestroy(&pixa); pixDestroy(&pix1); pixDestroy(&pixs); return regTestCleanup(rp); }