6 changes: 3 additions & 3 deletions prog/adaptmap_dark.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PIXAC *pixac1, *pixac2, *pixac3;
pixac3 = pixacompInterleave(pixac1, pixac2);
pixa2 = pixaCreateFromPixacomp(pixac3, L_CLONE);
pixa3 = pixaConvertToNUpPixa(pixa2, NULL, 1, 2, 1000, 6, 2, 0);
fprintf(stderr, "Time with pixac interleaving = %7.3f sec\n", stopTimer());
lept_stderr("Time with pixac interleaving = %7.3f sec\n", stopTimer());
L_INFO("Writing to /tmp/lept/adapt/cleaning2.pdf\n", procName);
pixaConvertToPdf(pixa3, 100, 1.0, L_JPEG_ENCODE,
75, "Adaptive cleaning", "/tmp/lept/adapt/cleaning2.pdf");
Expand All @@ -135,7 +135,7 @@ PIXAC *pixac1, *pixac2, *pixac3;
pixa2 = pixaCopy(pixa1, L_COPY_CLONE);
pixa3 = pixaInterleave(pixa1, pixa2, L_CLONE);
pixa4 = pixaConvertToNUpPixa(pixa3, NULL, 1, 2, 1000, 6, 2, 0);
fprintf(stderr, "Time with pixa interleaving = %7.3f sec\n", stopTimer());
lept_stderr("Time with pixa interleaving = %7.3f sec\n", stopTimer());
L_INFO("Writing to /tmp/lept/adapt/cleaning3.pdf\n", procName);
pixaConvertToPdf(pixa4, 100, 1.0, L_JPEG_ENCODE,
75, "Adaptive cleaning", "/tmp/lept/adapt/cleaning3.pdf");
Expand Down Expand Up @@ -166,7 +166,7 @@ PIX *pix1, *pix2, *pix3, *pix4, *pix5;

pix2 = pixBackgroundNorm(pix1, NULL, NULL, 10, 15, thresh, 25, 200, 2, 1);
snprintf(buf, sizeof(buf), "Norm color: fg thresh = %d", thresh);
fprintf(stderr, "%s\n", buf);
lept_stderr("%s\n", buf);
pix3 = pixAddTextlines(pix2, bmf, buf, 0x00ff0000, L_ADD_BELOW);
snprintf(buf, sizeof(buf), "/tmp/lept/adapt/adapt_%03d.jpg", index++);
pixWrite(buf, pix3, IFF_JFIF_JPEG);
Expand Down
53 changes: 45 additions & 8 deletions prog/adaptmap_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ L_REGPARAMS *rp;
pixRasterop(pixim, XS, YS, WS, HS, PIX_SET, NULL, 0, 0);
pixGetBackgroundGrayMap(pixg, pixim, SIZE_X, SIZE_Y,
BINTHRESH, MINCOUNT, &pixgm);
fprintf(stderr, "Time for gray adaptmap gen: %7.3f\n", stopTimer());
lept_stderr("Time for gray adaptmap gen: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pixgm, IFF_PNG); /* 0 */
pixaAddPix(pixa, pixgm, L_INSERT);

startTimer();
pixmi = pixGetInvBackgroundMap(pixgm, BGVAL, SMOOTH_X, SMOOTH_Y);
fprintf(stderr, "Time for gray inv map generation: %7.3f\n", stopTimer());
lept_stderr("Time for gray inv map generation: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pixmi, IFF_PNG); /* 1 */
pixaAddPix(pixa, pixmi, L_INSERT);

startTimer();
pix1 = pixApplyInvBackgroundGrayMap(pixg, pixmi, SIZE_X, SIZE_Y);
fprintf(stderr, "Time to apply gray inv map: %7.3f\n", stopTimer());
lept_stderr("Time to apply gray inv map: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 2 */
pixaAddPix(pixa, pix1, L_INSERT);

Expand All @@ -108,7 +108,7 @@ L_REGPARAMS *rp;
pixGetBackgroundRGBMap(pixs, pixim, NULL, SIZE_X, SIZE_Y,
BINTHRESH, MINCOUNT,
&pixmr, &pixmg, &pixmb);
fprintf(stderr, "Time for color adaptmap gen: %7.3f\n", stopTimer());
lept_stderr("Time for color adaptmap gen: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pixmr, IFF_PNG); /* 4 */
regTestWritePixAndCheck(rp, pixmg, IFF_PNG); /* 5 */
regTestWritePixAndCheck(rp, pixmb, IFF_PNG); /* 6 */
Expand All @@ -120,7 +120,7 @@ L_REGPARAMS *rp;
pixmri = pixGetInvBackgroundMap(pixmr, BGVAL, SMOOTH_X, SMOOTH_Y);
pixmgi = pixGetInvBackgroundMap(pixmg, BGVAL, SMOOTH_X, SMOOTH_Y);
pixmbi = pixGetInvBackgroundMap(pixmb, BGVAL, SMOOTH_X, SMOOTH_Y);
fprintf(stderr, "Time for color inv map generation: %7.3f\n", stopTimer());
lept_stderr("Time for color inv map generation: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pixmri, IFF_PNG); /* 7 */
regTestWritePixAndCheck(rp, pixmgi, IFF_PNG); /* 8 */
regTestWritePixAndCheck(rp, pixmbi, IFF_PNG); /* 9 */
Expand All @@ -131,7 +131,7 @@ L_REGPARAMS *rp;
startTimer();
pix1 = pixApplyInvBackgroundRGBMap(pixs, pixmri, pixmgi, pixmbi,
SIZE_X, SIZE_Y);
fprintf(stderr, "Time to apply color inv maps: %7.3f\n", stopTimer());
lept_stderr("Time to apply color inv maps: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 10 */
pixaAddPix(pixa, pix1, L_INSERT);

Expand All @@ -148,7 +148,7 @@ L_REGPARAMS *rp;
pixRasterop(pixim, XS, YS, WS, HS, PIX_SET, NULL, 0, 0);
pix1 = pixBackgroundNorm(pixs, pixim, NULL, 5, 10, BINTHRESH, 20,
BGVAL, SMOOTH_X, SMOOTH_Y);
fprintf(stderr, "Time for bg normalization: %7.3f\n", stopTimer());
lept_stderr("Time for bg normalization: %7.3f\n", stopTimer());
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 12 */
pixaAddPix(pixa, pix1, L_INSERT);

Expand All @@ -162,10 +162,47 @@ L_REGPARAMS *rp;
/* Display results */
pix1 = pixaDisplayTiledAndScaled(pixa, 32, 400, 4, 0, 20, 2);
pixWrite("/tmp/lept/adapt/results.jpg", pix1, IFF_JFIF_JPEG);
pixDisplayWithTitle(pix1, 100, 0, NULL, rp->display);
pixDisplayWithTitle(pix1, 50, 0, NULL, rp->display);
pixDestroy(&pix1);
pixaDestroy(&pixa);

/* Check pixFillMapHoles() */
pixa = pixaCreate(3);
pix1 = pixRead("weasel8.png"); /* use this as the map */
pixGammaTRC(pix1, pix1, 1.0, 0, 270); /* darken white pixels */
pixaAddPix(pixa, pix1, L_COPY);
pixGetDimensions(pix1, &w, &h, NULL);
pixRasterop(pix1, 0, 0, 5, h, PIX_SET, NULL, 0, 0); /* add white holes */
pixRasterop(pix1, 20, 0, 2, h, PIX_SET, NULL, 0, 0);
pixRasterop(pix1, 40, 0, 3, h, PIX_SET, NULL, 0, 0);
pixRasterop(pix1, 0, 0, w, 3, PIX_SET, NULL, 0, 0);
pixRasterop(pix1, 0, 15, w, 3, PIX_SET, NULL, 0, 0);
pixRasterop(pix1, 0, 35, w, 2, PIX_SET, NULL, 0, 0);
pixaAddPix(pixa, pix1, L_COPY);
pixFillMapHoles(pix1, w, h, L_FILL_WHITE);
pixaAddPix(pixa, pix1, L_INSERT);
pix2 = pixaDisplayTiledInColumns(pixa, 3, 1.0, 20, 1);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 14 */
pixDisplayWithTitle(pix2, 50, 850, NULL, rp->display);
pixaDestroy(&pixa);
pixDestroy(&pix2);

/* An even simpler check of pixFillMapHoles() */
pixa = pixaCreate(2);
pix1 = pixCreate(3, 3, 8);
pixSetPixel(pix1, 1, 0, 128);
pix2 = pixExpandReplicate(pix1, 25);
pixaAddPix(pixa, pix2, L_INSERT);
pixFillMapHoles(pix1, 3, 3, L_FILL_BLACK);
pix2 = pixExpandReplicate(pix1, 25);
pixaAddPix(pixa, pix2, L_INSERT);
pixDestroy(&pix1);
pix1 = pixaDisplayTiledInColumns(pixa, 2, 1.0, 20, 0);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 15 */
pixDisplayWithTitle(pix1, 50, 1000, NULL, rp->display);
pixaDestroy(&pixa);
pixDestroy(&pix1);

return regTestCleanup(rp);
}

4 changes: 2 additions & 2 deletions prog/adaptnorm_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ L_REGPARAMS *rp;
startTimer();
pix1 = pixContrastNorm(NULL, pixs, 10, 10, 40, 2, 2);
mps = 0.000001 * w * h / stopTimer();
fprintf(stderr, "Time: Contrast norm: %7.3f Mpix/sec\n", mps);
lept_stderr("Time: Contrast norm: %7.3f Mpix/sec\n", mps);
pixaAddPix(pixa1, pix1, L_INSERT);
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 1 */

Expand Down Expand Up @@ -106,7 +106,7 @@ L_REGPARAMS *rp;
startTimer();
pix1 = pixBackgroundNormFlex(pixs, 7, 7, 1, 1, 10);
mps = 0.000001 * w * h / stopTimer();
fprintf(stderr, "Time: Flexible bg norm: %7.3f Mpix/sec\n", mps);
lept_stderr("Time: Flexible bg norm: %7.3f Mpix/sec\n", mps);
pixaAddPix(pixa1, pix1, L_INSERT);
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 9 */

Expand Down
34 changes: 17 additions & 17 deletions prog/affine_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of sequential. */
fprintf(stderr, "Test invertability of sequential\n");
lept_stderr("Test invertability of sequential\n");
pixa = pixaCreate(0);
for (i = 0; i < 3; i++) {
pixb = pixAddBorder(pixs, ADDED_BORDER_PIXELS, 0);
Expand Down Expand Up @@ -122,7 +122,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of sampling */
fprintf(stderr, "Test invertability of sampling\n");
lept_stderr("Test invertability of sampling\n");
pixa = pixaCreate(0);
for (i = 0; i < 3; i++) {
pixb = pixAddBorder(pixs, ADDED_BORDER_PIXELS, 0);
Expand Down Expand Up @@ -154,7 +154,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of interpolation on grayscale */
fprintf(stderr, "Test invertability of grayscale interpolation\n");
lept_stderr("Test invertability of grayscale interpolation\n");
pix = pixRead("feyn.tif");
pixg = pixScaleToGray3(pix);
pixDestroy(&pix);
Expand Down Expand Up @@ -190,7 +190,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of interpolation on color */
fprintf(stderr, "Test invertability of color interpolation\n");
lept_stderr("Test invertability of color interpolation\n");
pixa = pixaCreate(0);
pixc = pixRead("test24.jpg");
pixcs = pixScale(pixc, 0.3, 0.3);
Expand Down Expand Up @@ -225,7 +225,7 @@ L_REGPARAMS *rp;

#if ALL
/* Comparison between sequential and sampling */
fprintf(stderr, "Compare sequential with sampling\n");
lept_stderr("Compare sequential with sampling\n");
pix = pixRead("feyn.tif");
pixs = pixScale(pix, 0.22, 0.22);
pixDestroy(&pix);
Expand Down Expand Up @@ -264,7 +264,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test with large distortion */
fprintf(stderr, "Test with large distortion\n");
lept_stderr("Test with large distortion\n");
MakePtas(4, &ptas, &ptad);
pixa = pixaCreate(0);
pix = pixRead("feyn.tif");
Expand Down Expand Up @@ -306,7 +306,7 @@ L_REGPARAMS *rp;

#if ALL
/* Set up pix and boxa */
fprintf(stderr, "Test affine transforms and inverses on pix and boxa\n");
lept_stderr("Test affine transforms and inverses on pix and boxa\n");
pixa = pixaCreate(0);
pix = pixRead("lucasta.1.300.tif");
pixTranslate(pix, pix, 70, 0, L_BRING_IN_WHITE);
Expand Down Expand Up @@ -338,22 +338,22 @@ L_REGPARAMS *rp;
/* Invert the original affine transform --> matdinv */
affineInvertXform(matd, &matdinv);
if (rp->display) {
fprintf(stderr, " Affine transform, applied to boxa\n");
lept_stderr(" Affine transform, applied to boxa\n");
for (i = 0; i < 9; i++) {
if (i && (i % 3 == 0)) fprintf(stderr, "\n");
fprintf(stderr, " %7.3f ", matd[i]);
if (i && (i % 3 == 0)) lept_stderr("\n");
lept_stderr(" %7.3f ", matd[i]);
}
fprintf(stderr, "\n Inverse transform, by composing inverse parts");
lept_stderr("\n Inverse transform, by composing inverse parts");
for (i = 0; i < 9; i++) {
if (i % 3 == 0) fprintf(stderr, "\n");
fprintf(stderr, " %7.3f ", matdi[i]);
if (i % 3 == 0) lept_stderr("\n");
lept_stderr(" %7.3f ", matdi[i]);
}
fprintf(stderr, "\n Inverse transform, by inverting affine xform");
lept_stderr("\n Inverse transform, by inverting affine xform");
for (i = 0; i < 6; i++) {
if (i % 3 == 0) fprintf(stderr, "\n");
fprintf(stderr, " %7.3f ", matdinv[i]);
if (i % 3 == 0) lept_stderr("\n");
lept_stderr(" %7.3f ", matdinv[i]);
}
fprintf(stderr, "\n");
lept_stderr("\n");
}

/* Apply the inverted affine transform --> pixs */
Expand Down
13 changes: 9 additions & 4 deletions prog/alltests_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ static const char *tests[] = {
"boxa3_reg",
"boxa4_reg",
"bytea_reg",
"ccbord_reg",
"ccthin1_reg",
"ccthin2_reg",
"checkerboard_reg",
"circle_reg",
"cmapquant_reg",
"colorcontent_reg",
"colorfill_reg",
"coloring_reg",
"colorize_reg",
"colormask_reg",
Expand All @@ -89,6 +92,7 @@ static const char *tests[] = {
"conncomp_reg",
"conversion_reg",
"convolve_reg",
"crop_reg",
"dewarp_reg",
"distance_reg",
"dither_reg",
Expand All @@ -115,6 +119,7 @@ static const char *tests[] = {
"graymorph2_reg",
"grayquant_reg",
"hardlight_reg",
"hash_reg",
"heap_reg",
"insert_reg",
"ioformats_reg",
Expand Down Expand Up @@ -218,7 +223,7 @@ static char mainName[] = "alltests_reg";
setLeptDebugOK(1); /* required for testing */
l_getCurrentTime(&start, NULL);
ntests = sizeof(tests) / sizeof(char *);
fprintf(stderr, "Running alltests_reg:\n"
lept_stderr("Running alltests_reg:\n"
"This currently tests %d regression test\n"
"programs in the /prog directory.\n", ntests);

Expand Down Expand Up @@ -252,7 +257,7 @@ static char mainName[] = "alltests_reg";
nfail++;
}
else
fprintf(stderr, "%s", buf);
lept_stderr("%s", buf);
}
}

Expand All @@ -264,11 +269,11 @@ static char mainName[] = "alltests_reg";
#endif /* !_WIN32 */
lept_free(results_file);
ret = system(command);
fprintf(stderr, "Success in %d of %d *_reg programs (output matches"
lept_stderr("Success in %d of %d *_reg programs (output matches"
" the \"golden\" files)\n", ntests - nfail, ntests);
}

l_getCurrentTime(&stop, NULL);
fprintf(stderr, "Time for all regression tests: %d sec\n", stop - start);
lept_stderr("Time for all regression tests: %d sec\n", stop - start);
return 0;
}
2 changes: 1 addition & 1 deletion prog/alphaops_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ L_REGPARAMS *rp;
pix2 = pixRead("/tmp/lept/alpha/cs2.png"); /* cleaned under transparent */
n1 = nbytesInFile("/tmp/lept/alpha/cs1.png");
n2 = nbytesInFile("/tmp/lept/alpha/cs2.png");
fprintf(stderr, " Original: %d bytes\n Cleaned: %d bytes\n", n1, n2);
lept_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);
Expand Down
7 changes: 3 additions & 4 deletions prog/arabic_lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static char mainName[] = "arabic_lines";
/* Deskew */
pixb = pixFindSkewAndDeskew(pix, 1, &angle, &conf);
pixDestroy(&pix);
fprintf(stderr, "Skew angle: %7.2f degrees; %6.2f conf\n", angle, conf);
lept_stderr("Skew angle: %7.2f degrees; %6.2f conf\n", angle, conf);
pixaAddPix(pixa, pixb, L_INSERT);

/* Use full image morphology to find columns, at 2x reduction.
Expand All @@ -102,7 +102,7 @@ static char mainName[] = "arabic_lines";
pix1 = pixMorphCompSequence(pixb2, "c5.500 + o20.20", 0);
boxa1 = pixConnComp(pix1, &pixam, 8);
ncols = boxaGetCount(boxa1);
fprintf(stderr, "Num columns: %d\n", ncols);
lept_stderr("Num columns: %d\n", ncols);
pixaAddPix(pixa, pix1, L_INSERT);
boxaDestroy(&boxa1);

Expand All @@ -128,8 +128,7 @@ static char mainName[] = "arabic_lines";
pixaaAddBox(pixaa, box, L_INSERT);
pix4 = pixaDisplayRandomCmap(pixa1, 0, 0);
pixaAddPix(pixa, pix4, L_INSERT);
fprintf(stderr, "Num textlines in col %d: %d\n", i,
boxaGetCount(boxa2));
lept_stderr("Num textlines in col %d: %d\n", i, boxaGetCount(boxa2));
pixDestroy(&pix2);
pixDestroy(&pix3);
boxaDestroy(&boxa2);
Expand Down
4 changes: 2 additions & 2 deletions prog/autogentest2.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ PIXA *pixa;
pixaWrite("/tmp/lept/auto/junkpa.pa", pixa);
filesAreIdentical("/tmp/lept/auto/junkpa.pa", files[i], &same);
if (same)
fprintf(stderr, "Files are the same for %s\n", files[i]);
lept_stderr("Files are the same for %s\n", files[i]);
else
fprintf(stderr, "Error: files are different for %s\n", files[i]);
lept_stderr("Error: files are different for %s\n", files[i]);
pixaDestroy(&pixa);
}

Expand Down
10 changes: 5 additions & 5 deletions prog/bilinear_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test non-invertability of sampling */
fprintf(stderr, "Test invertability of sampling\n");
lept_stderr("Test invertability of sampling\n");
pixa = pixaCreate(0);
for (i = 1; i < 3; i++) {
pixb = pixAddBorder(pixg, ADDED_BORDER_PIXELS, 255);
Expand Down Expand Up @@ -110,7 +110,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of grayscale interpolation */
fprintf(stderr, "Test invertability of grayscale interpolation\n");
lept_stderr("Test invertability of grayscale interpolation\n");
pixa = pixaCreate(0);
for (i = 1; i < 3; i++) {
pixb = pixAddBorder(pixg, ADDED_BORDER_PIXELS, 255);
Expand Down Expand Up @@ -140,7 +140,7 @@ L_REGPARAMS *rp;

#if ALL
/* Test invertability of color interpolation */
fprintf(stderr, "Test invertability of color interpolation\n");
lept_stderr("Test invertability of color interpolation\n");
pixa = pixaCreate(0);
pixc = pixRead("test24.jpg");
pixcs = pixScale(pixc, 0.3, 0.3);
Expand Down Expand Up @@ -174,7 +174,7 @@ L_REGPARAMS *rp;

#if ALL
/* Comparison between sampling and interpolated */
fprintf(stderr, "Compare sampling with interpolated\n");
lept_stderr("Compare sampling with interpolated\n");
MakePtas(2, &ptas, &ptad);
pixa = pixaCreate(0);

Expand Down Expand Up @@ -206,7 +206,7 @@ L_REGPARAMS *rp;

#if ALL
/* Large distortion with inversion */
fprintf(stderr, "Large bilinear distortion with inversion\n");
lept_stderr("Large bilinear distortion with inversion\n");
MakePtas(0, &ptas, &ptad);
pixa = pixaCreate(0);
pixs = pixRead("marge.jpg");
Expand Down
8 changes: 4 additions & 4 deletions prog/binarize_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ PIXA *pixa;
/* Get speed */
startTimer();
pixSauvolaBinarize(pixs, size, factor, 1, NULL, NULL, NULL, &pixd);
fprintf(stderr, "\nSpeed: 1 tile, %7.3f Mpix/sec\n",
(w * h / 1000000.) / stopTimer());
lept_stderr("\nSpeed: 1 tile, %7.3f Mpix/sec\n",
(w * h / 1000000.) / stopTimer());
pixDestroy(&pixd);

/* Get results */
Expand Down Expand Up @@ -137,8 +137,8 @@ PIXA *pixa;
/* Get speed */
startTimer();
pixSauvolaBinarizeTiled(pixs, size, factor, nx, ny, NULL, &pixd);
fprintf(stderr, "Speed: %d x %d tiles, %7.3f Mpix/sec\n",
nx, ny, (w * h / 1000000.) / stopTimer());
lept_stderr("Speed: %d x %d tiles, %7.3f Mpix/sec\n",
nx, ny, (w * h / 1000000.) / stopTimer());
pixDestroy(&pixd);

/* Get results */
Expand Down
6 changes: 3 additions & 3 deletions prog/binarize_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static char mainName[] = "binarize_set";
pixg = pixConvertTo8(pixs, 0);
pix1 = pixOtsuThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 255, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
lept_stderr("thresh val = %d\n", threshval);
pixaAddPix(pixa, pix1, L_INSERT);
pixWrite("/tmp/lept/binar/binar2.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 200);
Expand All @@ -118,7 +118,7 @@ static char mainName[] = "binarize_set";
pixg = pixConvertTo8(pixs, 0);
pix1 = pixMaskedThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
lept_stderr("thresh val = %d\n", threshval);
pixaAddPix(pixa, pix1, L_INSERT);
pixWrite("/tmp/lept/binar/binar3.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 400);
Expand Down Expand Up @@ -152,7 +152,7 @@ static char mainName[] = "binarize_set";
pixGetPixel(pix1, 0, 0, &val);
ival = (l_int32)val;
newval = ival + (l_int32)(0.6 * (110 - ival));
fprintf(stderr, "th1 = %d, th2 = %d\n", ival, newval);
lept_stderr("th1 = %d, th2 = %d\n", ival, newval);
pixDestroy(&pix1);

pixContrastNorm(pixg, pixg, 50, 50, 130, 2, 2);
Expand Down
6 changes: 3 additions & 3 deletions prog/binarizefiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SARRAY *sa;
static char mainName[] = "binarizefiles.c";

if (argc != 6) {
fprintf(stderr,
lept_stderr(
"Syntax: binarizefiles dirin pattern thresh scalefact dirout\n"
" dirin: input directory for image files\n"
" pattern: use 'allfiles' to convert all files\n"
Expand Down Expand Up @@ -84,7 +84,7 @@ static char mainName[] = "binarizefiles.c";

/* Write the output files */
makeTempDirname(dirname, 256, subdirout);
fprintf(stderr, "dirname: %s\n", dirname);
lept_stderr("dirname: %s\n", dirname);
lept_mkdir(subdirout);
for (i = 0; i < n; i++) {
fname = sarrayGetString(sa, i, L_NOCOPY);
Expand All @@ -97,7 +97,7 @@ static char mainName[] = "binarizefiles.c";
snprintf(buf, sizeof(buf), "%s/%s.tif", dirname, basename);
lept_free(tail);
lept_free(basename);
fprintf(stderr, "fileout: %s\n", buf);
lept_stderr("fileout: %s\n", buf);
if (scalefactor != 1.0)
pix2 = pixScale(pix1, scalefactor, scalefactor);
else
Expand Down
18 changes: 9 additions & 9 deletions prog/bincompare.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ static char mainName[] = "bincompare";
return ERROR_INT("pixs1 not binary", mainName, 1);

pixCountPixels(pixs1, &n, NULL);
fprintf(stderr, "Number of fg pixels in file1 = %d\n", n);
lept_stderr("Number of fg pixels in file1 = %d\n", n);
pixCountPixels(pixs2, &n, NULL);
fprintf(stderr, "Number of fg pixels in file2 = %d\n", n);
lept_stderr("Number of fg pixels in file2 = %d\n", n);

#if XOR
fprintf(stderr, "xor: 1 ^ 2\n");
lept_stderr("xor: 1 ^ 2\n");
pixRasterop(pixs1, 0, 0, w, h, PIX_SRC ^ PIX_DST, pixs2, 0, 0);
pixCountPixels(pixs1, &n, NULL);
fprintf(stderr, "Number of fg pixels in XOR = %d\n", n);
lept_stderr("Number of fg pixels in XOR = %d\n", n);
pixWrite(fileout, pixs1, IFF_PNG);
#elif SUBTRACT_1_FROM_2
fprintf(stderr, "subtract: 2 - 1\n");
lept_stderr("subtract: 2 - 1\n");
pixRasterop(pixs1, 0, 0, w, h, PIX_SRC & PIX_NOT(PIX_DST), pixs2, 0, 0);
pixCountPixels(pixs1, &n, NULL);
fprintf(stderr, "Number of fg pixels in 2 - 1 = %d\n", n);
lept_stderr("Number of fg pixels in 2 - 1 = %d\n", n);
pixWrite(fileout, pixs1, IFF_PNG);
#elif SUBTRACT_2_FROM_1
fprintf(stderr, "subtract: 1 - 2\n");
lept_stderr("subtract: 1 - 2\n");
pixRasterop(pixs1, 0, 0, w, h, PIX_DST & PIX_NOT(PIX_SRC), pixs2, 0, 0);
pixCountPixels(pixs1, &n, NULL);
fprintf(stderr, "Number of fg pixels in 1 - 2 = %d\n", n);
lept_stderr("Number of fg pixels in 1 - 2 = %d\n", n);
pixWrite(fileout, pixs1, IFF_PNG);
#else
fprintf(stderr, "no comparison selected\n");
lept_stderr("no comparison selected\n");
#endif

return 0;
Expand Down
140 changes: 70 additions & 70 deletions prog/binmorph1_reg.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions prog/binmorph2_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static char mainName[] = "binmorph2_reg";
/* Check if the size is exactly decomposable */
selectComposableSizes(i, &factor1, &factor2);
diff = factor1 * factor2 - i;
fprintf(stderr, "%d: (%d, %d): %d\n", i, factor1, factor2, diff);
lept_stderr("%d: (%d, %d): %d\n", i, factor1, factor2, diff);

/* Carry out operations on identical sized Sels: dilation */
snprintf(buffer1, sizeof(buffer1), "d%d.%d", i + diff, i + diff);
Expand Down Expand Up @@ -164,9 +164,9 @@ static char mainName[] = "binmorph2_reg";
pixDestroy(&pixsd);

if (success)
fprintf(stderr, "\n---------- Success: no errors ----------\n");
lept_stderr("\n---------- Success: no errors ----------\n");
else
fprintf(stderr, "\n---------- Failure: error(s) found -----------\n");
lept_stderr("\n---------- Failure: error(s) found -----------\n");
return 0;
}

Expand All @@ -175,17 +175,17 @@ static void writeResult(const char *sequence,
l_int32 same)
{
if (same)
fprintf(stderr, "Sequence %s: SUCCESS\n", sequence);
lept_stderr("Sequence %s: SUCCESS\n", sequence);
else
fprintf(stderr, "Sequence %s: FAILURE\n", sequence);
lept_stderr("Sequence %s: FAILURE\n", sequence);
}


#if 0
for (i = 1; i < 400; i++) {
selectComposableSizes(i, &factor1, &factor2);
diff = factor1 * factor2 - i;
fprintf(stderr, "%d: (%d, %d): %d\n",
lept_stderr("%d: (%d, %d): %d\n",
i, factor1, factor2, diff);
selectComposableSels(i, L_HORIZ, &sel1, &sel2);
selDestroy(&sel1);
Expand All @@ -196,27 +196,27 @@ static void writeResult(const char *sequence,
#if 0
selectComposableSels(68, L_HORIZ, &sel1, &sel2); /* 17, 4 */
str = selPrintToString(sel2);
fprintf(stderr, str);
lept_stderr(str);
selDestroy(&sel1);
selDestroy(&sel2);
lept_free(str);
selectComposableSels(70, L_HORIZ, &sel1, &sel2); /* 10, 7 */
str = selPrintToString(sel2);
selDestroy(&sel1);
selDestroy(&sel2);
fprintf(stderr, str);
lept_stderr(str);
lept_free(str);
selectComposableSels(85, L_HORIZ, &sel1, &sel2); /* 17, 5 */
str = selPrintToString(sel2);
selDestroy(&sel1);
selDestroy(&sel2);
fprintf(stderr, str);
lept_stderr(str);
lept_free(str);
selectComposableSels(96, L_HORIZ, &sel1, &sel2); /* 12, 8 */
str = selPrintToString(sel2);
selDestroy(&sel1);
selDestroy(&sel2);
fprintf(stderr, str);
lept_stderr(str);
lept_free(str);

{ SELA *sela;
Expand Down
52 changes: 26 additions & 26 deletions prog/binmorph3_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ SELA *sela;

if (symmetric) {
resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
fprintf(stderr, "Testing with symmetric boundary conditions\n"
"==========================================\n");
lept_stderr("Testing with symmetric boundary conditions\n"
"==========================================\n");
} else {
resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
fprintf(stderr, "Testing with asymmetric boundary conditions\n"
"==========================================\n");
lept_stderr("Testing with asymmetric boundary conditions\n"
"==========================================\n");
}

for (i = 0; i < 3; i++) {
Expand All @@ -118,18 +118,18 @@ SELA *sela;
return ERROR_INT("dwa vert sel not defined", rp->testname, 1);
}
}
fprintf(stderr, "w = %d, h = %d, selh = %s, selv = %s\n",
lept_stderr("w = %d, h = %d, selh = %s, selv = %s\n",
w, h, selnameh, selnamev);
ok = TRUE;
selaDestroy(&sela);

/* ----------------- Dilation ----------------- */
fprintf(stderr, "Testing dilation\n");
lept_stderr("Testing dilation\n");
pixref = pixDilate(NULL, pixs, sel);
pix1 = pixDilateBrickDwa(NULL, pixs, w, h);
pixEqual(pixref, pix1, &same);
if (!same) {
fprintf(stderr, "pixref != pix1 !\n"); ok = FALSE;
lept_stderr("pixref != pix1 !\n"); ok = FALSE;
}
pixDestroy(&pix1);

Expand All @@ -143,7 +143,7 @@ SELA *sela;
pix2 = pixClone(pix1);
pixEqual(pixref, pix2, &same);
if (!same) {
fprintf(stderr, "pixref != pix2 !\n"); ok = FALSE;
lept_stderr("pixref != pix2 !\n"); ok = FALSE;
}
pixDestroy(&pix1);
pixDestroy(&pix2);
Expand All @@ -160,7 +160,7 @@ SELA *sela;
pix4 = pixRemoveBorder(pix3, 32);
pixEqual(pixref, pix4, &same);
if (!same) {
fprintf(stderr, "pixref != pix4 !\n"); ok = FALSE;
lept_stderr("pixref != pix4 !\n"); ok = FALSE;
}
pixDestroy(&pixref);
pixDestroy(&pix1);
Expand All @@ -169,12 +169,12 @@ SELA *sela;
pixDestroy(&pix4);

/* ----------------- Erosion ----------------- */
fprintf(stderr, "Testing erosion\n");
lept_stderr("Testing erosion\n");
pixref = pixErode(NULL, pixs, sel);
pix1 = pixErodeBrickDwa(NULL, pixs, w, h);
pixEqual(pixref, pix1, &same);
if (!same) {
fprintf(stderr, "pixref != pix1 !\n"); ok = FALSE;
lept_stderr("pixref != pix1 !\n"); ok = FALSE;
}
pixDestroy(&pix1);

Expand All @@ -188,7 +188,7 @@ SELA *sela;
pix2 = pixClone(pix1);
pixEqual(pixref, pix2, &same);
if (!same) {
fprintf(stderr, "pixref != pix2 !\n"); ok = FALSE;
lept_stderr("pixref != pix2 !\n"); ok = FALSE;
}
pixDestroy(&pix1);
pixDestroy(&pix2);
Expand All @@ -205,7 +205,7 @@ SELA *sela;
pix4 = pixRemoveBorder(pix3, 32);
pixEqual(pixref, pix4, &same);
if (!same) {
fprintf(stderr, "pixref != pix4 !\n"); ok = FALSE;
lept_stderr("pixref != pix4 !\n"); ok = FALSE;
}
pixDestroy(&pixref);
pixDestroy(&pix1);
Expand All @@ -214,12 +214,12 @@ SELA *sela;
pixDestroy(&pix4);

/* ----------------- Opening ----------------- */
fprintf(stderr, "Testing opening\n");
lept_stderr("Testing opening\n");
pixref = pixOpen(NULL, pixs, sel);
pix1 = pixOpenBrickDwa(NULL, pixs, w, h);
pixEqual(pixref, pix1, &same);
if (!same) {
fprintf(stderr, "pixref != pix1 !\n"); ok = FALSE;
lept_stderr("pixref != pix1 !\n"); ok = FALSE;
}
pixDestroy(&pix1);

Expand All @@ -236,7 +236,7 @@ SELA *sela;
}
pixEqual(pixref, pix2, &same);
if (!same) {
fprintf(stderr, "pixref != pix2 !\n"); ok = FALSE;
lept_stderr("pixref != pix2 !\n"); ok = FALSE;
}
pixDestroy(&pix2);

Expand All @@ -255,15 +255,15 @@ SELA *sela;
pix4 = pixRemoveBorder(pix3, 32);
pixEqual(pixref, pix4, &same);
if (!same) {
fprintf(stderr, "pixref != pix4 !\n"); ok = FALSE;
lept_stderr("pixref != pix4 !\n"); ok = FALSE;
}
pixDestroy(&pixref);
pixDestroy(&pix1);
pixDestroy(&pix3);
pixDestroy(&pix4);

/* ----------------- Closing ----------------- */
fprintf(stderr, "Testing closing\n");
lept_stderr("Testing closing\n");
pixref = pixClose(NULL, pixs, sel);

/* Note: L_MORPH_CLOSE for h==1 or w==1 gives safe closing,
Expand All @@ -285,7 +285,7 @@ SELA *sela;
pixDestroy(&pix1);
pixEqual(pixref, pix2, &same);
if (!same) {
fprintf(stderr, "pixref != pix2 !\n"); ok = FALSE;
lept_stderr("pixref != pix2 !\n"); ok = FALSE;
}
pixDestroy(&pix2);

Expand All @@ -308,27 +308,27 @@ SELA *sela;
pix4 = pixRemoveBorder(pix3, 32);
pixEqual(pixref, pix4, &same);
if (!same) {
fprintf(stderr, "pixref != pix4 !\n"); ok = FALSE;
lept_stderr("pixref != pix4 !\n"); ok = FALSE;
}
pixDestroy(&pixref);
pixDestroy(&pix1);
pixDestroy(&pix3);
pixDestroy(&pix4);

/* ------------- Safe Closing ----------------- */
fprintf(stderr, "Testing safe closing\n");
lept_stderr("Testing safe closing\n");
pixref = pixCloseSafe(NULL, pixs, sel);
pix0 = pixCloseSafeBrick(NULL, pixs, w, h);
pixEqual(pixref, pix0, &same);
if (!same) {
fprintf(stderr, "pixref != pix0 !\n"); ok = FALSE;
lept_stderr("pixref != pix0 !\n"); ok = FALSE;
}
pixDestroy(&pix0);

pix1 = pixCloseBrickDwa(NULL, pixs, w, h);
pixEqual(pixref, pix1, &same);
if (!same) {
fprintf(stderr, "pixref != pix1 !\n"); ok = FALSE;
lept_stderr("pixref != pix1 !\n"); ok = FALSE;
}
pixDestroy(&pix1);

Expand Down Expand Up @@ -365,7 +365,7 @@ SELA *sela;
}
pixEqual(pixref, pix3, &same);
if (!same) {
fprintf(stderr, "pixref != pix3 !\n"); ok = FALSE;
lept_stderr("pixref != pix3 !\n"); ok = FALSE;
}
pixDestroy(&pix3);

Expand All @@ -384,7 +384,7 @@ SELA *sela;
pix4 = pixRemoveBorder(pix3, 32 + extraborder);
pixEqual(pixref, pix4, &same);
if (!same) {
fprintf(stderr, "pixref != pix4 !\n"); ok = FALSE;
lept_stderr("pixref != pix4 !\n"); ok = FALSE;
}
pixDestroy(&pixref);
pixDestroy(&pix1);
Expand All @@ -393,7 +393,7 @@ SELA *sela;

regTestCompareValues(rp, TRUE, ok, 0);
if (ok)
fprintf(stderr, "All morph tests OK!\n\n");
lept_stderr("All morph tests OK!\n\n");
selDestroy(&sel);
lept_free(selnameh);
lept_free(selnamev);
Expand Down
102 changes: 51 additions & 51 deletions prog/binmorph4_reg.c

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions prog/binmorph5_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6;
resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
pix1 = pixAddBorder(pixs, 128, 0);
pixTransferAllData(pixs, &pix1, 0, 0);
fprintf(stderr, "Testing with symmetric boundary conditions\n");
lept_stderr("Testing with symmetric boundary conditions\n");
} else {
resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
fprintf(stderr, "Testing with asymmetric boundary conditions\n");
lept_stderr("Testing with asymmetric boundary conditions\n");
}

pix1 = pixCreateTemplateNoInit(pixs);
Expand Down Expand Up @@ -155,7 +155,7 @@ PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6;
}
#endif /* SLOWER_TEST */

fprintf(stderr, "\n");
lept_stderr("\n");
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
Expand All @@ -181,54 +181,54 @@ l_int32 fact1, fact2, size;
selectComposableSizes(isize, &fact1, &fact2);
size = fact1 * fact2;

fprintf(stderr, "..%d..", size);
lept_stderr("..%d..", size);

if (TIMING) startTimer();
pixDilateCompBrickExtendDwa(pix1, pixs, size, 1);
pixDilateCompBrickExtendDwa(pix3, pixs, 1, size);
pixDilateCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixDilateCompBrick(pix2, pixs, size, 1);
pixDilateCompBrick(pix4, pixs, 1, size);
pixDilateCompBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "dilate", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixErodeCompBrickExtendDwa(pix1, pixs, size, 1);
pixErodeCompBrickExtendDwa(pix3, pixs, 1, size);
pixErodeCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixErodeCompBrick(pix2, pixs, size, 1);
pixErodeCompBrick(pix4, pixs, 1, size);
pixErodeCompBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "erode", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixOpenCompBrickExtendDwa(pix1, pixs, size, 1);
pixOpenCompBrickExtendDwa(pix3, pixs, 1, size);
pixOpenCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixOpenCompBrick(pix2, pixs, size, 1);
pixOpenCompBrick(pix4, pixs, 1, size);
pixOpenCompBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "open", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixCloseCompBrickExtendDwa(pix1, pixs, size, 1);
pixCloseCompBrickExtendDwa(pix3, pixs, 1, size);
pixCloseCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixCloseSafeCompBrick(pix2, pixs, size, 1);
pixCloseSafeCompBrick(pix4, pixs, 1, size);
pixCloseSafeCompBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "close", pix1, pix2, pix3, pix4, pix5, pix6);

return 0;
Expand All @@ -246,54 +246,54 @@ DoComparisonDwa2(L_REGPARAMS *rp,
PIX *pix6,
l_int32 size) /* exactly decomposable */
{
fprintf(stderr, "..%d..", size);
lept_stderr("..%d..", size);

if (TIMING) startTimer();
pixDilateCompBrickExtendDwa(pix1, pixs, size, 1);
pixDilateCompBrickExtendDwa(pix3, pixs, 1, size);
pixDilateCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixDilateBrick(pix2, pixs, size, 1);
pixDilateBrick(pix4, pixs, 1, size);
pixDilateBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "dilate", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixErodeCompBrickExtendDwa(pix1, pixs, size, 1);
pixErodeCompBrickExtendDwa(pix3, pixs, 1, size);
pixErodeCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixErodeBrick(pix2, pixs, size, 1);
pixErodeBrick(pix4, pixs, 1, size);
pixErodeBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "erode", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixOpenCompBrickExtendDwa(pix1, pixs, size, 1);
pixOpenCompBrickExtendDwa(pix3, pixs, 1, size);
pixOpenCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixOpenBrick(pix2, pixs, size, 1);
pixOpenBrick(pix4, pixs, 1, size);
pixOpenBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "open", pix1, pix2, pix3, pix4, pix5, pix6);

if (TIMING) startTimer();
pixCloseCompBrickExtendDwa(pix1, pixs, size, 1);
pixCloseCompBrickExtendDwa(pix3, pixs, 1, size);
pixCloseCompBrickExtendDwa(pix5, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Dwa: %7.3f sec\n", stopTimer());
if (TIMING) startTimer();
pixCloseSafeBrick(pix2, pixs, size, 1);
pixCloseSafeBrick(pix4, pixs, 1, size);
pixCloseSafeBrick(pix6, pixs, size, size);
if (TIMING) fprintf(stderr, "Time Rop: %7.3f sec\n", stopTimer());
if (TIMING) lept_stderr("Time Rop: %7.3f sec\n", stopTimer());
PixCompareDwa(rp, size, "close", pix1, pix2, pix3, pix4, pix5, pix6);

return 0;
Expand All @@ -316,14 +316,14 @@ l_int32 same;
pixEqual(pix1, pix2, &same);
regTestCompareValues(rp, TRUE, same, 0);
if (!same)
fprintf(stderr, "%s (%d, 1) not same\n", type, size);
lept_stderr("%s (%d, 1) not same\n", type, size);
pixEqual(pix3, pix4, &same);
regTestCompareValues(rp, TRUE, same, 0);
if (!same)
fprintf(stderr, "%s (1, %d) not same\n", type, size);
lept_stderr("%s (1, %d) not same\n", type, size);
pixEqual(pix5, pix6, &same);
regTestCompareValues(rp, TRUE, same, 0);
if (!same)
fprintf(stderr, "%s (%d, %d) not same\n", type, size, size);
lept_stderr("%s (%d, %d) not same\n", type, size, size);
}

4 changes: 2 additions & 2 deletions prog/blackwhite_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ L_REGPARAMS *rp;
spp = pixGetSpp(pixs);
pixGetBlackOrWhiteVal(pixs, L_GET_WHITE_VAL, &wval);
pixGetBlackOrWhiteVal(pixs, L_GET_BLACK_VAL, &bval);
fprintf(stderr, "d = %d, spp = %d, bval = %x, wval = %x\n",
lept_stderr("d = %d, spp = %d, bval = %x, wval = %x\n",
pixGetDepth(pixs), spp, bval, wval);
if (spp == 4) /* remove alpha, using white background */
pix1 = pixAlphaBlendUniform(pixs, wval);
Expand All @@ -90,7 +90,7 @@ L_REGPARAMS *rp;
spp = pixGetSpp(pixs);
pixGetBlackOrWhiteVal(pixs, L_GET_WHITE_VAL, &wval);
pixGetBlackOrWhiteVal(pixs, L_GET_BLACK_VAL, &bval);
fprintf(stderr, "d = %d, spp = %d, bval = %x, wval = %x\n",
lept_stderr("d = %d, spp = %d, bval = %x, wval = %x\n",
pixGetDepth(pixs), spp, bval, wval);
if (spp == 4) /* remove alpha, using white background */
pix1 = pixAlphaBlendUniform(pixs, wval);
Expand Down
2 changes: 1 addition & 1 deletion prog/blendcmaptest.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ PIXCMAP *cmap;
pixaAddPix(pixa, pix2, L_COPY);
cmap = pixGetColormap(pix2);
pixcmapWriteStream(stderr, cmap);
fprintf(stderr, "Writing to: /tmp/lept/blend/blendcmap.pdf\n");
lept_stderr("Writing to: /tmp/lept/blend/blendcmap.pdf\n");
pixaConvertToPdf(pixa, 0, 1.0, L_FLATE_ENCODE, 0, "cmap-blendtest",
"/tmp/lept/blend/blendcmap.pdf");

Expand Down
12 changes: 6 additions & 6 deletions prog/boxa2_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ L_REGPARAMS *rp;
regTestCompareValues(rp, 210, median_w_diff, 0.0); /* 0 */
regTestCompareValues(rp, 15, median_h_diff, 0.0); /* 1 */
if (rp->display) {
fprintf(stderr, "diff of e/o median widths = %d\n", median_w_diff);
fprintf(stderr, "diff of e/o median heights = %d\n", median_h_diff);
lept_stderr("diff of e/o median widths = %d\n", median_w_diff);
lept_stderr("diff of e/o median heights = %d\n", median_h_diff);
}

/* Find the differences of box width and height from the median */
Expand Down Expand Up @@ -133,8 +133,8 @@ L_REGPARAMS *rp;
regTestCompareValues(rp, 24, noutw, 0.0); /* 2 */
regTestCompareValues(rp, 0, nouth, 0.0); /* 3 */
if (rp->display)
fprintf(stderr, "num width outliers = %d, num height outliers = %d\n",
noutw, nouth);
lept_stderr("num width outliers = %d, num height outliers = %d\n",
noutw, nouth);
numaDestroy(&nadiffw);
numaDestroy(&nadiffh);
numaDestroy(&naiw);
Expand Down Expand Up @@ -173,8 +173,8 @@ L_REGPARAMS *rp;
regTestCompareValues(rp, 409, w_diff, 0.0); /* 4 */
regTestCompareValues(rp, 49, h_diff, 0.0); /* 5 */
if (rp->display)
fprintf(stderr, "Binned rank results: w_diff = %d, h_diff = %d\n",
w_diff, h_diff);
lept_stderr("Binned rank results: w_diff = %d, h_diff = %d\n",
w_diff, h_diff);

/* Plot the results */
if (noutw > 0 || nouth > 0) {
Expand Down
10 changes: 5 additions & 5 deletions prog/boxa3_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ PIX *pix1;
boxaMedianDimensions(boxa2, &medw, &medh, NULL, NULL, NULL, NULL,
NULL, NULL);
if (rp->display)
fprintf(stderr, "median width = %d, median height = %d\n", medw, medh);
lept_stderr("median width = %d, median height = %d\n", medw, medh);

/* Check for deviations from median by pairs: method 1 */
boxaSizeConsistency1(boxa2, L_CHECK_HEIGHT, 0.0, 0.0,
Expand All @@ -109,15 +109,15 @@ PIX *pix1;
regTestCompareValues(rp, varm[index], fvarm, 0.003); /* 3, 16, 29 */
regTestCompareValues(rp, same[index], isame, 0); /* 4, 17, 30 */
if (rp->display)
fprintf(stderr, "fvarp = %7.4f, fvarm = %7.4f, same = %d\n",
fvarp, fvarm, isame);
lept_stderr("fvarp = %7.4f, fvarm = %7.4f, same = %d\n",
fvarp, fvarm, isame);

/* Check for deviations from median by pairs: method 2 */
boxaSizeConsistency2(boxa2, &devw, &devh, 0);
regTestCompareValues(rp, devwidth[index], devw, 0.001); /* 5, 18, 31 */
regTestCompareValues(rp, devheight[index], devh, 0.001); /* 6, 19, 32 */
if (rp->display)
fprintf(stderr, "dev width = %7.4f, dev height = %7.4f\n", devw, devh);
lept_stderr("dev width = %7.4f, dev height = %7.4f\n", devw, devh);

/* Reconcile widths */
boxa3 = boxaReconcileSizeByMedian(boxa2, L_CHECK_WIDTH, 0.05, 0.04, 1.03,
Expand All @@ -129,7 +129,7 @@ PIX *pix1;
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 8, 21, 34 */
pixDisplayWithTitle(pix1, 500, 0, NULL, rp->display);
if (rp->display)
fprintf(stderr, "ratio median width/height = %6.3f\n", ratiowh);
lept_stderr("ratio median width/height = %6.3f\n", ratiowh);
boxaDestroy(&boxa3);
pixDestroy(&pix1);

Expand Down
2 changes: 1 addition & 1 deletion prog/boxa4_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ L_REGPARAMS *rp;
pix1 = pixaDisplayTiledInRows(pixa2, 32, 1400, 1.0, 0, 10, 0);
regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 12 */
pixDisplayWithTitle(pix1, 0, 600, NULL, rp->display);
fprintf(stderr, "Writing to: /tmp/lept/boxa/show.pdf\n");
lept_stderr("Writing to: /tmp/lept/boxa/show.pdf\n");
l_pdfSetDateAndVersion(FALSE);
pixaConvertToPdf(pixa2, 75, 0.6, 0, 0, NULL, "/tmp/lept/boxa/show.pdf");
regTestCheckFile(rp, "/tmp/lept/boxa/show.pdf"); /* 13 */
Expand Down
18 changes: 8 additions & 10 deletions prog/buffertest.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static char mainName[] = "buffertest";

if ((array1 = l_binaryRead(filein, &nbytes)) == NULL)
return ERROR_INT("array not made", mainName, 1);
fprintf(stderr, "Bytes read from file: %lu\n", (unsigned long)nbytes);
lept_stderr("Bytes read from file: %lu\n", (unsigned long)nbytes);

/* Application of byte buffer ops: compress/decompress in memory */
#if 1
Expand All @@ -69,12 +69,11 @@ static char mainName[] = "buffertest";

filesAreIdentical(filein, "/tmp/dataout2", &same);
if (same)
fprintf(stderr, "Correct: data is the same\n");
lept_stderr("Correct: data is the same\n");
else
fprintf(stderr, "Error: data is different\n");
lept_stderr("Error: data is different\n");

fprintf(stderr,
"nbytes in = %lu, nbytes comp = %lu, nbytes uncomp = %lu\n",
lept_stderr("nbytes in = %lu, nbytes comp = %lu, nbytes uncomp = %lu\n",
(unsigned long)nbytes, (unsigned long)nout, (unsigned long)nout2);
lept_free(dataout);
lept_free(dataout2);
Expand All @@ -87,23 +86,22 @@ static char mainName[] = "buffertest";

array2 = (l_uint8 *)lept_calloc(2 * nbytes, sizeof(l_uint8));

fprintf(stderr, " Bytes initially in buffer: %d\n", bb->n);
lept_stderr(" Bytes initially in buffer: %d\n", bb->n);

blocksize = (2 * nbytes) / NBLOCKS;
for (i = 0; i <= NBLOCKS; i++) {
bbufferWrite(bb, array2, blocksize, &nout);
fprintf(stderr, " block %d: wrote %lu bytes\n", i + 1,
lept_stderr(" block %d: wrote %lu bytes\n", i + 1,
(unsigned long)nout);
}

fprintf(stderr, " Bytes left in buffer: %d\n", bb->n);
lept_stderr(" Bytes left in buffer: %d\n", bb->n);

bb2 = bbufferCreate(NULL, 0);
bbufferRead(bb2, array1, nbytes);
fp = lept_fopen(fileout, "wb");
bbufferWriteStream(bb2, fp, nbytes, &nout);
fprintf(stderr, " bytes written out to fileout: %lu\n",
(unsigned long)nout);
lept_stderr(" bytes written out to fileout: %lu\n", (unsigned long)nout);
lept_fclose(fp);

bbufferDestroy(&bb);
Expand Down
11 changes: 8 additions & 3 deletions prog/bytea_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ SARRAY *sa;
L_BYTEA *lba1, *lba2, *lba3, *lba4;
L_REGPARAMS *rp;

#if !defined(HAVE_LIBJPEG)
L_ERROR("This test requires libjpeg to run.\n", "bytea_reg");
exit(77);
#endif

if (regTestSetup(argc, argv, &rp))
return 1;

Expand Down Expand Up @@ -133,14 +138,14 @@ L_REGPARAMS *rp;
total = nbytesInFile("breviar.38.150.jpg");
lba1 = l_byteaCreate(100);
n = 2 + total / slice; /* using 1 is correct; using 2 gives two errors */
fprintf(stderr, "******************************************************\n");
fprintf(stderr, "* Testing error checking: ignore two reported errors *\n");
lept_stderr("******************************************************\n");
lept_stderr("* Testing error checking: ignore two reported errors *\n");
for (i = 0, start = 0; i < n; i++, start += slice) {
data2 = l_binaryReadSelect("breviar.38.150.jpg", start, slice, &size2);
l_byteaAppendData(lba1, data2, size2);
lept_free(data2);
}
fprintf(stderr, "******************************************************\n");
lept_stderr("******************************************************\n");
data1 = l_byteaGetData(lba1, &size1);
data2 = l_binaryRead("breviar.38.150.jpg", &size2);
regTestCompareStrings(rp, data1, size1, data2, size2); /* 5 */
Expand Down
231 changes: 231 additions & 0 deletions prog/ccbord_reg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials
- provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*====================================================================*/

/*
* ccbord_reg.c
*
* Regression test for border-following representations of binary images.
* This uses the steps in ccbordtest.c to test specified images.
*/

#ifdef HAVE_CONFIG_H
#include <config_auto.h>
#endif /* HAVE_CONFIG_H */

#include <string.h>
#include "allheaders.h"

void RunCCBordTest(const char *fname, L_REGPARAMS *rp);

int main(int argc,
char **argv)
{
L_REGPARAMS *rp;

if (regTestSetup(argc, argv, &rp))
return 1;
lept_mkdir("lept/ccbord");

RunCCBordTest("feyn-fract.tif", rp);
RunCCBordTest("dreyfus1.png", rp);
return regTestCleanup(rp);
}

/* ----------------------------------------------- */
void RunCCBordTest(const char *fname,
L_REGPARAMS *rp)
{
char *svgstr;
l_int32 count, disp;
CCBORDA *ccba, *ccba2;
PIX *pixs, *pixd, *pixd2, *pixd3;
PIX *pixt, *pixc, *pixc2;

pixs = pixRead(fname);
disp = rp->display;

/*------------------------------------------------------------------*
* Get border representation and verify border pixels *
*------------------------------------------------------------------*/
if(disp) lept_stderr("Get border representation...");
ccba = pixGetAllCCBorders(pixs);

/* Get global locs directly and display borders */
if (disp) lept_stderr("Convert from local to global locs...");
ccbaGenerateGlobalLocs(ccba);
if (disp) lept_stderr("display border representation...");
pixd = ccbaDisplayBorder(ccba);
regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 0,7 */
pixDisplayWithTitle(pixd, 0, 0, NULL, rp->display);
pixDestroy(&pixd);

/* Get step chain code, then global coords, and display borders */
if (disp) lept_stderr("get step chain code...");
ccbaGenerateStepChains(ccba);
if (disp) lept_stderr("convert from step chain to global locs...");
ccbaStepChainsToPixCoords(ccba, CCB_GLOBAL_COORDS);
if (disp) lept_stderr("display border representation\n");
pixd = ccbaDisplayBorder(ccba);
regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 1,8 */
pixDisplayWithTitle(pixd, 200, 0, NULL, rp->display);

/* Check if border pixels are in original set */
lept_stderr("Check if border pixels are in original set\n");
pixt = pixSubtract(NULL, pixd, pixs);
pixCountPixels(pixt, &count, NULL);
if (count == 0)
lept_stderr(" ==> all border pixels are in original set\n");
else
lept_stderr(" ==> %d border pixels are not in original set\n", count);
pixDestroy(&pixt);

/* Display image */
lept_stderr("Reconstruct image\n");
pixc = ccbaDisplayImage2(ccba);
regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 2,9 */
pixDisplayWithTitle(pixc, 400, 0, NULL, rp->display);

/* Check with original to see if correct */
pixXor(pixc, pixc, pixs);
pixCountPixels(pixc, &count, NULL);
if (count == 0)
lept_stderr(" ==> perfect direct reconstruction\n");
else {
l_int32 w, h, i, j;
l_uint32 val;
lept_stderr(" ==> %d pixels in error in reconstruction\n", count);
#if 1
w = pixGetWidth(pixc);
h = pixGetHeight(pixc);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
pixGetPixel(pixc, j, i, &val);
if (val == 1)
lept_stderr("bad pixel at (%d, %d)\n", j, i);
}
}
pixWrite("/tmp/lept/ccbord/badpixels1.png", pixc, IFF_PNG);
#endif
}

/*----------------------------------------------------------*
* Write to file (compressed) and read back *
*----------------------------------------------------------*/
if (disp) lept_stderr("Write serialized step data...");
ccbaWrite("/tmp/lept/ccbord/stepdata.ccb", ccba);
if (disp) lept_stderr("read serialized step data...");
ccba2 = ccbaRead("/tmp/lept/ccbord/stepdata.ccb");

/* Display the border pixels again */
if (disp) lept_stderr("convert from step chain to global locs...");
ccbaStepChainsToPixCoords(ccba2, CCB_GLOBAL_COORDS);
if (disp) lept_stderr("display border representation\n");
pixd2 = ccbaDisplayBorder(ccba2);
regTestWritePixAndCheck(rp, pixd2, IFF_PNG); /* 3,10 */
pixDisplayWithTitle(pixd2, 600, 0, NULL, rp->display);

/* Check if border pixels are same as first time */
lept_stderr("Check border after write/read\n");
pixXor(pixd2, pixd2, pixd);
pixCountPixels(pixd2, &count, NULL);
if (count == 0)
lept_stderr(" ==> perfect w/r border recon\n");
else
lept_stderr(" ==> %d pixels in error in w/r recon\n", count);
pixDestroy(&pixd2);

/* Display image again */
if (disp) lept_stderr("Convert from step chain to local coords...\n");
ccbaStepChainsToPixCoords(ccba2, CCB_LOCAL_COORDS);
lept_stderr("Reconstruct image from file\n");
pixc2 = ccbaDisplayImage2(ccba2);
regTestWritePixAndCheck(rp, pixc2, IFF_PNG); /* 4,11 */
pixDisplayWithTitle(pixc2, 800, 0, NULL, rp->display);

/* Check with original to see if correct */
pixXor(pixc2, pixc2, pixs);
pixCountPixels(pixc2, &count, NULL);
if (count == 0)
lept_stderr(" ==> perfect image recon\n");
else {
l_int32 w, h, i, j;
l_uint32 val;
lept_stderr(" ==> %d pixels in error in image recon\n", count);
#if 1
w = pixGetWidth(pixc2);
h = pixGetHeight(pixc2);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
pixGetPixel(pixc2, j, i, &val);
if (val == 1)
lept_stderr("bad pixel at (%d, %d)\n", j, i);
}
}
pixWrite("/tmp/lept/ccbord/badpixels2.png", pixc, IFF_PNG);
#endif
}

/*----------------------------------------------------------*
* Make, display and check single path border for svg *
*----------------------------------------------------------*/
/* Make local single path border for svg */
if (disp) lept_stderr("Make local single path borders for svg ...");
ccbaGenerateSinglePath(ccba);

/* Generate global single path border */
if (disp) lept_stderr("generate global single path borders ...");
ccbaGenerateSPGlobalLocs(ccba, CCB_SAVE_TURNING_PTS);

/* Display border pixels from single path */
if (disp) lept_stderr("display border from single path\n");
pixd3 = ccbaDisplaySPBorder(ccba);
regTestWritePixAndCheck(rp, pixd3, IFF_PNG); /* 5,12 */
pixDisplayWithTitle(pixd3, 1000, 0, NULL, rp->display);

/* Check if border pixels are in original set */
lept_stderr("Check if border pixels are in original set\n");
pixt = pixSubtract(NULL, pixd3, pixs);
pixCountPixels(pixt, &count, NULL);
if (count == 0)
lept_stderr(" ==> all border pixels are in original set\n");
else
lept_stderr(" ==> %d border pixels are not in original set\n", count);
lept_stderr("============================================\n");
pixDestroy(&pixt);
pixDestroy(&pixd3);

/* Output in svg file format */
svgstr = ccbaWriteSVGString(ccba);
regTestWriteDataAndCheck(rp, svgstr, strlen(svgstr), "ccb"); /* 6,13 */

ccbaDestroy(&ccba2);
ccbaDestroy(&ccba);
pixDestroy(&pixs);
pixDestroy(&pixd);
pixDestroy(&pixc);
pixDestroy(&pixc2);
lept_free(svgstr);
}
113 changes: 55 additions & 58 deletions prog/ccbordtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,76 +57,74 @@ static char mainName[] = "ccbordtest";
if ((pixs = pixRead(filein)) == NULL)
return ERROR_INT("pixs not made", mainName, 1);

fprintf(stderr, "Get border representation...");
lept_stderr("Get border representation...");
startTimer();
ccba = pixGetAllCCBorders(pixs);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());

#if 0
/* get global locs directly and display borders */
fprintf(stderr, "Convert from local to global locs...");
/* Get global locs directly and display borders */
lept_stderr("Convert from local to global locs...");
startTimer();
ccbaGenerateGlobalLocs(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Display border representation...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Display border representation...");
startTimer();
pixd = ccbaDisplayBorder(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkborder1.png", pixd, IFF_PNG);
pixDestroy(&pixd);

#else
/* get step chain code, then global coords, and display borders */
fprintf(stderr, "Get step chain code...");
/* Get step chain code, then global coords, and display borders */
lept_stderr("Get step chain code...");
startTimer();
ccbaGenerateStepChains(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Convert from step chain to global locs...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Convert from step chain to global locs...");
startTimer();
ccbaStepChainsToPixCoords(ccba, CCB_GLOBAL_COORDS);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Display border representation...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Display border representation...");
startTimer();
pixd = ccbaDisplayBorder(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkborder1.png", pixd, IFF_PNG);
#endif

/* check if border pixels are in original set */
fprintf(stderr, "Check if border pixels are in original set ...\n");
/* Check if border pixels are in original set */
lept_stderr("Check if border pixels are in original set ...\n");
pixt = pixSubtract(NULL, pixd, pixs);
pixCountPixels(pixt, &count, NULL);
if (count == 0)
fprintf(stderr, " all border pixels are in original set\n");
lept_stderr(" all border pixels are in original set\n");
else
fprintf(stderr, " %d border pixels are not in original set\n", count);
lept_stderr(" %d border pixels are not in original set\n", count);
pixDestroy(&pixt);

/* display image */
fprintf(stderr, "Reconstruct image ...");
/* Display image */
lept_stderr("Reconstruct image ...");
startTimer();
/* pixc = ccbaDisplayImage1(ccba); */
pixc = ccbaDisplayImage2(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkrecon1.png", pixc, IFF_PNG);

/* check with original to see if correct */
fprintf(stderr, "Check with original to see if correct ...\n");
lept_stderr("Check with original to see if correct ...\n");
pixXor(pixc, pixc, pixs);
pixCountPixels(pixc, &count, NULL);
if (count == 0)
fprintf(stderr, " perfect direct recon\n");
lept_stderr(" perfect direct recon\n");
else {
l_int32 w, h, i, j;
l_uint32 val;
fprintf(stderr, " %d pixels in error in recon\n", count);
lept_stderr(" %d pixels in error in recon\n", count);
#if 1
w = pixGetWidth(pixc);
h = pixGetHeight(pixc);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
pixGetPixel(pixc, j, i, &val);
if (val == 1)
fprintf(stderr, "bad pixel at (%d, %d)\n", j, i);
lept_stderr("bad pixel at (%d, %d)\n", j, i);
}
}
pixWrite("/tmp/lept/ccbord/junkbadpixels.png", pixc, IFF_PNG);
Expand All @@ -137,65 +135,65 @@ static char mainName[] = "ccbordtest";
/*----------------------------------------------------------*
* write to file (compressed) and read back *
*----------------------------------------------------------*/
fprintf(stderr, "Write serialized step data...");
lept_stderr("Write serialized step data...");
startTimer();
ccbaWrite("/tmp/junkstepout", ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Read serialized step data...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Read serialized step data...");
startTimer();
ccba2 = ccbaRead("/tmp/junkstepout");
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());

/* display the border pixels again */
fprintf(stderr, "Convert from step chain to global locs...");
lept_stderr("Convert from step chain to global locs...");
startTimer();
ccbaStepChainsToPixCoords(ccba2, CCB_GLOBAL_COORDS);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Display border representation...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Display border representation...");
startTimer();
pixd2 = ccbaDisplayBorder(ccba2);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkborder2.png", pixd2, IFF_PNG);

/* check if border pixels are same as first time */
pixXor(pixd2, pixd2, pixd);
pixCountPixels(pixd2, &count, NULL);
if (count == 0)
fprintf(stderr, " perfect w/r border recon\n");
lept_stderr(" perfect w/r border recon\n");
else
fprintf(stderr, " %d pixels in error in w/r recon\n", count);
lept_stderr(" %d pixels in error in w/r recon\n", count);
pixDestroy(&pixd2);

/* display image again */
fprintf(stderr, "Convert from step chain to local coords...");
lept_stderr("Convert from step chain to local coords...");
startTimer();
ccbaStepChainsToPixCoords(ccba2, CCB_LOCAL_COORDS);
fprintf(stderr, "%6.3f sec\n", stopTimer());
fprintf(stderr, "Reconstruct image from file ...");
lept_stderr("%6.3f sec\n", stopTimer());
lept_stderr("Reconstruct image from file ...");
startTimer();
/* pixc2 = ccbaDisplayImage1(ccba2); */
pixc2 = ccbaDisplayImage2(ccba2);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkrecon2.png", pixc2, IFF_PNG);

/* check with original to see if correct */
fprintf(stderr, "Check with original to see if correct ...\n");
lept_stderr("Check with original to see if correct ...\n");
pixXor(pixc2, pixc2, pixs);
pixCountPixels(pixc2, &count, NULL);
if (count == 0)
fprintf(stderr, " perfect image recon\n");
lept_stderr(" perfect image recon\n");
else {
l_int32 w, h, i, j;
l_uint32 val;
fprintf(stderr, " %d pixels in error in image recon\n", count);
lept_stderr(" %d pixels in error in image recon\n", count);
#if 1
w = pixGetWidth(pixc2);
h = pixGetHeight(pixc2);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
pixGetPixel(pixc2, j, i, &val);
if (val == 1)
fprintf(stderr, "bad pixel at (%d, %d)\n", j, i);
lept_stderr("bad pixel at (%d, %d)\n", j, i);
}
}
pixWrite("/tmp/lept/ccbord/junkbadpixels2.png", pixc2, IFF_PNG);
Expand All @@ -206,37 +204,37 @@ static char mainName[] = "ccbordtest";
* make, display and check single path border for svg *
*----------------------------------------------------------*/
/* make local single path border for svg */
fprintf(stderr, "Make local single path borders for svg ...");
lept_stderr("Make local single path borders for svg ...");
startTimer();
ccbaGenerateSinglePath(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
/* generate global single path border */
fprintf(stderr, "Generate global single path borders ...");
lept_stderr("Generate global single path borders ...");
startTimer();
ccbaGenerateSPGlobalLocs(ccba, CCB_SAVE_TURNING_PTS);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
/* display border pixels from single path */
fprintf(stderr, "Display border from single path...");
lept_stderr("Display border from single path...");
startTimer();
pixd3 = ccbaDisplaySPBorder(ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());
pixWrite("/tmp/lept/ccbord/junkborder3.png", pixd3, IFF_PNG);
/* check if border pixels are in original set */
fprintf(stderr, "Check if border pixels are in original set ...\n");
lept_stderr("Check if border pixels are in original set ...\n");
pixt = pixSubtract(NULL, pixd3, pixs);
pixCountPixels(pixt, &count, NULL);
if (count == 0)
fprintf(stderr, " all border pixels are in original set\n");
lept_stderr(" all border pixels are in original set\n");
else
fprintf(stderr, " %d border pixels are not in original set\n", count);
lept_stderr(" %d border pixels are not in original set\n", count);
pixDestroy(&pixt);
pixDestroy(&pixd3);

/* output in svg file format */
fprintf(stderr, "Write output in svg file format ...\n");
lept_stderr("Write output in svg file format ...\n");
startTimer();
ccbaWriteSVG("/tmp/junksvg", ccba);
fprintf(stderr, "%6.3f sec\n", stopTimer());
lept_stderr("%6.3f sec\n", stopTimer());

ccbaDestroy(&ccba2);
ccbaDestroy(&ccba);
Expand All @@ -246,4 +244,3 @@ static char mainName[] = "ccbordtest";
pixDestroy(&pixc2);
return 0;
}

14 changes: 7 additions & 7 deletions prog/cctest1.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,32 @@ static char mainName[] = "cctest1";
startTimer();
for (i = 0; i < NTIMES; i++)
pixCountConnComp(pixs, 4, &count);
fprintf(stderr, "Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES);
fprintf(stderr, "Number of 4-cc: %d\n", count);
lept_stderr("Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES);
lept_stderr("Number of 4-cc: %d\n", count);
startTimer();
for (i = 0; i < NTIMES; i++)
pixCountConnComp(pixs, 8, &count);
fprintf(stderr, "Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES);
fprintf(stderr, "Number of 8-cc: %d\n", count);
lept_stderr("Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES);
lept_stderr("Number of 8-cc: %d\n", count);

/* Test speed of pixConnComp(), with only boxa output */
startTimer();
for (i = 0; i < NTIMES; i++) {
boxa = pixConnComp(pixs, NULL, 4);
boxaDestroy(&boxa);
}
fprintf(stderr, "Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES);
lept_stderr("Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES);
startTimer();
for (i = 0; i < NTIMES; i++) {
boxa = pixConnComp(pixs, NULL, 8);
boxaDestroy(&boxa);
}
fprintf(stderr, "Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES);
lept_stderr("Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES);

/* Draw outline of each c.c. box */
boxa = pixConnComp(pixs, NULL, 4);
n = boxaGetCount(boxa);
fprintf(stderr, "Num 4-cc boxes: %d\n", n);
lept_stderr("Num 4-cc boxes: %d\n", n);
for (i = 0; i < n; i++) {
box = boxaGetBox(boxa, i, L_CLONE);
pixRenderBox(pixs, box, 3, L_FLIP_PIXELS);
Expand Down
4 changes: 2 additions & 2 deletions prog/ccthin1_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ L_REGPARAMS *rp;
/* Optional display */
if (rp->display) {
lept_mkdir("/lept/thin");
fprintf(stderr, "Writing to: /tmp/lept/thin/ccthin1-1.pdf");
lept_stderr("Writing to: /tmp/lept/thin/ccthin1-1.pdf");
pixaConvertToPdf(pixa, 0, 1.0, 0, 0, "Thin 1 Sels",
"/tmp/lept/thin/ccthin1-1.pdf");
}
Expand Down Expand Up @@ -192,7 +192,7 @@ L_REGPARAMS *rp;
pixDisplayWithTitle(pix1, 0, 0, NULL, rp->display);
pixDestroy(&pix1);
if (rp->display) {
fprintf(stderr, "Writing to: /tmp/lept/thin/ccthin1-2.pdf");
lept_stderr("Writing to: /tmp/lept/thin/ccthin1-2.pdf");
pixaConvertToPdf(pixa, 0, 1.0, 0, 0, "Thin 1 Results",
"/tmp/lept/thin/ccthin1-2.pdf");
}
Expand Down
4 changes: 2 additions & 2 deletions prog/ccthin2_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ SELA *sela;
if (rp->display) {
lept_mkdir("lept/thin");
pixDisplayWithTitle(pix1, 0, 0, NULL, rp->display);
fprintf(stderr, "Writing to: /tmp/lept/thin/ccthin2-1.pdf");
lept_stderr("Writing to: /tmp/lept/thin/ccthin2-1.pdf");
pixaConvertToPdf(pixa1, 0, 1.0, 0, 0, "Thin 2 Results",
"/tmp/lept/thin/ccthin2-1.pdf");
}
Expand Down Expand Up @@ -177,7 +177,7 @@ SELA *sela;
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 18 */
if (rp->display) {
pixDisplayWithTitle(pix1, 0, 0, NULL, rp->display);
fprintf(stderr, "Writing to: /tmp/lept/thin/ccthin2-2.pdf");
lept_stderr("Writing to: /tmp/lept/thin/ccthin2-2.pdf");
pixaConvertToPdf(pixa5, 0, 1.0, 0, 0, "Thin strokes",
"/tmp/lept/thin/ccthin2-2.pdf");
}
Expand Down
140 changes: 140 additions & 0 deletions prog/circle_reg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials
- provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*====================================================================*/

/*
* circle_reg.c
*
* Extract the digits from within a circle. In some cases the circle
* touches the digits, so this cannot be done by simply selecting
* connected components.
*
* Method:
* (1) Find a solid circle that covers the fg pixels.
* (2) Progressively erode the circle, computing the number of
* 8-connected components after each successive 3x3 erosion.
* (3) Stop when the minimum number of components is first reached,
* after passing the maximum number of components. Disregard the
* original image in the counting, because it can have noise.
*/

#ifdef HAVE_CONFIG_H
#include <config_auto.h>
#endif /* HAVE_CONFIG_H */

#include "allheaders.h"

static const l_int32 num_erodes = 8;

int main(int argc,
char **argv)
{
l_int32 i, k, prevcount, count, nfiles, n, maxloc, maxval, minval;
NUMA *na;
PIX *pixs, *pixsi, *pixc, *pixoc, *pix1, *pix2, *pix3;
PIXA *pixas, *pixa1, *pixa2;
L_REGPARAMS *rp;

#if !defined(HAVE_LIBPNG)
L_ERROR("This test requires libpng to run.\n", "circle_reg");
exit(77);
#endif

if (regTestSetup(argc, argv, &rp))
return 1;

/* Read the images */
pixas = pixaRead("circles.pa");
n = pixaGetCount(pixas);

pixa2 = pixaCreate(0);
for (k = 0; k < n; k++) {
pixa1 = pixaCreate(0);
na = numaCreate(0);
pixs = pixaGetPix(pixas, k, L_COPY);
pixaAddPix(pixa1, pixs, L_INSERT);
pixsi = pixInvert(NULL, pixs);
pixc = pixCreateTemplate(pixs);
pixSetOrClearBorder(pixc, 1, 1, 1, 1, PIX_SET);
pixSeedfillBinary(pixc, pixc, pixsi, 4);
pixInvert(pixc, pixc);
pixoc = pixCopy(NULL, pixc); /* original circle */
pixaAddPix(pixa1, pixoc, L_INSERT);
pix1 = pixAnd(NULL, pixs, pixc);
pixaAddPix(pixa1, pix1, L_INSERT);
pixCountConnComp(pix1, 8, &count);
numaAddNumber(na, count);
if (rp->display) lept_stderr("count[0] = %d\n", count);
for (i = 1; i < num_erodes; i++) {
pixErodeBrick(pixc, pixc, 3, 3);
pix1 = pixAnd(NULL, pixs, pixc);
pixaAddPix(pixa1, pix1, L_INSERT);
pixCountConnComp(pix1, 8, &count);
numaAddNumber(na, count);
if (rp->display) lept_stderr("count[%d] = %d\n", i, count);
}

/* Find the max value, not including the original image, which
* may have noise. Then find the first occurrence of the
* min value that follows this max value. */
maxval = maxloc = 0;
for (i = 1; i < num_erodes; i++) { /* get max value starting at 1 */
numaGetIValue(na, i, &count);
if (count > maxval) {
maxval = count;
maxloc = i;
}
}
minval = 1000;
for (i = maxloc + 1; i < num_erodes; i++) { /* get the min value */
numaGetIValue(na, i, &count);
if (count < minval) minval = count;
}
for (i = maxloc + 1; i < num_erodes; i++) { /* get first occurrence */
numaGetIValue(na, i, &count);
if (count == minval) break;
}

pix1 = pixErodeBrick(NULL, pixoc, 2 * i + 1, 2 * i + 1);
pix2 = pixAnd(NULL, pixs, pix1);
pixaAddPix(pixa1, pix2, L_INSERT);
pix3 = pixaDisplayTiledInColumns(pixa1, 11, 1.0, 10, 2);
regTestWritePixAndCheck(rp, pix3, IFF_PNG);
pixaAddPix(pixa2, pix3, L_INSERT);
pixaDestroy(&pixa1);
pixDestroy(&pix1);
pixDestroy(&pixsi);
pixDestroy(&pixc);
numaDestroy(&na);
}

pix1 = pixaDisplayTiledInColumns(pixa2, 1, 1.0, 10, 0);
regTestWritePixAndCheck(rp, pix1, IFF_PNG);
pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display);
pixaDestroy(&pixas);
pixaDestroy(&pixa2);
pixDestroy(&pix1);
return regTestCleanup(rp);
}
Binary file added prog/circles.pa
Binary file not shown.
68 changes: 49 additions & 19 deletions prog/cleanpdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,45 @@
* It will also take as input clean, orthographically-generated pdfs,
* and concatenate them into a single pdf file of images.
*
* Syntax: cleanpdf basedir threshold resolution [rotation]
* Syntax: cleanpdf basedir threshold resolution outfile [rotation]
*
* The basedir is a directory where the input pdf files are located.
* The %basedir is a directory where the input pdf files are located.
* The program will operate on every file in this directory with
* the ".pdf" extension.
*
* The input threshold should be somewhere in the range [130 - 190].
* The result is typically not very sensitive to the value, because
* internally we use a pixel mapping that is adapted to the local
* background before thresholding to binarize the image.
* The input binarization %threshold should be somewhere in the
* range [130 - 190]. The result is typically not very sensitive to
* the value, because internally we use a pixel mapping that is adapted
* to the local background before thresholding to binarize the image.
*
* The resolution should be the scanned resolution. This is typically
* 300 ppi, which for an 8.5 x 11 page would be 2550 x 3300 pixels.
* The output %resolution parameter can take on two values:
* 300 (binarize at the same resolution as the gray or color input,
* which is typically 300 ppi)
* 600 (binarize at twice the resolution of the gray or color input,
* by doing an interpolated 2x expansion on the grayscale
* image, followed by thresholding to 1 bpp)
* That number will also be used as the resolution of the output pdf.
* At 300 ppi, an 8.5 x 11 page would have 2550 x 3300 pixels.
* You can also input 0 for the default resolution of 300 ppi.
*
* The optional rotation is an integer:
* The pdf output is written to %outfile. It is advisable (but not
* required) to have a '.pdf' extension.
*
* The optional %rotation is an integer:
* 0 no rotation
* 1 90 degrees cw
* 1 180 degrees cw
* 1 270 degrees cw
*
* Whenever possible, the images have been deskewed.
* Whenever possible, the images will be deskewed.
*
* The file-handling functions in leptonica do not support filenames
* that have spaces. To use cleanpdf in linux with such filenames,
* substitute an ascii character for the spaces; e.g., '^'.
* char *newstr = stringReplaceEachSubstr(str, " ", "^", NULL);
* Then run cleanpdf on the file(s). Note that you can have an
* output filename with spaces by using single quotes; e.g.,
* cleanpdf dir thresh res 'filename with spaces'
*
* N.B. This requires pdfimages. For non-unix systems, this requires
* installation of the cygwin Poppler package:
Expand Down Expand Up @@ -85,27 +103,35 @@ l_int32 main(int argc,
char **argv)
{
char buf[256];
char *basedir, *fname, *tail, *basename, *imagedir;
char *basedir, *fname, *tail, *basename, *imagedir, *outfile;
l_int32 thresh, res, rotation, i, n, ret;
PIX *pixs, *pix1, *pix2, *pix3, *pix4, *pix5;
SARRAY *sa;
static char mainName[] = "cleanpdf";

if (argc != 4 && argc != 5)
if (argc != 5 && argc != 6)
return ERROR_INT(
"Syntax: cleanpdf basedir threshold resolution [rotation]",
"Syntax: cleanpdf basedir threshold resolution outfile [rotation]",
mainName, 1);
basedir = argv[1];
thresh = atoi(argv[2]);
res = atoi(argv[3]);
if (argc == 5)
rotation = atoi(argv[4]);
outfile = argv[4];
if (argc == 6)
rotation = atoi(argv[5]);
else
rotation = 0;
if (rotation < 0 || rotation > 3) {
L_ERROR("rotation not in valid set {0,1,2,3}; setting to 0", mainName);
rotation = 0;
}
if (res == 0)
res = 300;
if (res != 300 && res != 600) {
L_ERROR("invalid res = %d; res must be in {0, 300, 600}\n",
mainName, res);
return 1;
}
setLeptDebugOK(1);

#if 1
Expand Down Expand Up @@ -154,7 +180,10 @@ static char mainName[] = "cleanpdf";
pix3 = pixFindSkewAndDeskew(pix2, 2, NULL, NULL);
pix4 = pixBackgroundNormSimple(pix3, NULL, NULL);
pixGammaTRC(pix4, pix4, 2.0, 50, 250);
pix5 = pixThresholdToBinary(pix4, thresh);
if (res == 300)
pix5 = pixThresholdToBinary(pix4, thresh);
else /* res == 600 */
pix5 = pixScaleGray2xLIThresh(pix4, thresh);
splitPathAtDirectory(fname, NULL, &tail);
splitPathAtExtension(tail, &basename, NULL);
snprintf(buf, sizeof(buf), "%s/%s.tif", imagedir, basename);
Expand All @@ -174,10 +203,11 @@ static char mainName[] = "cleanpdf";

#if 1
/* Generate the pdf */
fprintf(stderr, "Write output to /tmp/output.pdf\n");
convertFilesToPdf(imagedir, "tif", res, 1.0, L_G4_ENCODE, 0, NULL,
"/tmp/output.pdf");
fprintf(stderr, "Write output to %s\n", outfile);
convertFilesToPdf(imagedir, "tif", res, 1.0, L_G4_ENCODE, 0, NULL, outfile);
#endif

return 0;
}


8 changes: 4 additions & 4 deletions prog/cmapquant_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ L_REGPARAMS *rp;
cmap = pixGetColormap(pix1);
pix3 = pixOctcubeQuantFromCmap(pix2, cmap, MIN_DEPTH,
LEVEL, L_EUCLIDEAN_DISTANCE);
fprintf(stderr, "Time to re-quantize to cmap = %7.3f sec\n", stopTimer());
lept_stderr("Time to re-quantize to cmap = %7.3f sec\n", stopTimer());
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 2 */
pixDisplayWithTitle(pix3, 0, 0, NULL, rp->display);

Expand All @@ -98,22 +98,22 @@ L_REGPARAMS *rp;
/* Octcube quantize mixed with gray */
startTimer();
pix7 = pixOctcubeQuantMixedWithGray(pix2, 4, 5, 5);
fprintf(stderr, "Time to re-quantize mixed = %7.3f sec\n", stopTimer());
lept_stderr("Time to re-quantize mixed = %7.3f sec\n", stopTimer());
regTestWritePixAndCheck(rp, pix7, IFF_PNG); /* 5 */
pixDisplayWithTitle(pix7, 0, 0, NULL, rp->display);

/* Fixed octcube quantization */
startTimer();
pix8 = pixFixedOctcubeQuant256(pix2, 0);
fprintf(stderr, "Time to re-quantize 256 = %7.3f sec\n", stopTimer());
lept_stderr("Time to re-quantize 256 = %7.3f sec\n", stopTimer());
regTestWritePixAndCheck(rp, pix8, IFF_PNG); /* 6 */
pixDisplayWithTitle(pix8, 0, 0, NULL, rp->display);

/* Remove unused colors */
startTimer();
pix9 = pixCopy(NULL, pix8);
pixRemoveUnusedColors(pix9);
fprintf(stderr, "Time to remove unused colors = %7.3f sec\n", stopTimer());
lept_stderr("Time to remove unused colors = %7.3f sec\n", stopTimer());
regTestWritePixAndCheck(rp, pix9, IFF_PNG); /* 7 */
pixDisplayWithTitle(pix8, 0, 0, NULL, rp->display);

Expand Down
69 changes: 62 additions & 7 deletions prog/colorcontent_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
l_int32 main(int argc,
char **argv)
{
//char *fname[64];
char fname[] = "/tmp/lept/colorcontent/maskgen.pdf";
l_uint32 *colors;
l_int32 ncolors;
l_int32 ncolors, w, h;
l_float32 fcolor;
PIX *pix1, *pix2, *pix3;
PIXA *pixadb;
PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pix8;
PIXA *pixa1;
L_REGPARAMS *rp;

#if !defined(HAVE_LIBPNG)
Expand Down Expand Up @@ -99,17 +101,70 @@ L_REGPARAMS *rp;

/* Find background color in image with light color regions */
pix1 = pixRead("map.057.jpg");
pixadb = pixaCreate(0);
pixa1 = pixaCreate(0);
pixFindColorRegions(pix1, NULL, 4, 200, 70, 10, 90, 0.05,
&fcolor, &pix2, NULL, pixadb);
&fcolor, &pix2, NULL, pixa1);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 8 */
pix3 = pixaDisplayTiledInColumns(pixadb, 5, 0.3, 20, 2);
pix3 = pixaDisplayTiledInColumns(pixa1, 5, 0.3, 20, 2);
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 9 */
pixDisplayWithTitle(pix3, 1000, 500, NULL, rp->display);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
pixaDestroy(&pixadb);
pixaDestroy(&pixa1);

/* Show binary classification of RGB colors using a plane */
pix1 = pixMakeGamutRGB(3);
pix2 = pixMakeArbMaskFromRGB(pix1, -0.5, -0.5, 1.0, 20);
pixGetDimensions(pix1, &w, &h, NULL);
pix3 = pixCreate(w, h, 32);
pixSetAll(pix3);
pixCombineMasked(pix3, pix1, pix2);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 10 */
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 11 */
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 12 */
pixDisplayWithTitle(pix3, 0, 1300, NULL, rp->display);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);

/* Show use of more than one plane to further restrict the
allowed region of RGB color space */
pixa1 = pixaCreate(0);
pix1 = pixMakeGamutRGB(3);
pix2 = pixMakeArbMaskFromRGB(pix1, -0.5, -0.5, 1.0, 20);
pix3 = pixMakeArbMaskFromRGB(pix1, 1.5, -0.5, -1.0, 0);
pix4 = pixMakeArbMaskFromRGB(pix1, 0.4, 0.3, 0.3, 60);
pixInvert(pix4, pix4);
pix5 = pixSubtract(NULL, pix2, pix3);
pix6 = pixSubtract(NULL, pix5, pix4);
pixGetDimensions(pix1, &w, &h, NULL);
pix7 = pixCreate(w, h, 32);
pixSetAll(pix7);
pixCombineMasked(pix7, pix1, pix6);
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(pixa1, pix1, L_INSERT);
pixaAddPix(pixa1, pix2, L_INSERT);
pixaAddPix(pixa1, pix3, L_INSERT);
pixaAddPix(pixa1, pix4, L_INSERT);
pixaAddPix(pixa1, pix5, L_INSERT);
pixaAddPix(pixa1, pix6, L_INSERT);
pixaAddPix(pixa1, pix7, L_INSERT);
lept_mkdir("lept/colorcontent");
l_pdfSetDateAndVersion(FALSE);
pixaConvertToPdf(pixa1, 0, 0.5, L_FLATE_ENCODE, 0, NULL, fname);
regTestCheckFile(rp, fname); /* 18 */
lept_stderr("Wrote %s\n", fname);
if (rp->display) {
pix8 = pixaDisplayTiledInColumns(pixa1, 2, 0.5, 15, 2);
pixDisplay(pix8, 800, 1300);
pixDestroy(&pix8);
}
pixaDestroy(&pixa1);

return regTestCleanup(rp);
}
167 changes: 167 additions & 0 deletions prog/colorfill_reg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials
- provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*====================================================================*/

/*
* colorfill_reg.c
*
* This tests the utility that does color segmentation by region growing.
*/

#ifdef HAVE_CONFIG_H
#include <config_auto.h>
#endif /* HAVE_CONFIG_H */

#include "allheaders.h"

static PIX *makeSmallTestPix(l_uint32 c1, l_uint32 c2);


int main(int argc,
char **argv)
{
L_COLORFILL *cf;
PIX *pix1, *pix2, *pix3, *pix4;
PIXA *pixa1, *pixa2;
L_REGPARAMS *rp;

if (regTestSetup(argc, argv, &rp))
return 1;

/* Test on a small image */
pix1 = makeSmallTestPix(0x3070A000, 0xA0703000);
pix2 = pixExpandReplicate(pix1, 15);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */
pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display);
pixDestroy(&pix2);
cf = l_colorfillCreate(pix1, 1, 1);
pixColorContentByLocation(cf, 0, 0, 0, 70, 15, 3, 1, 1);
pix2 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1);
pix3 = pixExpandReplicate(pix2, 10);
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 1 */
pixDisplayWithTitle(pix3, 300, 0, NULL, rp->display);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
l_colorfillDestroy(&cf);

/* Test on simple random image with many colors (1 tile and 4 tiles */
pixa1 = makeColorfillTestData(350, 350, 35, 100);
pixa2 = pixaCreate(5);
pix1 = pixaGetPix(pixa1, 0, L_COPY);
pix2 = pixConvertTo32(pix1);
pixDestroy(&pix1);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 2 */
pixaAddPix(pixa2, pix2, L_INSERT);
cf = l_colorfillCreate(pix2, 1, 1); /* 1 tile */
pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 500, 1, 1);
pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1);
pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1);
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3 */
regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 4 */
pixaAddPix(pixa2, pix3, L_INSERT);
pixaAddPix(pixa2, pix4, L_INSERT);
l_colorfillDestroy(&cf);

cf = l_colorfillCreate(pix2, 2, 2); /* 4 tiles */
pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 500, 1, 1);
pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1);
pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1);
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 5 */
regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 6 */
pixaAddPix(pixa2, pix3, L_INSERT);
pixaAddPix(pixa2, pix4, L_INSERT);
if (rp->display) {
pix1 = pixaDisplayTiledInColumns(pixa2, 5, 1.0, 15, 2);
pixDisplay(pix1, 0, 400);
pixDestroy(&pix1);
}
pixaDestroy(&pixa1);
pixaDestroy(&pixa2);
l_colorfillDestroy(&cf);

/* Test on an image with lots of color (with 1 tile and 9 tiles) */
pix1 = pixRead("lyra.005.jpg");
pix2 = pixScale(pix1, 0.5, 0.5);
pixDestroy(&pix1);
cf = l_colorfillCreate(pix2, 1, 1); /* 1 tile */
pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 100, 1, 1);
pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1);
pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 7 */
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 8 */
regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 9 */
pixa2 = pixaCreate(3);
pixaAddPix(pixa2, pix2, L_COPY);
pixaAddPix(pixa2, pix3, L_INSERT);
pixaAddPix(pixa2, pix4, L_INSERT);
if (rp->display) {
pix1 = pixaDisplayTiledInColumns(pixa2, 3, 0.8, 15, 2);
pixDisplay(pix1, 0, 650);
pixDestroy(&pix1);
}
l_colorfillDestroy(&cf);
pixaDestroy(&pixa2);

cf = l_colorfillCreate(pix2, 3, 3); /* 9 tiles */
pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 100, 1, 1);
pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1);
pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1);
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 10 */
regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 11 */
pixa2 = pixaCreate(2);
pixaAddPix(pixa2, pix3, L_INSERT);
pixaAddPix(pixa2, pix4, L_INSERT);
if (rp->display) {
pix1 = pixaDisplayTiledInColumns(pixa2, 2, 0.8, 15, 2);
pixDisplay(pix1, 0, 1000);
pixDestroy(&pix1);
}
l_colorfillDestroy(&cf);
pixDestroy(&pix2);
pixaDestroy(&pixa2);

return regTestCleanup(rp);
}

static PIX *makeSmallTestPix(l_uint32 c1, l_uint32 c2)
{
l_int32 i, j;
PIX *pix1;

pix1 = pixCreate(17, 17, 32);
pixSetAllArbitrary(pix1, c1);
for (i = 0; i < 15; i++) {
for (j = 0; j < i; j++)
pixSetPixel(pix1, j, i, c2);
}
for (i = 0; i < 15; i++) {
for (j = 17 - i; j < 17; j++)
pixSetPixel(pix1, j, i, c2);
}
for (i = 9; i < 17; i++)
pixSetPixel(pix1, 8, i, c1);
return pix1;
}
2 changes: 1 addition & 1 deletion prog/colorize_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ L_REGPARAMS *rp;
irval = lept_roundftoi(fract * rval);
igval = lept_roundftoi(fract * gval / 2.0);
ibval = lept_roundftoi(fract * bval / 2.0);
fprintf(stderr, "(r,g,b) = (%d,%d,%d)\n", irval, igval, ibval);
lept_stderr("(r,g,b) = (%d,%d,%d)\n", irval, igval, ibval);

/* Test mask-based colorization on gray and cmapped gray */
pix10 = pixColorGrayMasked(pix2, pix9, L_PAINT_DARK, 225,
Expand Down
4 changes: 2 additions & 2 deletions prog/colormorph_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ L_REGPARAMS *rp;

if (rp->display) {
lept_mkdir("lept/cmorph");
fprintf(stderr, "Writing to: /tmp/lept/cmorph/colormorph.pdf\n");
lept_stderr("Writing to: /tmp/lept/cmorph/colormorph.pdf\n");
pixaConvertToPdf(pixa, 0, 1.0, L_FLATE_ENCODE, 0, "colormorph-test",
"/tmp/lept/cmorph/colormorph.pdf");
fprintf(stderr, "Writing to: /tmp/lept/cmorph/colormorph.jpg\n");
lept_stderr("Writing to: /tmp/lept/cmorph/colormorph.jpg\n");
pix1 = pixaDisplayTiledInColumns(pixa, 2, 1.0, 30, 2);
pixWrite("/tmp/lept/cmorph/colormorph.jpg", pix1, IFF_JFIF_JPEG);
pixDisplay(pix1, 100, 100);
Expand Down
2 changes: 1 addition & 1 deletion prog/colorsegtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static char mainName[] = "colorsegtest";
pixt = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
pixd = pixColorSegment(pixt, max_dist, max_colors, sel_size,
final_colors, 1);
fprintf(stderr, "Time to segment: %7.3f sec\n", stopTimer());
lept_stderr("Time to segment: %7.3f sec\n", stopTimer());
pixWrite(fileout, pixd, IFF_PNG);

pixDestroy(&pixs);
Expand Down
5 changes: 2 additions & 3 deletions prog/colorspace_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ L_REGPARAMS *rp;
pix0 = pixGlobalNormRGB(NULL, pixs, rwhite, gwhite, bwhite, 255);
pixaAddPix(pixat, pix0, L_INSERT);
pix1 = pixColorMagnitude(pixs, rwhite, gwhite, bwhite,
L_MAX_DIFF_FROM_AVERAGE_2);
L_AVE_MAX_DIFF_2);
for (j = 0; j < 6; j++) {
pix2 = pixThresholdToBinary(pix1, 30 + 10 * j);
pixInvert(pix2, pix2);
Expand All @@ -149,8 +149,7 @@ L_REGPARAMS *rp;
pixDestroy(&pix2);
}
pixDestroy(&pix1);
pix1 = pixColorMagnitude(pixs, rwhite, gwhite, bwhite,
L_MAX_MIN_DIFF_FROM_2);
pix1 = pixColorMagnitude(pixs, rwhite, gwhite, bwhite, L_INTERMED_DIFF);
for (j = 0; j < 6; j++) {
pix2 = pixThresholdToBinary(pix1, 30 + 10 * j);
pixInvert(pix2, pix2);
Expand Down
18 changes: 10 additions & 8 deletions prog/compare_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ l_float32 cx1, cy1, cx2, cy2, score, fract;
PIX *pix0, *pix1, *pix2, *pix3, *pix4, *pix5;
L_REGPARAMS *rp;

#if !defined(HAVE_LIBPNG)
L_ERROR("This test requires libpng to run.\n", "compare_reg");
exit(77);
#endif

if (regTestSetup(argc, argv, &rp))
return 1;


/* ------------ Test of pixBestCorrelation() --------------- */
pix0 = pixRead("harmoniam100-11.png");
pix1 = pixConvertTo1(pix0, 160);
Expand All @@ -73,15 +77,13 @@ L_REGPARAMS *rp;
pixCentroid(pix2, ctab, stab, &cx2, &cy2);
etransx = lept_roundftoi(cx1 - cx2);
etransy = lept_roundftoi(cy1 - cy2);
fprintf(stderr, "delta cx = %d, delta cy = %d\n",
etransx, etransy);
lept_stderr("delta cx = %d, delta cy = %d\n", etransx, etransy);

/* Get the best correlation, searching around the translation
* where the centroids coincide */
pixBestCorrelation(pix1, pix2, area1, area2, etransx, etransy,
4, stab, &delx, &dely, &score, 5);
fprintf(stderr, "delx = %d, dely = %d, score = %7.4f\n",
delx, dely, score);
lept_stderr("delx = %d, dely = %d, score = %7.4f\n", delx, dely, score);
regTestCompareValues(rp, 32, delx, 0); /* 0 */
regTestCompareValues(rp, 12, dely, 0); /* 1 */
lept_mv("/tmp/lept/comp/correl_5.png", "lept/regout", NULL, NULL);
Expand All @@ -103,7 +105,7 @@ L_REGPARAMS *rp;
pixCompareWithTranslation(pix1, pix2, 160, &delx, &dely, &score, 1);
pixDestroy(&pix1);
pixDestroy(&pix2);
fprintf(stderr, "delx = %d, dely = %d\n", delx, dely);
lept_stderr("delx = %d, dely = %d\n", delx, dely);
regTestCompareValues(rp, 45, delx, 0); /* 3 */
regTestCompareValues(rp, -25, dely, 0); /* 4 */
lept_mv("/tmp/lept/comp/correl.pdf", "lept/regout", NULL, NULL);
Expand All @@ -116,7 +118,7 @@ L_REGPARAMS *rp;
pix1 = pixRead("redcover.jpg"); /* pre-scaled to the same size */
/* Apply directly to the color images */
pixGetPerceptualDiff(pix0, pix1, 1, 3, 20, &fract, &pix2, &pix3);
fprintf(stderr, "Fraction of color pixels = %f\n", fract);
lept_stderr("Fraction of color pixels = %f\n", fract);
regTestCompareValues(rp, 0.061252, fract, 0.01); /* 7 */
regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 8 */
regTestWritePixAndCheck(rp, pix3, IFF_TIFF_G4); /* 9 */
Expand All @@ -126,7 +128,7 @@ L_REGPARAMS *rp;
pix2 = pixConvertTo8(pix0, 0);
pix3 = pixConvertTo8(pix1, 0);
pixGetPerceptualDiff(pix2, pix3, 1, 3, 20, &fract, &pix4, &pix5);
fprintf(stderr, "Fraction of grayscale pixels = %f\n", fract);
lept_stderr("Fraction of grayscale pixels = %f\n", fract);
regTestCompareValues(rp, 0.046928, fract, 0.0002); /* 10 */
regTestWritePixAndCheck(rp, pix4, IFF_JFIF_JPEG); /* 11 */
regTestWritePixAndCheck(rp, pix5, IFF_TIFF_G4); /* 12 */
Expand Down
Loading