main(int argc, char **argv) { l_int32 i; PIX *pix; PIXA *pixa; for (i = 0; i < NTests; i++) GenerateSplitPlot(i); /* Read the results back in ... */ pixa = pixaCreate(0); for (i = 0; i < NTests; i++) { sprintf(buf, "/tmp/junkplot.%d.png", i); pix = pixRead(buf); pixSaveTiled(pix, pixa, 1, 1, 25, 32); pixDestroy(&pix); sprintf(buf, "/tmp/junkplots.%d.png", i); pix = pixRead(buf); pixSaveTiled(pix, pixa, 1, 0, 25, 32); pixDestroy(&pix); } /* ... and save into a tiled pix */ pix = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkotsuplot.png", pix, IFF_PNG); pixDisplay(pix, 100, 100); pixaDestroy(&pixa); pixDestroy(&pix); return 0; }
static void AddScaledImages(PIXA *pixa, const char *fname, l_int32 width) { l_int32 i, w; l_float32 scalefactor; PIX *pixs, *pixt1, *pixt2, *pix32; pixs = pixRead(fname); w = pixGetWidth(pixs); for (i = 0; i < 5; i++) { scalefactor = (l_float32)width / (FACTOR[i] * (l_float32)w); pixt1 = pixScale(pixs, FACTOR[i], FACTOR[i]); pixt2 = pixScale(pixt1, scalefactor, scalefactor); pix32 = pixConvertTo32(pixt2); if (i == 0) pixSaveTiled(pix32, pixa, 1.0, 1, SPACE, 32); else pixSaveTiled(pix32, pixa, 1.0, 0, SPACE, 32); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pix32); } pixDestroy(&pixs); return; }
static PIXA * PixSavePlots1(void) { PIX *pixt; PIXA *pixa; pixa = pixaCreate(8); pixt = pixRead("/tmp/rtnan.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnar.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnai.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnarbin.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnabb.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnared.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnagreen.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnablue.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); return pixa; }
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); }
static void PixSave32(PIXA *pixa, PIX *pixc) { PIX *pix32; pix32 = pixConvertTo32(pixc); pixSaveTiled(pix32, pixa, 1.0, 0, SPACE, 32); pixDestroy(&pixc); pixDestroy(&pix32); return; }
static void PixSave32(PIXA *pixa, PIX *pixc, L_REGPARAMS *rp) { PIX *pix32; pix32 = pixConvertTo32(pixc); pixSaveTiled(pix32, pixa, 1.0, 0, SPACE, 0); regTestWritePixAndCheck(rp, pix32, IFF_JFIF_JPEG); pixDestroy(&pixc); pixDestroy(&pix32); }
PIX * PixTest1(PIX *pixs, l_int32 size, l_float32 factor, L_REGPARAMS *rp) { l_int32 w, h; PIX *pixm, *pixsd, *pixth, *pixd, *pixt; PIXA *pixa; pixm = pixsd = pixth = pixd = NULL; pixGetDimensions(pixs, &w, &h, NULL); /* 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()); pixDestroy(&pixd); /* Get results */ pixSauvolaBinarize(pixs, size, factor, 1, &pixm, &pixsd, &pixth, &pixd); pixa = pixaCreate(0); pixSaveTiled(pixm, pixa, 1, 1, 30, 8); pixSaveTiled(pixsd, pixa, 1, 0, 30, 8); pixSaveTiled(pixth, pixa, 1, 1, 30, 8); pixSaveTiled(pixd, pixa, 1, 0, 30, 8); pixt = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixt, IFF_JFIF_JPEG); if (rp->index < 5) pixDisplayWithTitle(pixt, 100, 100, NULL, rp->display); regTestWritePixAndCheck(rp, pixd, IFF_PNG); pixaDestroy(&pixa); pixDestroy(&pixm); pixDestroy(&pixsd); pixDestroy(&pixth); pixDestroy(&pixt); return pixd; }
int main(int argc, char **argv) { char namebuf[256]; l_int32 i, j, k, maxdist, maxcolors, selsize, finalcolors; PIX *pixs, *pixt, *pixd; PIXA *pixa; static char mainName[] = "colorseg_reg"; if (argc != 1) return ERROR_INT("Syntax: colorseg_reg", mainName, 1); pixs = pixRead("tetons.jpg"); for (k = 0; k < 3; k++) { maxcolors = MaxColors[k]; finalcolors = FinalColors[k]; pixa = pixaCreate(0); pixSaveTiled(pixs, pixa, 1.0, 1, 15, 32); for (i = 1; i <= 9; i++) { maxdist = 20 * i; for (j = 0; j <= 6; j++) { selsize = j; pixt = pixColorSegment(pixs, maxdist, maxcolors, selsize, finalcolors); pixSaveTiled(pixt, pixa, 1.0, j == 0 ? 1 : 0, 15, 32); pixDestroy(&pixt); } } pixd = pixaDisplay(pixa, 0, 0); pixDisplay(pixd, 100, 100); sprintf(namebuf, "/tmp/junkcolorseg%d.jpg", k); pixWrite(namebuf, pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); } pixDestroy(&pixs); return 0; }
void AddTestSet(PIXA *pixa, PIX *pixs, l_int32 filtertype, l_int32 edgethresh, l_int32 smoothx, l_int32 smoothy, l_float32 gamma, l_int32 minval, l_int32 maxval, l_int32 targetthresh) { PIX *pixb, *pixd, *pixth; pixThresholdSpreadNorm(pixs, filtertype, edgethresh, smoothx, smoothy, gamma, minval, maxval, targetthresh, &pixth, NULL, &pixd); pixSaveTiled(pixth, pixa, 1.0, 1, 20, 0); pixSaveTiled(pixd, pixa, 1.0, 0, 20, 0); pixb = pixThresholdToBinary(pixd, targetthresh - 20); pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0); pixDestroy(&pixb); pixb = pixThresholdToBinary(pixd, targetthresh); pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0); pixDestroy(&pixb); pixb = pixThresholdToBinary(pixd, targetthresh + 20); pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0); pixDestroy(&pixb); pixb = pixThresholdToBinary(pixd, targetthresh + 40); pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0); pixDestroy(&pixb); pixDestroy(&pixth); pixDestroy(&pixd); return; }
static void DisplayResult(PIXA *pixac, PIXA **ppixa, l_int32 w, l_int32 h, l_int32 newline) { PIX *pixd; pixd = pixaDisplay(*ppixa, w, h); pixSaveTiled(pixd, pixac, 1, newline, 30, 8); pixDestroy(&pixd); pixaDestroy(ppixa); return; }
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; }
static PIXA * PixSavePlots2(void) { PIX *pixt; PIXA *pixa; pixa = pixaCreate(9); pixt = pixRead("/tmp/rtnan1.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnai1.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnarbin1.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnan2.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnai2.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnarbin2.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnan3.png"); pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnai3.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = pixRead("/tmp/rtnarbin3.png"); pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); return pixa; }
/*! * pixSaveTiledWithText() * * Input: pixs (1, 2, 4, 8, 32 bpp) * pixa (the pix are accumulated here; as 32 bpp) * outwidth (in pixels; use 0 to disable entirely) * newrow (1 to start a new row; 0 to go on same row as previous) * space (horizontal and vertical spacing, in pixels) * linewidth (width of added outline for image; 0 for no outline) * bmf (<optional> font struct) * textstr (<optional> text string to be added) * val (color to set the text) * location (L_ADD_ABOVE, L_ADD_AT_TOP, L_ADD_AT_BOT, L_ADD_BELOW) * Return: 0 if OK, 1 on error. * * Notes: * (1) Before calling this function for the first time, use * pixaCreate() to make the @pixa that will accumulate the pix. * This is passed in each time pixSaveTiled() is called. * (2) @outwidth is the scaled width. After scaling, the image is * saved in the input pixa, along with a box that specifies * the location to place it when tiled later. Disable saving * the pix by setting @outwidth == 0. * (3) @newrow and @space specify the location of the new pix * with respect to the last one(s) that were entered. * (4) All pix are saved as 32 bpp RGB. * (5) If both @bmf and @textstr are defined, this generates a pix * with the additional text; otherwise, no text is written. * (6) The text is written before scaling, so it is properly * antialiased in the scaled pix. However, if the pix on * different calls have different widths, the size of the * text will vary. * (7) See pixSaveTiledOutline() for other implementation details. */ l_int32 pixSaveTiledWithText(PIX *pixs, PIXA *pixa, l_int32 outwidth, l_int32 newrow, l_int32 space, l_int32 linewidth, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location) { PIX *pix1, *pix2, *pix3, *pix4; PROCNAME("pixSaveTiledWithText"); if (outwidth == 0) return 0; if (!pixs) return ERROR_INT("pixs not defined", procName, 1); if (!pixa) return ERROR_INT("pixa not defined", procName, 1); pix1 = pixConvertTo32(pixs); if (linewidth > 0) pix2 = pixAddBorder(pix1, linewidth, 0); else pix2 = pixClone(pix1); if (bmf && textstr) pix3 = pixAddSingleTextblock(pix2, bmf, textstr, val, location, NULL); else pix3 = pixClone(pix2); pix4 = pixScaleToSize(pix3, outwidth, 0); pixSaveTiled(pix4, pixa, 1.0, newrow, space, 32); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); return 0; }
static void RotateTest(PIX *pixs, l_float32 scale, L_REGPARAMS *rp) { l_int32 w, h, d, i, outformat; PIX *pixt, *pixd; PIXA *pixa; pixa = pixaCreate(0); pixGetDimensions(pixs, &w, &h, &d); outformat = (d == 8 || d == 32) ? IFF_JFIF_JPEG : IFF_PNG; pixd = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h); for (i = 1; i < NTIMES; i++) { if ((i % MODSIZE) == 0) { if (i == MODSIZE) { pixSaveTiled(pixd, pixa, scale, 1, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } else { pixSaveTiled(pixd, pixa, scale, 0, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } } pixt = pixRotate(pixd, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h); pixDestroy(&pixd); pixd = pixt; } pixDestroy(&pixd); pixd = pixRotate(pixs, ANGLE1, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h); for (i = 1; i < NTIMES; i++) { if ((i % MODSIZE) == 0) { if (i == MODSIZE) { pixSaveTiled(pixd, pixa, scale, 1, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } else { pixSaveTiled(pixd, pixa, scale, 0, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } } pixt = pixRotate(pixd, ANGLE1, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h); pixDestroy(&pixd); pixd = pixt; } pixDestroy(&pixd); pixd = pixRotate(pixs, ANGLE1, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h); for (i = 1; i < NTIMES; i++) { if ((i % MODSIZE) == 0) { if (i == MODSIZE) { pixSaveTiled(pixd, pixa, scale, 1, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } else { pixSaveTiled(pixd, pixa, scale, 0, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } } pixt = pixRotate(pixd, ANGLE1, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h); pixDestroy(&pixd); pixd = pixt; } pixDestroy(&pixd); pixd = pixRotateAMCorner(pixs, ANGLE2, L_BRING_IN_WHITE); for (i = 1; i < NTIMES; i++) { if ((i % MODSIZE) == 0) { if (i == MODSIZE) { pixSaveTiled(pixd, pixa, scale, 1, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } else { pixSaveTiled(pixd, pixa, scale, 0, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } } pixt = pixRotateAMCorner(pixd, ANGLE2, L_BRING_IN_WHITE); pixDestroy(&pixd); pixd = pixt; } pixDestroy(&pixd); if (d == 32) { pixd = pixRotateAMColorFast(pixs, ANGLE1, 0xb0ffb000); for (i = 1; i < NTIMES; i++) { if ((i % MODSIZE) == 0) { if (i == MODSIZE) { pixSaveTiled(pixd, pixa, scale, 1, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } else { pixSaveTiled(pixd, pixa, scale, 0, 20, 32); regTestWritePixAndCheck(rp, pixd, outformat); } } pixt = pixRotateAMColorFast(pixd, ANGLE1, 0xb0ffb000); pixDestroy(&pixd); pixd = pixt; } } pixDestroy(&pixd); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixaDestroy(&pixa); return; }
main(int argc, char **argv) { l_float32 sum, sumx, sumy, diff; L_DEWARP *dew; L_DEWARPA *dewa; FPIX *fpixs, *fpixs2, *fpixs3, *fpixs4, *fpixg, *fpixd; FPIX *fpix1, *fpix2, *fpixt1, *fpixt2; DPIX *dpix, *dpix2; L_KERNEL *kel, *kelx, *kely; PIX *pixs, *pixs2, *pixs3, *pixt, *pixd, *pixg, *pixb, *pixn; PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6; PIXA *pixa; PTA *ptas, *ptad; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixa = pixaCreate(0); /* Gaussian kernel */ kel = makeGaussianKernel(5, 5, 3.0, 4.0); kernelGetSum(kel, &sum); if (rp->display) fprintf(stderr, "Sum for 2d gaussian kernel = %f\n", sum); pixt = kernelDisplayInPix(kel, 41, 2); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 0 */ pixSaveTiled(pixt, pixa, 1, 1, 20, 8); pixDestroy(&pixt); /* Separable gaussian kernel */ makeGaussianKernelSep(5, 5, 3.0, 4.0, &kelx, &kely); kernelGetSum(kelx, &sumx); if (rp->display) fprintf(stderr, "Sum for x gaussian kernel = %f\n", sumx); kernelGetSum(kely, &sumy); if (rp->display) fprintf(stderr, "Sum for y gaussian kernel = %f\n", sumy); if (rp->display) fprintf(stderr, "Sum for x * y gaussian kernel = %f\n", sumx * sumy); pixt = kernelDisplayInPix(kelx, 41, 2); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 1 */ pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); pixt = kernelDisplayInPix(kely, 41, 2); regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 2 */ pixSaveTiled(pixt, pixa, 1, 0, 20, 8); pixDestroy(&pixt); /* Use pixRasterop() to generate source image */ pixs = pixRead("test8.jpg"); pixs2 = pixRead("karen8.jpg"); pixRasterop(pixs, 150, 125, 150, 100, PIX_SRC, pixs2, 75, 100); regTestWritePixAndCheck(rp, pixs, IFF_JFIF_JPEG); /* 3 */ /* Convolution directly with pix */ pixt1 = pixConvolve(pixs, kel, 8, 1); regTestWritePixAndCheck(rp, pixt1, IFF_JFIF_JPEG); /* 4 */ pixSaveTiled(pixt1, pixa, 1, 1, 20, 8); pixt2 = pixConvolveSep(pixs, kelx, kely, 8, 1); regTestWritePixAndCheck(rp, pixt2, IFF_JFIF_JPEG); /* 5 */ pixSaveTiled(pixt2, pixa, 1, 0, 20, 8); /* Convolution indirectly with fpix, using fpixRasterop() * to generate the source image. */ fpixs = pixConvertToFPix(pixs, 3); fpixs2 = pixConvertToFPix(pixs2, 3); fpixRasterop(fpixs, 150, 125, 150, 100, fpixs2, 75, 100); fpixt1 = fpixConvolve(fpixs, kel, 1); pixt3 = fpixConvertToPix(fpixt1, 8, L_CLIP_TO_ZERO, 1); regTestWritePixAndCheck(rp, pixt3, IFF_JFIF_JPEG); /* 6 */ pixSaveTiled(pixt3, pixa, 1, 1, 20, 8); fpixt2 = fpixConvolveSep(fpixs, kelx, kely, 1); pixt4 = fpixConvertToPix(fpixt2, 8, L_CLIP_TO_ZERO, 1); regTestWritePixAndCheck(rp, pixt4, IFF_JFIF_JPEG); /* 7 */ pixSaveTiled(pixt4, pixa, 1, 0, 20, 8); pixDestroy(&pixs2); fpixDestroy(&fpixs2); fpixDestroy(&fpixt1); fpixDestroy(&fpixt2); /* Comparison of results */ pixCompareGray(pixt1, pixt2, L_COMPARE_ABS_DIFF, 0, NULL, &diff, NULL, NULL); if (rp->display) fprintf(stderr, "Ave diff of pixConvolve and pixConvolveSep: %f\n", diff); pixCompareGray(pixt3, pixt4, L_COMPARE_ABS_DIFF, 0, NULL, &diff, NULL, NULL); if (rp->display) fprintf(stderr, "Ave diff of fpixConvolve and fpixConvolveSep: %f\n", diff); pixCompareGray(pixt1, pixt3, L_COMPARE_ABS_DIFF, 0, NULL, &diff, NULL, NULL); if (rp->display) fprintf(stderr, "Ave diff of pixConvolve and fpixConvolve: %f\n", diff); pixCompareGray(pixt2, pixt4, L_COMPARE_ABS_DIFF, GPLOT_PNG, NULL, &diff, NULL, NULL); if (rp->display) fprintf(stderr, "Ave diff of pixConvolveSep and fpixConvolveSep: %f\n", diff); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); /* Test arithmetic operations; add in a fraction rotated by 180 */ pixs3 = pixRotate180(NULL, pixs); regTestWritePixAndCheck(rp, pixs3, IFF_JFIF_JPEG); /* 8 */ pixSaveTiled(pixs3, pixa, 1, 1, 20, 8); fpixs3 = pixConvertToFPix(pixs3, 3); fpixd = fpixLinearCombination(NULL, fpixs, fpixs3, 20.0, 5.0); fpixAddMultConstant(fpixd, 0.0, 23.174); /* multiply up in magnitude */ pixd = fpixDisplayMaxDynamicRange(fpixd); /* bring back to 8 bpp */ regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 9 */ pixSaveTiled(pixd, pixa, 1, 0, 20, 8); pixDestroy(&pixs3); fpixDestroy(&fpixs3); fpixDestroy(&fpixd); pixDestroy(&pixd); pixDestroy(&pixs); fpixDestroy(&fpixs); /* Save the comparison graph; gnuplot should have made it by now! */ #ifndef _WIN32 sleep(2); #else Sleep(2000); #endif /* _WIN32 */ pixt5 = pixRead("/tmp/grayroot.png"); regTestWritePixAndCheck(rp, pixt5, IFF_PNG); /* 10 */ pixSaveTiled(pixt5, pixa, 1, 1, 20, 8); pixDestroy(&pixt5); /* Display results */ pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 11 */ pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixaDestroy(&pixa); /* Test some more convolutions, with sampled output. First on pix */ pixa = pixaCreate(0); pixs = pixRead("1555-7.jpg"); pixg = pixConvertTo8(pixs, 0); l_setConvolveSampling(5, 5); pixt1 = pixConvolve(pixg, kel, 8, 1); regTestWritePixAndCheck(rp, pixt1, IFF_JFIF_JPEG); /* 12 */ pixSaveTiled(pixt1, pixa, 1, 1, 20, 32); pixt2 = pixConvolveSep(pixg, kelx, kely, 8, 1); regTestWritePixAndCheck(rp, pixt2, IFF_JFIF_JPEG); /* 13 */ pixSaveTiled(pixt2, pixa, 1, 0, 20, 32); pixt3 = pixConvolveRGB(pixs, kel); regTestWritePixAndCheck(rp, pixt3, IFF_JFIF_JPEG); /* 14 */ pixSaveTiled(pixt3, pixa, 1, 0, 20, 32); pixt4 = pixConvolveRGBSep(pixs, kelx, kely); regTestWritePixAndCheck(rp, pixt4, IFF_JFIF_JPEG); /* 15 */ pixSaveTiled(pixt4, pixa, 1, 0, 20, 32); /* Then on fpix */ fpixg = pixConvertToFPix(pixg, 1); fpixt1 = fpixConvolve(fpixg, kel, 1); pixt5 = fpixConvertToPix(fpixt1, 8, L_CLIP_TO_ZERO, 0); regTestWritePixAndCheck(rp, pixt5, IFF_JFIF_JPEG); /* 16 */ pixSaveTiled(pixt5, pixa, 1, 1, 20, 32); fpixt2 = fpixConvolveSep(fpixg, kelx, kely, 1); pixt6 = fpixConvertToPix(fpixt2, 8, L_CLIP_TO_ZERO, 0); regTestWritePixAndCheck(rp, pixt6, IFF_JFIF_JPEG); /* 17 */ pixSaveTiled(pixt2, pixa, 1, 0, 20, 32); regTestCompareSimilarPix(rp, pixt1, pixt5, 2, 0.00, 0); /* 18 */ regTestCompareSimilarPix(rp, pixt2, pixt6, 2, 0.00, 0); /* 19 */ pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); fpixDestroy(&fpixg); fpixDestroy(&fpixt1); fpixDestroy(&fpixt2); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 20 */ pixDisplayWithTitle(pixd, 600, 100, NULL, rp->display); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); pixaDestroy(&pixa); /* Test extension (continued and slope). * First, build a smooth vertical disparity array; * then extend and show the contours. */ pixs = pixRead("cat-35.jpg"); pixn = pixBackgroundNormSimple(pixs, NULL, NULL); pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2); pixb = pixThresholdToBinary(pixg, 130); dewa = dewarpaCreate(1, 30, 1, 15, 0); dew = dewarpCreate(pixb, 35); dewarpaInsertDewarp(dewa, dew); dewarpBuildModel(dew, NULL); dewarpPopulateFullRes(dew, NULL); fpixs = dew->fullvdispar; fpixs2 = fpixAddContinuedBorder(fpixs, 200, 200, 100, 300); fpixs3 = fpixAddSlopeBorder(fpixs, 200, 200, 100, 300); dpix = fpixConvertToDPix(fpixs3); fpixs4 = dpixConvertToFPix(dpix); pixt1 = fpixRenderContours(fpixs, 2.0, 0.2); pixt2 = fpixRenderContours(fpixs2, 2.0, 0.2); pixt3 = fpixRenderContours(fpixs3, 2.0, 0.2); pixt4 = fpixRenderContours(fpixs4, 2.0, 0.2); pixt5 = pixRead("karen8.jpg"); dpix2 = pixConvertToDPix(pixt5, 1); pixt6 = dpixConvertToPix(dpix2, 8, L_CLIP_TO_ZERO, 0); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 21 */ pixDisplayWithTitle(pixt1, 0, 100, NULL, rp->display); regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 22 */ pixDisplayWithTitle(pixt2, 470, 100, NULL, rp->display); regTestWritePixAndCheck(rp, pixt3, IFF_PNG); /* 23 */ pixDisplayWithTitle(pixt3, 1035, 100, NULL, rp->display); regTestComparePix(rp, pixt3, pixt4); /* 24 */ regTestComparePix(rp, pixt5, pixt6); /* 25 */ pixDestroy(&pixs); pixDestroy(&pixn); pixDestroy(&pixg); pixDestroy(&pixb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); pixDestroy(&pixt6); fpixDestroy(&fpixs2); fpixDestroy(&fpixs3); fpixDestroy(&fpixs4); dpixDestroy(&dpix); dpixDestroy(&dpix2); /* Test affine and projective transforms on fpix */ fpixWrite("/tmp/fpix1.fp", dew->fullvdispar); fpix1 = fpixRead("/tmp/fpix1.fp"); pixt1 = fpixAutoRenderContours(fpix1, 40); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 26 */ pixDisplayWithTitle(pixt1, 0, 500, NULL, rp->display); pixDestroy(&pixt1); MakePtasAffine(1, &ptas, &ptad); fpix2 = fpixAffinePta(fpix1, ptad, ptas, 200, 0.0); pixt2 = fpixAutoRenderContours(fpix2, 40); regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 27 */ pixDisplayWithTitle(pixt2, 400, 500, NULL, rp->display); fpixDestroy(&fpix2); pixDestroy(&pixt2); ptaDestroy(&ptas); ptaDestroy(&ptad); MakePtas(1, &ptas, &ptad); fpix2 = fpixProjectivePta(fpix1, ptad, ptas, 200, 0.0); pixt3 = fpixAutoRenderContours(fpix2, 40); regTestWritePixAndCheck(rp, pixt3, IFF_PNG); /* 28 */ pixDisplayWithTitle(pixt3, 400, 500, NULL, rp->display); fpixDestroy(&fpix2); pixDestroy(&pixt3); ptaDestroy(&ptas); ptaDestroy(&ptad); fpixDestroy(&fpix1); dewarpaDestroy(&dewa); kernelDestroy(&kel); kernelDestroy(&kelx); kernelDestroy(&kely); return regTestCleanup(rp); }
main(int argc, char **argv) { l_int32 i, j, w1, h1, w2, h2, w, h, same; BOX *box1, *box2; PIX *pixs, *pixs1, *pixs2, *pix1, *pix2; PIX *pixg, *pixg1, *pixg2, *pixc2, *pixbl, *pixd; PIXA *pixa; static char mainName[] = "blend2_reg"; /* --- Set up the 8 bpp blending image --- */ pixg = pixCreate(660, 500, 8); for (i = 0; i < 500; i++) for (j = 0; j < 660; j++) pixSetPixel(pixg, j, i, (l_int32)(0.775 * j) % 256); /* --- Set up the initial color images to be blended together --- */ pixs1 = pixRead("wyom.jpg"); pixs2 = pixRead("fish24.jpg"); pixGetDimensions(pixs1, &w1, &h1, NULL); pixGetDimensions(pixs2, &w2, &h2, NULL); h = L_MIN(h1, h2); w = L_MIN(w1, w2); box1 = boxCreate(0, 0, w1, h1); box2 = boxCreate(0, 300, 660, 500); pix1 = pixClipRectangle(pixs1, box1, NULL); pix2 = pixClipRectangle(pixs2, box2, NULL); pixDestroy(&pixs1); pixDestroy(&pixs2); boxDestroy(&box1); boxDestroy(&box2); /* --- Blend 2 rgb images --- */ pixa = pixaCreate(0); pixSaveTiled(pixg, pixa, 1, 1, 40, 32); pixd = pixBlendWithGrayMask(pix1, pix2, pixg, 50, 50); pixSaveTiled(pix1, pixa, 1, 1, 40, 32); pixSaveTiled(pix2, pixa, 1, 0, 40, 32); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); /* --- Blend 2 grayscale images --- */ pixg1 = pixConvertRGBToLuminance(pix1); pixg2 = pixConvertRGBToLuminance(pix2); pixd = pixBlendWithGrayMask(pixg1, pixg2, pixg, 50, 50); pixSaveTiled(pixg1, pixa, 1, 1, 40, 32); pixSaveTiled(pixg2, pixa, 1, 0, 40, 32); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixg1); pixDestroy(&pixg2); pixDestroy(&pixd); /* --- Blend a colormap image and an rgb image --- */ pixc2 = pixFixedOctcubeQuantGenRGB(pix2, 2); pixd = pixBlendWithGrayMask(pix1, pixc2, pixg, 50, 50); pixSaveTiled(pix1, pixa, 1, 1, 40, 32); pixSaveTiled(pixc2, pixa, 1, 0, 40, 32); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixc2); pixDestroy(&pixd); /* --- Blend a colormap image and a grayscale image --- */ pixg1 = pixConvertRGBToLuminance(pix1); pixc2 = pixFixedOctcubeQuantGenRGB(pix2, 2); pixd = pixBlendWithGrayMask(pixg1, pixc2, pixg, 50, 50); pixSaveTiled(pixg1, pixa, 1, 1, 40, 32); pixSaveTiled(pixc2, pixa, 1, 0, 40, 32); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); pixd = pixBlendWithGrayMask(pixg1, pixc2, pixg, -100, -100); pixSaveTiled(pixg1, pixa, 1, 1, 40, 32); pixSaveTiled(pixc2, pixa, 1, 0, 40, 32); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); pixDestroy(&pixg1); pixDestroy(&pixc2); /* --- Test png read/write with alpha channel --- */ /* First make pixs1, using pixg as the alpha channel */ pixs = pixRead("fish24.jpg"); box1 = boxCreate(0, 300, 660, 500); pixs1 = pixClipRectangle(pixs, box1, NULL); pixSaveTiled(pixs1, pixa, 1, 1, 40, 32); pixSetRGBComponent(pixs1, pixg, L_ALPHA_CHANNEL); /* To see the alpha channel, blend with a black image */ pixbl = pixCreate(660, 500, 32); pixd = pixBlendWithGrayMask(pixbl, pixs1, NULL, 0, 0); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); /* Write out the RGBA image and read it back */ l_pngSetWriteAlpha(1); pixWrite("/tmp/junkpixs1.png", pixs1, IFF_PNG); l_pngSetStripAlpha(0); pixs2 = pixRead("/tmp/junkpixs1.png"); /* Make sure that the alpha channel image hasn't changed */ pixg2 = pixGetRGBComponent(pixs2, L_ALPHA_CHANNEL); pixEqual(pixg, pixg2, &same); if (same) fprintf(stderr, "PNG with alpha read/write OK\n"); else fprintf(stderr, "PNG with alpha read/write failed\n"); /* Blend again with a black image */ pixd = pixBlendWithGrayMask(pixbl, pixs2, NULL, 0, 0); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); /* Blend with a white image */ pixSetAll(pixbl); pixd = pixBlendWithGrayMask(pixbl, pixs2, NULL, 0, 0); pixSaveTiled(pixd, pixa, 1, 0, 40, 32); pixDestroy(&pixd); l_pngSetWriteAlpha(0); /* reset to default */ l_pngSetStripAlpha(1); /* reset to default */ pixDestroy(&pixbl); pixDestroy(&pixs); pixDestroy(&pixs1); pixDestroy(&pixs2); pixDestroy(&pixg2); boxDestroy(&box1); /* --- Display results --- */ pixd = pixaDisplay(pixa, 0, 0); pixDisplay(pixd, 100, 100); pixWrite("/tmp/junkblend2.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); pixDestroy(&pixg); pixDestroy(&pix1); pixDestroy(&pix2); return 0; }
main(int argc, char **argv) { l_int32 i, j, x, y, val; PIX *pixsq, *pixs, *pixc, *pixd; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixsq = pixCreate(3, 3, 32); pixSetAllArbitrary(pixsq, 0x00ff0000); pixa = pixaCreate(6); /* Moderately dense */ pixs = pixCreate(300, 300, 8); for (i = 0; i < 100; i++) { x = (153 * i * i * i + 59) % 299; y = (117 * i * i * i + 241) % 299; val = (97 * i + 74) % 256; pixSetPixel(pixs, x, y, val); } pixd = pixSeedspread(pixs, 4); /* 4-cc */ pixc = pixConvertTo32(pixd); for (i = 0; i < 100; i++) { x = (153 * i * i * i + 59) % 299; y = (117 * i * i * i + 241) % 299; pixRasterop(pixc, x - 1, y - 1, 3, 3, PIX_SRC, pixsq, 0, 0); } pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 32); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 0 */ pixDisplayWithTitle(pixc, 100, 100, "4-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixd = pixSeedspread(pixs, 8); /* 8-cc */ pixc = pixConvertTo32(pixd); for (i = 0; i < 100; i++) { x = (153 * i * i * i + 59) % 299; y = (117 * i * i * i + 241) % 299; pixRasterop(pixc, x - 1, y - 1, 3, 3, PIX_SRC, pixsq, 0, 0); } pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 1 */ pixDisplayWithTitle(pixc, 410, 100, "8-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixDestroy(&pixs); /* Regular lattice */ pixs = pixCreate(200, 200, 8); for (i = 5; i <= 195; i += 10) { for (j = 5; j <= 195; j += 10) { pixSetPixel(pixs, i, j, (7 * i + 17 * j) % 255); } } pixd = pixSeedspread(pixs, 4); /* 4-cc */ pixc = pixConvertTo32(pixd); for (i = 5; i <= 195; i += 10) { for (j = 5; j <= 195; j += 10) { pixRasterop(pixc, j - 1, i - 1, 3, 3, PIX_SRC, pixsq, 0, 0); } } pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 0); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 2 */ pixDisplayWithTitle(pixc, 100, 430, "4-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixd = pixSeedspread(pixs, 8); /* 8-cc */ pixc = pixConvertTo32(pixd); for (i = 5; i <= 195; i += 10) { for (j = 5; j <= 195; j += 10) { pixRasterop(pixc, j - 1, i - 1, 3, 3, PIX_SRC, pixsq, 0, 0); } } pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 3 */ pixDisplayWithTitle(pixc, 310, 430, "8-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixDestroy(&pixs); /* Very sparse points */ pixs = pixCreate(200, 200, 8); pixSetPixel(pixs, 60, 20, 90); pixSetPixel(pixs, 160, 40, 130); pixSetPixel(pixs, 80, 80, 205); pixSetPixel(pixs, 40, 160, 115); pixd = pixSeedspread(pixs, 4); /* 4-cc */ pixc = pixConvertTo32(pixd); pixRasterop(pixc, 60 - 1, 20 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 160 - 1, 40 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 80 - 1, 80 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 40 - 1, 160 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 0); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 4 */ pixDisplayWithTitle(pixc, 100, 600, "4-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixd = pixSeedspread(pixs, 8); /* 8-cc */ pixc = pixConvertTo32(pixd); pixRasterop(pixc, 60 - 1, 20 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 160 - 1, 40 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 80 - 1, 80 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixRasterop(pixc, 40 - 1, 160 - 1, 3, 3, PIX_SRC, pixsq, 0, 0); pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0); regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 5 */ pixDisplayWithTitle(pixc, 310, 660, "8-cc", rp->display); pixDestroy(&pixd); pixDestroy(&pixc); pixDestroy(&pixs); pixDestroy(&pixsq); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 6 */ pixDisplayWithTitle(pixc, 720, 100, "Final", rp->display); pixaDestroy(&pixa); pixDestroy(&pixd); return regTestCleanup(rp); }
main(int argc, char **argv) { const char *str; l_int32 equal, index, w, h; BOX *box; PIX *pixs, *pixd, *pixt, *pixd1, *pixd2, *pixd3; PIX *pixt0, *pixt1, *pixt2, *pixt3, *pixt4; PIXA *pixa; PIXCMAP *cmap; static char mainName[] = "grayquant_reg"; if ((pixs = pixRead("test8.jpg")) == NULL) exit(ERROR_INT("pixs not made", mainName, 1)); pixa = pixaCreate(0); pixSaveTiled(pixs, pixa, 1, 1, 20, 8); /* threshold to 1 bpp */ pixd = pixThresholdToBinary(pixs, THRESHOLD); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/junkthr0.png", pixd, IFF_PNG); pixDestroy(&pixd); /* dither to 2 bpp, with and without colormap */ pixd = pixDitherTo2bpp(pixs, 1); pixt = pixDitherTo2bpp(pixs, 0); pixt2 = pixConvertGrayToColormap(pixt); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr1.png", pixd, IFF_PNG); pixWrite("/tmp/junkthr2.png", pixt, IFF_PNG); pixWrite("/tmp/junkthr3.png", pixt2, IFF_PNG); /* pixcmapWriteStream(stderr, pixGetColormap(pixd)); */ pixEqual(pixd, pixt2, &equal); if (!equal) fprintf(stderr, "Error: thr2 != thr3\n"); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixd); /* threshold to 2 bpp, with and without colormap */ pixd = pixThresholdTo2bpp(pixs, 4, 1); pixt = pixThresholdTo2bpp(pixs, 4, 0); pixt2 = pixConvertGrayToColormap(pixt); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr4.png", pixd, IFF_PNG); pixWrite("/tmp/junkthr5.png", pixt2, IFF_PNG); pixEqual(pixd, pixt2, &equal); if (!equal) fprintf(stderr, "Error: thr4 != thr5\n"); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixd); pixd = pixThresholdTo2bpp(pixs, 3, 1); pixt = pixThresholdTo2bpp(pixs, 3, 0); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr6.png", pixd, IFF_PNG); pixWrite("/tmp/junkthr7.png", pixt, IFF_PNG); pixDestroy(&pixt); pixDestroy(&pixd); /* threshold to 4 bpp, with and without colormap */ pixd = pixThresholdTo4bpp(pixs, 9, 1); pixt = pixThresholdTo4bpp(pixs, 9, 0); pixt2 = pixConvertGrayToColormap(pixt); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr8.png", pixd, IFF_PNG); pixWrite("/tmp/junkthr9.png", pixt, IFF_PNG); pixWrite("/tmp/junkthr10.png", pixt2, IFF_PNG); /* pixcmapWriteStream(stderr, pixGetColormap(pixd)); */ pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixd); /* threshold on 8 bpp, with and without colormap */ pixd = pixThresholdOn8bpp(pixs, 9, 1); pixt = pixThresholdOn8bpp(pixs, 9, 0); pixt2 = pixConvertGrayToColormap(pixt); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr11.png", pixd, IFF_PNG); pixWrite("/tmp/junkthr12.png", pixt2, IFF_PNG); /* pixcmapWriteStream(stderr, pixGetColormap(pixd)); */ pixEqual(pixd, pixt2, &equal); if (!equal) fprintf(stderr, "Error: thr11 != thr12\n"); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixd); pixd1 = pixaDisplay(pixa, 0, 0); pixDisplay(pixd1, 100, 100); pixWrite("/tmp/junkpixd1.jpg", pixd1, IFF_JFIF_JPEG); pixDestroy(&pixd1); pixaDestroy(&pixa); pixa = pixaCreate(0); pixSaveTiled(pixs, pixa, 1, 1, 20, 32); /* highlight 2 bpp with colormap */ pixd = pixThresholdTo2bpp(pixs, 3, 1); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); box = boxCreate(278, 35, 122, 50); pixSetSelectCmap(pixd, box, 2, 255, 255, 100); pixcmapWriteStream(stderr, cmap); pixDisplay(pixd, 0, 0); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/junkthr13.png", pixd, IFF_PNG); pixDestroy(&pixd); boxDestroy(&box); /* test pixThreshold8() */ pixd = pixThreshold8(pixs, 1, 2, 1); /* cmap */ pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/junkthr14.png", pixd, IFF_PNG); pixDisplay(pixd, 100, 0); pixDestroy(&pixd); pixd = pixThreshold8(pixs, 1, 2, 0); /* no cmap */ pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr15.png", pixd, IFF_PNG); pixDisplay(pixd, 200, 0); pixDestroy(&pixd); pixd = pixThreshold8(pixs, 2, 3, 1); /* highlight one box */ pixSaveTiled(pixd, pixa, 1, 0, 20, 0); box = boxCreate(278, 35, 122, 50); pixSetSelectCmap(pixd, box, 2, 255, 255, 100); pixWrite("/tmp/junkthr16.png", pixd, IFF_PNG); pixDisplay(pixd, 300, 0); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); boxDestroy(&box); pixDestroy(&pixd); pixd = pixThreshold8(pixs, 2, 4, 0); /* no cmap */ pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr17.png", pixd, IFF_PNG); pixDisplay(pixd, 400, 0); pixDestroy(&pixd); pixd = pixThreshold8(pixs, 4, 6, 1); /* highlight one box */ box = boxCreate(278, 35, 122, 50); pixSetSelectCmap(pixd, box, 5, 255, 255, 100); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr18.png", pixd, IFF_PNG); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); boxDestroy(&box); pixDisplay(pixd, 500, 0); pixDestroy(&pixd); pixd = pixThreshold8(pixs, 4, 6, 0); /* no cmap */ pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr19.png", pixd, IFF_PNG); pixDisplay(pixd, 600, 0); pixDestroy(&pixd); /* highlight 4 bpp with 2 colormap entries */ /* Note: We use 5 levels (0-4) for gray. */ /* 5 & 6 are used for highlight color. */ pixd = pixThresholdTo4bpp(pixs, 5, 1); cmap = pixGetColormap(pixd); pixcmapGetIndex(cmap, 255, 255, 255, &index); box = boxCreate(278, 35, 122, 50); pixSetSelectCmap(pixd, box, index, 255, 255, 100); /* use 5 */ boxDestroy(&box); box = boxCreate(4, 6, 157, 33); pixSetSelectCmap(pixd, box, index, 100, 255, 255); /* use 6 */ boxDestroy(&box); pixcmapWriteStream(stderr, cmap); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixDisplay(pixd, 700, 0); pixWrite("/tmp/junkthr20.png", pixd, IFF_PNG); pixDestroy(&pixd); /* comparison 8 bpp jpeg with 2 bpp (highlight) */ pixDestroy(&pixs); pixs = pixRead("feyn.tif"); pixt = pixScaleToGray4(pixs); pixt2 = pixReduceRankBinaryCascade(pixs, 2, 2, 0, 0); pixd = pixThresholdTo2bpp(pixt, 3, 1); box = boxCreate(175, 208, 228, 88); pixSetSelectCmap(pixd, box, 2, 255, 255, 100); pixDisplay(pixd, 100, 200); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); pixSaveTiled(pixt, pixa, 1, 1, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr21.jpg", pixt, IFF_JFIF_JPEG); pixWrite("/tmp/junkthr22.png", pixt2, IFF_PNG); pixWrite("/tmp/junkthr23.png", pixd, IFF_PNG); pixDestroy(&pixd); pixDestroy(&pixt2); boxDestroy(&box); /* thresholding to 4 bpp (highlight); use pixt from above */ pixd = pixThresholdTo4bpp(pixt, NLEVELS, 1); box = boxCreate(175, 208, 228, 83); pixSetSelectCmap(pixd, box, NLEVELS - 1, 255, 255, 100); boxDestroy(&box); box = boxCreate(232, 298, 110, 25); pixSetSelectCmap(pixd, box, NLEVELS - 1, 100, 255, 255); boxDestroy(&box); box = boxCreate(21, 698, 246, 82); pixSetSelectCmap(pixd, box, NLEVELS - 1, 225, 100, 255); boxDestroy(&box); pixDisplay(pixd, 500, 200); cmap = pixGetColormap(pixd); pixcmapWriteStream(stderr, cmap); pixt2 = pixReduceRankBinaryCascade(pixs, 2, 2, 0, 0); pixSaveTiled(pixt2, pixa, 1, 1, 20, 0); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/junkthr24.png", pixt2, IFF_PNG); pixWrite("/tmp/junkthr25.png", pixd, IFF_PNG); pixDestroy(&pixt2); pixDestroy(&pixd); /* Thresholding to 4 bpp at 2, 3, 4, 5 and 6 levels */ box = boxCreate(25, 202, 136, 37); pixt1 = pixClipRectangle(pixt, box, NULL); pixt2 = pixScale(pixt1, 6., 6.); pixGetDimensions(pixt2, &w, &h, NULL); pixSaveTiled(pixt2, pixa, 1, 1, 20, 0); pixDisplay(pixt2, 0, 0); pixWrite("/tmp/junk-8.jpg", pixt2, IFF_JFIF_JPEG); pixd = pixCreate(w, 6 * h, 8); pixRasterop(pixd, 0, 0, w, h, PIX_SRC, pixt2, 0, 0); pixt3 = pixThresholdTo4bpp(pixt2, 6, 1); pixt4 = pixRemoveColormap(pixt3, REMOVE_CMAP_TO_GRAYSCALE); pixRasterop(pixd, 0, h, w, h, PIX_SRC, pixt4, 0, 0); pixSaveTiled(pixt3, pixa, 1, 0, 20, 0); pixDisplay(pixt3, 0, 100); pixWrite("/tmp/junk-4-6.png", pixt3, IFF_PNG); pixDestroy(&pixt3); pixDestroy(&pixt4); pixt3 = pixThresholdTo4bpp(pixt2, 5, 1); pixt4 = pixRemoveColormap(pixt3, REMOVE_CMAP_TO_GRAYSCALE); pixRasterop(pixd, 0, 2 * h, w, h, PIX_SRC, pixt4, 0, 0); pixSaveTiled(pixt3, pixa, 1, 0, 20, 0); pixDisplay(pixt3, 0, 200); pixWrite("/tmp/junk-4-5.png", pixt3, IFF_PNG); pixDestroy(&pixt3); pixDestroy(&pixt4); pixt3 = pixThresholdTo4bpp(pixt2, 4, 1); pixt4 = pixRemoveColormap(pixt3, REMOVE_CMAP_TO_GRAYSCALE); pixRasterop(pixd, 0, 3 * h, w, h, PIX_SRC, pixt4, 0, 0); pixSaveTiled(pixt3, pixa, 1, 0, 20, 0); pixDisplay(pixt3, 0, 300); pixWrite("/tmp/junk-4-4.png", pixt3, IFF_PNG); pixDestroy(&pixt3); pixDestroy(&pixt4); pixt3 = pixThresholdTo4bpp(pixt2, 3, 1); pixt4 = pixRemoveColormap(pixt3, REMOVE_CMAP_TO_GRAYSCALE); pixRasterop(pixd, 0, 4 * h, w, h, PIX_SRC, pixt4, 0, 0); pixSaveTiled(pixt3, pixa, 1, 1, 20, 0); pixDisplay(pixt3, 0, 400); pixWrite("/tmp/junk-4-3.png", pixt3, IFF_PNG); pixDestroy(&pixt3); pixDestroy(&pixt4); pixt3 = pixThresholdTo4bpp(pixt2, 2, 1); pixt4 = pixRemoveColormap(pixt3, REMOVE_CMAP_TO_GRAYSCALE); pixRasterop(pixd, 0, 5 * h, w, h, PIX_SRC, pixt4, 0, 0); pixDisplay(pixt3, 0, 500); pixSaveTiled(pixt3, pixa, 1, 0, 20, 0); pixWrite("/tmp/junk-4-2.png", pixt3, IFF_PNG); pixDestroy(&pixt3); pixDestroy(&pixt4); pixWrite("/tmp/junk-all.png", pixd, IFF_PNG); pixDestroy(&pixd); pixd2 = pixaDisplay(pixa, 0, 0); pixDisplay(pixd2, 100, 100); pixWrite("/tmp/junkpixd2.jpg", pixd2, IFF_JFIF_JPEG); pixDestroy(&pixd2); pixaDestroy(&pixa); #if 0 /* upscale 2x and threshold to 1 bpp; e.g., use test8.jpg */ startTimer(); pixd = pixScaleGray2xLIThresh(pixs, THRESHOLD); fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer()); pixWrite(fileout, pixd, IFF_PNG); pixDestroy(&pixd); #endif #if 0 /* upscale 4x and threshold to 1 bpp; e.g., use test8.jpg */ startTimer(); pixd = pixScaleGray4xLIThresh(pixs, THRESHOLD); fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer()); pixWrite(fileout, pixd, IFF_PNG); pixDestroy(&pixd); #endif boxDestroy(&box); pixDestroy(&pixt); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixs); /* Thresholding with fixed and arbitrary bin boundaries */ pixa = pixaCreate(0); pixs = pixRead("stampede2.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 8); pixt = pixThresholdTo4bpp(pixs, 5, 1); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixt = pixThresholdTo4bpp(pixs, 7, 1); cmap = pixGetColormap(pixt); pixcmapWriteStream(stderr, cmap); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixt = pixThresholdTo4bpp(pixs, 11, 1); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixSaveTiled(pixs, pixa, 1, 1, 20, 8); str = "45 75 115 185"; pixt = pixThresholdGrayArb(pixs, str, 8, 0, 0, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); str = "38 65 85 115 160 210"; pixt = pixThresholdGrayArb(pixs, str, 8, 0, 1, 1); cmap = pixGetColormap(pixt); pixcmapWriteStream(stderr, cmap); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); str = "38 60 75 90 110 130 155 185 208 239"; pixt = pixThresholdGrayArb(pixs, str, 8, 0, 0, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixSaveTiled(pixs, pixa, 1, 1, 20, 8); str = "45 75 115 185"; pixt = pixThresholdGrayArb(pixs, str, 0, 1, 0, 1); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); str = "38 65 85 115 160 210"; pixt = pixThresholdGrayArb(pixs, str, 0, 1, 0, 1); cmap = pixGetColormap(pixt); pixcmapWriteStream(stderr, cmap); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); str = "38 60 75 90 110 130 155 185 208 239"; pixt = pixThresholdGrayArb(pixs, str, 4, 1, 0, 1); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixd3 = pixaDisplay(pixa, 0, 0); pixDisplay(pixd3, 100, 100); pixWrite("/tmp/junkpixd3.jpg", pixd3, IFF_JFIF_JPEG); pixDestroy(&pixd3); pixaDestroy(&pixa); pixDestroy(&pixs); return 0; }
static void TestDistance(PIXA *pixa, PIX *pixs, l_int32 conn, l_int32 depth, l_int32 bc, l_int32 *pcount, L_REGPARAMS *rp) { PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5; /* Test the distance function and display */ pixInvert(pixs, pixs); pixt1 = pixDistanceFunction(pixs, conn, depth, bc); regTestWritePixAndCheck(pixt1, IFF_PNG, pcount, rp); pixSaveTiled(pixt1, pixa, 1, 1, 20, 0); pixInvert(pixs, pixs); pixt2 = pixMaxDynamicRange(pixt1, L_LOG_SCALE); regTestWritePixAndCheck(pixt2, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); /* Test the distance function and display with contour rendering */ pixInvert(pixs, pixs); pixt1 = pixDistanceFunction(pixs, conn, depth, bc); regTestWritePixAndCheck(pixt1, IFF_PNG, pcount, rp); pixSaveTiled(pixt1, pixa, 1, 1, 20, 0); pixInvert(pixs, pixs); pixt2 = pixRenderContours(pixt1, 2, 4, 1); /* binary output */ regTestWritePixAndCheck(pixt2, IFF_PNG, pcount, rp); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixt3 = pixRenderContours(pixt1, 2, 4, depth); pixt4 = pixMaxDynamicRange(pixt3, L_LINEAR_SCALE); regTestWritePixAndCheck(pixt4, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt4, pixa, 1, 0, 20, 0); pixt5 = pixMaxDynamicRange(pixt3, L_LOG_SCALE); regTestWritePixAndCheck(pixt5, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt5, pixa, 1, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixDestroy(&pixt5); /* Label all pixels in each c.c. with a color equal to the * max distance of any pixel within that c.c. from the bg. * Note that we've normalized so the dynamic range extends * to 255. For the image here, each unit of distance is * represented by about 21 grayscale units. The largest * distance is 12. */ if (depth == 8) { pixt1 = pixDistanceFunction(pixs, conn, depth, bc); pixt4 = pixMaxDynamicRange(pixt1, L_LOG_SCALE); regTestWritePixAndCheck(pixt4, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt4, pixa, 1, 1, 20, 0); pixt2 = pixCreateTemplate(pixt1); pixSetMasked(pixt2, pixs, 255); regTestWritePixAndCheck(pixt2, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixSeedfillGray(pixt1, pixt2, 4); pixt3 = pixMaxDynamicRange(pixt1, L_LINEAR_SCALE); regTestWritePixAndCheck(pixt3, IFF_JFIF_JPEG, pcount, rp); pixSaveTiled(pixt3, pixa, 1, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); } return; }
main(int argc, char **argv) { l_int32 i, n, ws, hs, w, h, rval, gval, bval, order; l_float32 *mat1, *mat2, *mat3; l_float32 matd[9]; BOX *box, *boxt; BOXA *boxa, *boxat, *boxa1, *boxa2, *boxa3, *boxa4, *boxa5; PIX *pix, *pixs, *pixb, *pixc, *pixt, *pixt1, *pixt2, *pixt3; PIXA *pixa; static char mainName[] = "xformbox_reg"; /* ----------------------------------------------------------- * * Test hash rendering in 3 modes * * ----------------------------------------------------------- */ pixs = pixRead("feyn.tif"); box = boxCreate(461, 429, 1393, 342); pixt1 = pixClipRectangle(pixs, box, NULL); boxa = pixConnComp(pixt1, NULL, 8); n = boxaGetCount(boxa); pixt2 = pixConvertTo8(pixt1, 1); pixt3 = pixConvertTo32(pixt1); for (i = 0; i < n; i++) { boxt = boxaGetBox(boxa, i, L_CLONE); rval = (1413 * i) % 256; gval = (4917 * i) % 256; bval = (7341 * i) % 256; pixRenderHashBox(pixt1, boxt, 8, 2, i % 4, 1, L_SET_PIXELS); pixRenderHashBoxArb(pixt2, boxt, 7, 2, i % 4, 1, rval, gval, bval); pixRenderHashBoxBlend(pixt3, boxt, 7, 2, i % 4, 1, rval, gval, bval, 0.5); boxDestroy(&boxt); } pixDisplay(pixt1, 0, 0); pixDisplay(pixt2, 0, 300); pixDisplay(pixt3, 0, 570); pixWrite("/tmp/junkpixt1.png", pixt1, IFF_PNG); pixWrite("/tmp/junkpixt2.png", pixt2, IFF_PNG); pixWrite("/tmp/junkpixt3.png", pixt3, IFF_PNG); boxaDestroy(&boxa); boxDestroy(&box); pixDestroy(&pixs); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); /* ----------------------------------------------------------- * * Test box transforms with either translation or scaling * * combined with rotation, using the simple 'ordered' * * function. Show that the order of the operations does * * not matter; different hashing schemes end up in the * * identical boxes. * * ----------------------------------------------------------- */ pix = pixRead("feyn.tif"); box = boxCreate(420, 360, 1500, 465); pixt = pixClipRectangle(pix, box, NULL); pixs = pixAddBorderGeneral(pixt, 0, 200, 0, 0, 0); boxDestroy(&box); pixDestroy(&pix); pixDestroy(&pixt); boxa = pixConnComp(pixs, NULL, 8); n = boxaGetCount(boxa); pixa = pixaCreate(0); pixt = pixConvertTo32(pixs); for (i = 0; i < 3; i++) { if (i == 0) order = L_TR_SC_RO; else if (i == 1) order = L_TR_RO_SC; else order = L_SC_TR_RO; boxat = boxaTransformOrdered(boxa, SHIFTX_2, SHIFTY_2, 1.0, 1.0, 450, 250, ROTATION_2, order); RenderTransformedBoxa(pixt, boxat, i); boxaDestroy(&boxat); } pixSaveTiled(pixt, pixa, 1, 1, 30, 32); pixDestroy(&pixt); pixt = pixConvertTo32(pixs); for (i = 0; i < 3; i++) { if (i == 0) order = L_RO_TR_SC; else if (i == 1) order = L_RO_SC_TR; else order = L_SC_RO_TR; boxat = boxaTransformOrdered(boxa, SHIFTX_2, SHIFTY_2, 1.0, 1.0, 450, 250, ROTATION_2, order); RenderTransformedBoxa(pixt, boxat, i + 4); boxaDestroy(&boxat); } pixSaveTiled(pixt, pixa, 1, 1, 30, 0); pixDestroy(&pixt); pixt = pixConvertTo32(pixs); for (i = 0; i < 3; i++) { if (i == 0) order = L_TR_SC_RO; else if (i == 1) order = L_SC_RO_TR; else order = L_SC_TR_RO; boxat = boxaTransformOrdered(boxa, 0, 0, SCALEX_2, SCALEY_2, 450, 250, ROTATION_2, order); RenderTransformedBoxa(pixt, boxat, i + 8); boxaDestroy(&boxat); } pixSaveTiled(pixt, pixa, 1, 1, 30, 0); pixDestroy(&pixt); pixt = pixConvertTo32(pixs); for (i = 0; i < 3; i++) { if (i == 0) order = L_RO_TR_SC; else if (i == 1) order = L_RO_SC_TR; else order = L_TR_RO_SC; boxat = boxaTransformOrdered(boxa, 0, 0, SCALEX_2, SCALEY_2, 450, 250, ROTATION_2, order); RenderTransformedBoxa(pixt, boxat, i + 16); boxaDestroy(&boxat); } pixSaveTiled(pixt, pixa, 1, 1, 30, 0); pixDestroy(&pixt); pixt = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkxform1.png", pixt, IFF_PNG); pixDisplay(pixt, 1000, 0); pixDestroy(&pixt); pixDestroy(&pixs); boxaDestroy(&boxa); pixaDestroy(&pixa); /* ----------------------------------------------------------- * * Do more testing of box and pta transforms. Show that * * resulting boxes are identical by three methods. * * ----------------------------------------------------------- */ /* Set up pix and boxa */ pixa = pixaCreate(0); pix = pixRead("lucasta.1.300.tif"); pixTranslate(pix, pix, 70, 0, L_BRING_IN_WHITE); pixt = pixCloseBrick(NULL, pix, 14, 5); pixOpenBrick(pixt, pixt, 1, 2); boxa = pixConnComp(pixt, NULL, 8); pixs = pixConvertTo32(pix); pixc = pixCopy(NULL, pixs); RenderTransformedBoxa(pixc, boxa, 113); pixSaveTiled(pixc, pixa, 2, 1, 30, 32); pixDestroy(&pix); pixDestroy(&pixc); pixDestroy(&pixt); /* (a) Do successive discrete operations: shift, scale, rotate */ pixt1 = pixTranslate(NULL, pixs, SHIFTX_3, SHIFTY_3, L_BRING_IN_WHITE); boxa1 = boxaTranslate(boxa, SHIFTX_3, SHIFTY_3); pixc = pixCopy(NULL, pixt1); RenderTransformedBoxa(pixc, boxa1, 213); pixSaveTiled(pixc, pixa, 2, 0, 30, 32); pixDestroy(&pixc); pixt2 = pixScale(pixt1, SCALEX_3, SCALEY_3); boxa2 = boxaScale(boxa1, SCALEX_3, SCALEY_3); pixc = pixCopy(NULL, pixt2); RenderTransformedBoxa(pixc, boxa2, 313); pixSaveTiled(pixc, pixa, 2, 1, 30, 32); pixDestroy(&pixc); pixGetDimensions(pixt2, &w, &h, NULL); pixt3 = pixRotateAM(pixt2, ROTATION_3, L_BRING_IN_WHITE); boxa3 = boxaRotate(boxa2, w / 2, h / 2, ROTATION_3); pixc = pixCopy(NULL, pixt3); RenderTransformedBoxa(pixc, boxa3, 413); pixSaveTiled(pixc, pixa, 2, 0, 30, 32); pixDestroy(&pixc); /* (b) Set up and use the composite transform */ mat1 = createMatrix2dTranslate(SHIFTX_3, SHIFTY_3); mat2 = createMatrix2dScale(SCALEX_3, SCALEY_3); mat3 = createMatrix2dRotate(w / 2, h / 2, ROTATION_3); l_productMat3(mat3, mat2, mat1, matd, 3); boxa4 = boxaAffineTransform(boxa, matd); pixc = pixCopy(NULL, pixt3); RenderTransformedBoxa(pixc, boxa4, 513); pixSaveTiled(pixc, pixa, 2, 1, 30, 32); pixDestroy(&pixc); /* (c) Use the special 'ordered' function */ pixGetDimensions(pixs, &ws, &hs, NULL); boxa5 = boxaTransformOrdered(boxa, SHIFTX_3, SHIFTY_3, SCALEX_3, SCALEY_3, ws / 2, hs / 2, ROTATION_3, L_TR_SC_RO); pixc = pixCopy(NULL, pixt3); RenderTransformedBoxa(pixc, boxa5, 613); pixSaveTiled(pixc, pixa, 2, 0, 30, 32); pixDestroy(&pixc); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); boxaDestroy(&boxa1); boxaDestroy(&boxa2); boxaDestroy(&boxa3); boxaDestroy(&boxa4); boxaDestroy(&boxa5); lept_free(mat1); lept_free(mat2); lept_free(mat3); pixt = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkxform2.png", pixt, IFF_PNG); pixDisplay(pixt, 1000, 300); pixDestroy(&pixt); pixDestroy(&pixs); boxaDestroy(&boxa); pixaDestroy(&pixa); return 0; }
main(int argc, char **argv) { char bufname[256]; l_int32 i, j, w, h, d, x, y, wpls; l_uint32 *datas, *lines; l_float32 *vc; l_float32 *mat1, *mat2, *mat3, *mat1i, *mat2i, *mat3i, *matdinv; l_float32 matd[9], matdi[9]; BOXA *boxa, *boxa2; PIX *pix, *pixs, *pixb, *pixg, *pixc, *pixcs; PIX *pixd, *pixt1, *pixt2, *pixt3; PIXA *pixa; PTA *ptas, *ptad; static char mainName[] = "affine_reg"; if (argc != 1) exit(ERROR_INT(" Syntax: affine_reg", mainName, 1)); if ((pixs = pixRead("feyn.tif")) == NULL) exit(ERROR_INT("pixs not made", mainName, 1)); #if ALL /* Test invertability of sequential. */ pixa = pixaCreate(0); for (i = 0; i < 3; i++) { pixb = pixAddBorder(pixs, ADDED_BORDER_PIXELS, 0); MakePtas(i, &ptas, &ptad); pixt1 = pixAffineSequential(pixb, ptad, ptas, 0, 0); pixSaveTiled(pixt1, pixa, 3, 1, 20, 8); pixt2 = pixAffineSequential(pixt1, ptas, ptad, 0, 0); pixSaveTiled(pixt2, pixa, 3, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS); pixXor(pixd, pixd, pixs); pixSaveTiled(pixd, pixa, 3, 0, 20, 0); sprintf(bufname, "/tmp/junkseq%d.png", i); pixWrite(bufname, pixd, IFF_PNG); pixDestroy(&pixb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine1.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 100); pixDestroy(&pixt1); pixaDestroy(&pixa); #endif #if ALL /* Test invertability of sampling */ pixa = pixaCreate(0); for (i = 0; i < 3; i++) { pixb = pixAddBorder(pixs, ADDED_BORDER_PIXELS, 0); MakePtas(i, &ptas, &ptad); pixt1 = pixAffineSampledPta(pixb, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt1, pixa, 3, 1, 20, 8); pixt2 = pixAffineSampledPta(pixt1, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 3, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS); pixXor(pixd, pixd, pixs); pixSaveTiled(pixd, pixa, 3, 0, 20, 0); if (i == 0) pixWrite("/tmp/junksamp.png", pixt1, IFF_PNG); pixDestroy(&pixb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine2.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 300); pixDestroy(&pixt1); pixaDestroy(&pixa); #endif #if ALL /* Test invertability of interpolation on grayscale */ pixa = pixaCreate(0); pixg = pixScaleToGray3(pixs); for (i = 0; i < 3; i++) { pixb = pixAddBorder(pixg, ADDED_BORDER_PIXELS / 3, 255); MakePtas(i, &ptas, &ptad); pixt1 = pixAffinePta(pixb, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt1, pixa, 1, 1, 20, 8); pixt2 = pixAffinePta(pixt1, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS / 3); pixXor(pixd, pixd, pixg); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); if (i == 0) pixWrite("/tmp/junkinterp.png", pixt1, IFF_PNG); pixDestroy(&pixb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine3.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 500); pixDestroy(&pixt1); pixaDestroy(&pixa); pixDestroy(&pixg); #endif #if ALL /* Test invertability of interpolation on color */ pixa = pixaCreate(0); pixc = pixRead("test24.jpg"); pixcs = pixScale(pixc, 0.3, 0.3); for (i = 0; i < 3; i++) { pixb = pixAddBorder(pixcs, ADDED_BORDER_PIXELS / 4, 0xffffff00); MakePtas(i, &ptas, &ptad); pixt1 = pixAffinePta(pixb, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt1, pixa, 1, 1, 20, 32); pixt2 = pixAffinePta(pixt1, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS / 4); pixXor(pixd, pixd, pixcs); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixDestroy(&pixb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine4.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 500); pixDestroy(&pixt1); pixaDestroy(&pixa); pixDestroy(&pixc); pixDestroy(&pixcs); #endif #if ALL /* Comparison between sequential and sampling */ MakePtas(3, &ptas, &ptad); pixa = pixaCreate(0); /* Use sequential transforms */ pixt1 = pixAffineSequential(pixs, ptas, ptad, ADDED_BORDER_PIXELS, ADDED_BORDER_PIXELS); pixSaveTiled(pixt1, pixa, 2, 0, 20, 8); /* Use sampled transform */ pixt2 = pixAffineSampledPta(pixs, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 2, 0, 20, 8); /* Compare the results */ pixXor(pixt2, pixt2, pixt1); pixSaveTiled(pixt2, pixa, 2, 0, 20, 8); pixd = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine5.png", pixd, IFF_PNG); pixDisplay(pixd, 100, 700); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); pixaDestroy(&pixa); ptaDestroy(&ptas); ptaDestroy(&ptad); #endif #if ALL /* Get timings and test with large distortion */ MakePtas(4, &ptas, &ptad); pixa = pixaCreate(0); pixg = pixScaleToGray3(pixs); startTimer(); pixt1 = pixAffineSequential(pixg, ptas, ptad, 0, 0); fprintf(stderr, " Time for pixAffineSequentialPta(): %6.2f sec\n", stopTimer()); pixSaveTiled(pixt1, pixa, 1, 1, 20, 8); startTimer(); pixt2 = pixAffineSampledPta(pixg, ptas, ptad, L_BRING_IN_WHITE); fprintf(stderr, " Time for pixAffineSampledPta(): %6.2f sec\n", stopTimer()); pixSaveTiled(pixt2, pixa, 1, 0, 20, 8); startTimer(); pixt3 = pixAffinePta(pixg, ptas, ptad, L_BRING_IN_WHITE); fprintf(stderr, " Time for pixAffinePta(): %6.2f sec\n", stopTimer()); pixSaveTiled(pixt3, pixa, 1, 0, 20, 8); pixXor(pixt1, pixt1, pixt2); pixSaveTiled(pixt1, pixa, 1, 1, 20, 8); pixXor(pixt2, pixt2, pixt3); pixSaveTiled(pixt2, pixa, 1, 0, 20, 8); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixd = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine6.png", pixd, IFF_PNG); pixDisplay(pixd, 100, 900); pixDestroy(&pixd); pixDestroy(&pixg); pixaDestroy(&pixa); ptaDestroy(&ptas); ptaDestroy(&ptad); #endif pixDestroy(&pixs); #if 1 /* Set up pix and boxa */ pixa = pixaCreate(0); pix = pixRead("lucasta.1.300.tif"); pixTranslate(pix, pix, 70, 0, L_BRING_IN_WHITE); pixt1 = pixCloseBrick(NULL, pix, 14, 5); pixOpenBrick(pixt1, pixt1, 1, 2); boxa = pixConnComp(pixt1, NULL, 8); pixs = pixConvertTo32(pix); pixGetDimensions(pixs, &w, &h, NULL); pixc = pixCopy(NULL, pixs); RenderHashedBoxa(pixc, boxa, 113); pixSaveTiled(pixc, pixa, 2, 1, 30, 32); pixDestroy(&pix); pixDestroy(&pixc); pixDestroy(&pixt1); /* Set up an affine transform in matd, and apply it to boxa */ mat1 = createMatrix2dTranslate(SHIFTX, SHIFTY); mat2 = createMatrix2dScale(SCALEX, SCALEY); mat3 = createMatrix2dRotate(w / 2, h / 2, ROTATION); l_productMat3(mat3, mat2, mat1, matd, 3); boxa2 = boxaAffineTransform(boxa, matd); /* Set up the inverse transform in matdi */ mat1i = createMatrix2dTranslate(-SHIFTX, -SHIFTY); mat2i = createMatrix2dScale(1.0/ SCALEX, 1.0 / SCALEY); mat3i = createMatrix2dRotate(w / 2, h / 2, -ROTATION); l_productMat3(mat1i, mat2i, mat3i, matdi, 3); /* Invert the original affine transform in matdinv */ affineInvertXform(matd, &matdinv); fprintf(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]); } fprintf(stderr, "\nInverse transform, made by composing inverse parts"); for (i = 0; i < 9; i++) { if (i % 3 == 0) fprintf(stderr, "\n"); fprintf(stderr, " %7.3f ", matdi[i]); } fprintf(stderr, "\nInverse transform, made by inverting the affine xform"); for (i = 0; i < 6; i++) { if (i % 3 == 0) fprintf(stderr, "\n"); fprintf(stderr, " %7.3f ", matdinv[i]); } fprintf(stderr, "\n"); /* Apply the inverted affine transform pixs */ pixd = pixAffine(pixs, matdinv, L_BRING_IN_WHITE); RenderHashedBoxa(pixd, boxa2, 513); pixSaveTiled(pixd, pixa, 2, 0, 30, 32); pixDestroy(&pixd); pixd = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkaffine7.png", pixd, IFF_PNG); pixDisplay(pixd, 100, 900); pixDestroy(&pixd); pixDestroy(&pixs); pixaDestroy(&pixa); boxaDestroy(&boxa); boxaDestroy(&boxa2); FREE(mat1); FREE(mat2); FREE(mat3); FREE(mat1i); FREE(mat2i); FREE(mat3i); #endif return 0; }
static l_int32 TestImage(const char *filename, l_int32 i, L_REGPARAMS *rp) { char buf[256]; l_int32 w, h; l_float32 factor; PIX *pix, *pixs, *pixc, *pix32, *pixt, *pixd; PIXA *pixa; PROCNAME("TestImage"); if ((pix = pixRead(filename)) == NULL) { rp->success = FALSE; return ERROR_INT("pix not made", procName, 1); } pixGetDimensions(pix, &w, &h, NULL); if (w > MAX_WIDTH) { factor = (l_float32)MAX_WIDTH / (l_float32)w; pixs = pixScale(pix, factor, factor); } else pixs = pixClone(pix); pixDestroy(&pix); pixa = pixaCreate(0); /* Median cut quantizer (no dither; 5 sigbits) */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 32); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 16, 5, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 128, 5, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 256, 5, 1, 1); PixSave32(pixa, pixc, rp); /* Median cut quantizer (with dither; 5 sigbits) */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 16, 5, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 128, 5, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 256, 5, 1, 1); PixSave32(pixa, pixc, rp); /* Median cut quantizer (no dither; 6 sigbits) */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 32); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 16, 6, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 128, 6, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 0, 0, 256, 6, 1, 1); PixSave32(pixa, pixc, rp); /* Median cut quantizer (with dither; 6 sigbits) */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 16, 6, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 128, 6, 1, 1); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantGeneral(pixs, 1, 0, 256, 6, 10, 1); PixSave32(pixa, pixc, rp); /* Median cut quantizer (mixed color/gray) */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixMedianCutQuantMixed(pixs, 20, 10, 0, 0, 0); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantMixed(pixs, 60, 20, 0, 0, 0); PixSave32(pixa, pixc, rp); pixc = pixMedianCutQuantMixed(pixs, 180, 40, 0, 0, 0); PixSave32(pixa, pixc, rp); /* Simple 256 cube octcube quantizer */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixFixedOctcubeQuant256(pixs, 0); /* no dither */ PixSave32(pixa, pixc, rp); pixc = pixFixedOctcubeQuant256(pixs, 1); /* dither */ PixSave32(pixa, pixc, rp); /* 2-pass octree quantizer */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixOctreeColorQuant(pixs, 128, 0); /* no dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeColorQuant(pixs, 240, 0); /* no dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeColorQuant(pixs, 128, 1); /* dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeColorQuant(pixs, 240, 1); /* dither */ PixSave32(pixa, pixc, rp); /* Simple adaptive quantization to 4 or 8 bpp, specifying ncolors */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixOctreeQuantNumColors(pixs, 8, 0); /* fixed: 8 colors */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantNumColors(pixs, 16, 0); /* fixed: 16 colors */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantNumColors(pixs, 64, 0); /* fixed: 64 colors */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantNumColors(pixs, 256, 0); /* fixed: 256 colors */ PixSave32(pixa, pixc, rp); /* Quantize to fully populated octree (RGB) at given level */ pixSaveTiled(pixs, pixa, 1.0, 1, SPACE, 0); pixc = pixFixedOctcubeQuantGenRGB(pixs, 2); /* level 2 */ PixSave32(pixa, pixc, rp); pixc = pixFixedOctcubeQuantGenRGB(pixs, 3); /* level 3 */ PixSave32(pixa, pixc, rp); pixc = pixFixedOctcubeQuantGenRGB(pixs, 4); /* level 4 */ PixSave32(pixa, pixc, rp); pixc = pixFixedOctcubeQuantGenRGB(pixs, 5); /* level 5 */ PixSave32(pixa, pixc, rp); /* Generate 32 bpp RGB image with num colors <= 256 */ pixt = pixOctreeQuantNumColors(pixs, 256, 0); /* cmapped version */ pix32 = pixRemoveColormap(pixt, REMOVE_CMAP_BASED_ON_SRC); /* Quantize image with few colors at fixed octree leaf level */ pixSaveTiled(pixt, pixa, 1.0, 1, SPACE, 0); pixc = pixFewColorsOctcubeQuant1(pix32, 2); /* level 2 */ PixSave32(pixa, pixc, rp); pixc = pixFewColorsOctcubeQuant1(pix32, 3); /* level 3 */ PixSave32(pixa, pixc, rp); pixc = pixFewColorsOctcubeQuant1(pix32, 4); /* level 4 */ PixSave32(pixa, pixc, rp); pixc = pixFewColorsOctcubeQuant1(pix32, 5); /* level 5 */ PixSave32(pixa, pixc, rp); /* Quantize image by population */ pixSaveTiled(pixt, pixa, 1.0, 1, SPACE, 0); pixc = pixOctreeQuantByPopulation(pixs, 3, 0); /* level 3, no dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantByPopulation(pixs, 3, 1); /* level 3, dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantByPopulation(pixs, 4, 0); /* level 4, no dither */ PixSave32(pixa, pixc, rp); pixc = pixOctreeQuantByPopulation(pixs, 4, 1); /* level 4, dither */ PixSave32(pixa, pixc, rp); /* Mixed color/gray octree quantizer */ pixSaveTiled(pixt, pixa, 1.0, 1, SPACE, 0); pixc = pixOctcubeQuantMixedWithGray(pix32, 8, 64, 10); /* max delta = 10 */ PixSave32(pixa, pixc, rp); pixc = pixOctcubeQuantMixedWithGray(pix32, 8, 64, 30); /* max delta = 30 */ PixSave32(pixa, pixc, rp); pixc = pixOctcubeQuantMixedWithGray(pix32, 8, 64, 50); /* max delta = 50 */ PixSave32(pixa, pixc, rp); /* Run the high-level converter */ pixSaveTiled(pixt, pixa, 1.0, 1, SPACE, 0); pixc = pixConvertRGBToColormap(pix32, 1); PixSave32(pixa, pixc, rp); pixDestroy(&pix32); pixDestroy(&pixt); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); sprintf(buf, "/tmp/regout/disp.%d.jpg", i); pixWrite(buf, pixd, IFF_JFIF_JPEG); pixDestroy(&pixs); pixDestroy(&pixd); pixaDestroy(&pixa); return 0; }
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); }
void RotateTest(PIX *pixs, l_int32 reduction, L_REGPARAMS *rp) { l_int32 w, h, d, outformat; PIX *pixt1, *pixt2, *pixt3, *pixd; PIXA *pixa; pixGetDimensions(pixs, &w, &h, &d); outformat = (d == 8 || d == 32) ? IFF_JFIF_JPEG : IFF_PNG; pixa = pixaCreate(0); pixt1 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 32); pixt2 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_BLACK, w, h); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_WHITE, 0, 0); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0); pixt2 = pixRotate(pixs, ANGLE1, L_ROTATE_SHEAR, L_BRING_IN_BLACK, 0, 0); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_WHITE, w, h); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0); pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_BLACK, w, h); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_WHITE, 0, 0); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0); pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SHEAR, L_BRING_IN_BLACK, 0, 0); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, outformat); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixaDestroy(&pixa); pixa = pixaCreate(0); pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, w, h); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 32); pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_BLACK, w, h); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); pixt1 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, 0, 0); pixSaveTiled(pixt1, pixa, reduction, 1, 20, 0); pixt2 = pixRotate(pixs, ANGLE2, L_ROTATE_SAMPLING, L_BRING_IN_BLACK, 0, 0); pixSaveTiled(pixt2, pixa, reduction, 0, 20, 0); pixDestroy(&pixt1); pixDestroy(&pixt2); if (pixGetDepth(pixs) == 1) pixt1 = pixScaleToGray2(pixs); else pixt1 = pixClone(pixs); pixt2 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, w, h); pixSaveTiled(pixt2, pixa, reduction, 1, 20, 0); pixt3 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, w, h); pixSaveTiled(pixt3, pixa, reduction, 0, 20, 0); pixDestroy(&pixt2); pixDestroy(&pixt3); pixt2 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_WHITE, 0, 0); pixSaveTiled(pixt2, pixa, reduction, 1, 20, 0); pixt3 = pixRotate(pixt1, ANGLE2, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, 0, 0); pixSaveTiled(pixt3, pixa, reduction, 0, 20, 0); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt1); pixd = pixaDisplay(pixa, 0, 0); regTestWritePixAndCheck(rp, pixd, outformat); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixDestroy(&pixd); pixaDestroy(&pixa); return; }
main(int argc, char **argv) { l_int32 error; l_uint32 *data; PIX *pix1, *pix2, *pix3, *pix1c, *pix2c, *pix1t, *pix2t, *pixd; PIXA *pixa; static char mainName[] = "pixmem_reg"; error = 0; pixa = pixaCreate(0); /* Copy with internal resizing: onto a cmapped image */ pix1 = pixRead("weasel4.16c.png"); pix2 = pixRead("feyn-fract.tif"); pix3 = pixRead("lucasta.150.jpg"); fprintf(stderr, "before copy 2 --> 3\n"); pixCopy(pix3, pix2); Compare(pix2, pix3, &error); pixSaveTiled(pix3, pixa, 4, 1, 30, 32); fprintf(stderr, "before copy 3 --> 1\n"); pixCopy(pix1, pix3); Compare(pix2, pix1, &error); pixSaveTiled(pix1, pixa, 4, 0, 30, 32); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* Copy with internal resizing: from a cmapped image */ pix1 = pixRead("weasel4.16c.png"); pix2 = pixRead("feyn-fract.tif"); pix3 = pixRead("lucasta.150.jpg"); fprintf(stderr, "before copy 1 --> 2\n"); pixCopy(pix2, pix1); Compare(pix2, pix1, &error); pixSaveTiled(pix2, pixa, 1, 1, 30, 32); fprintf(stderr, "before copy 2 --> 3\n"); pixCopy(pix3, pix2); Compare(pix3, pix2, &error); pixSaveTiled(pix3, pixa, 1, 0, 30, 32); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* Transfer of data pixs --> pixd, when pixs is not cloned. * pixs is destroyed. */ pix1 = pixRead("weasel4.16c.png"); pix2 = pixRead("feyn-fract.tif"); pix3 = pixRead("lucasta.150.jpg"); pix1c = pixCopy(NULL, pix1); fprintf(stderr, "before transfer 1 --> 2\n"); pixTransferAllData(pix2, &pix1, 0, 0); Compare(pix2, pix1c, &error); pixSaveTiled(pix2, pixa, 1, 1, 30, 32); fprintf(stderr, "before transfer 2 --> 3\n"); pixTransferAllData(pix3, &pix2, 0, 0); Compare(pix3, pix1c, &error); pixSaveTiled(pix3, pixa, 1, 0, 30, 32); pixDestroy(&pix1c); pixDestroy(&pix3); /* Another transfer of data pixs --> pixd, when pixs is not cloned. * pixs is destroyed. */ pix1 = pixRead("weasel4.16c.png"); pix2 = pixRead("feyn-fract.tif"); pix3 = pixRead("lucasta.150.jpg"); pix1c = pixCopy(NULL, pix1); pix2c = pixCopy(NULL, pix2); fprintf(stderr, "before copy transfer 1 --> 2\n"); pixTransferAllData(pix2, &pix1c, 0, 0); Compare(pix2, pix1, &error); pixSaveTiled(pix2, pixa, 1, 0, 30, 32); fprintf(stderr, "before copy transfer 2 --> 3\n"); pixTransferAllData(pix3, &pix2, 0, 0); Compare(pix3, pix1, &error); pixSaveTiled(pix3, pixa, 1, 0, 30, 32); pixDestroy(&pix1); pixDestroy(&pix2c); pixDestroy(&pix3); /* Transfer of data pixs --> pixd, when pixs is cloned. * pixs has its refcount reduced by 1. */ pix1 = pixRead("weasel4.16c.png"); pix2 = pixRead("feyn-fract.tif"); pix3 = pixRead("lucasta.150.jpg"); pix1c = pixClone(pix1); pix2c = pixClone(pix2); fprintf(stderr, "before clone transfer 1 --> 2\n"); pixTransferAllData(pix2, &pix1c, 0, 0); Compare(pix2, pix1, &error); pixSaveTiled(pix2, pixa, 1, 0, 30, 32); fprintf(stderr, "before clone transfer 2 --> 3\n"); pixTransferAllData(pix3, &pix2c, 0, 0); Compare(pix3, pix1, &error); pixSaveTiled(pix3, pixa, 1, 0, 30, 32); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); /* Extraction of data when pixs is not cloned, putting * the data into a new template of pixs. */ pix2 = pixRead("feyn-fract.tif"); fprintf(stderr, "no clone: before extraction and reinsertion of 2\n"); pix2c = pixCopy(NULL, pix2); /* for later reference */ data = pixExtractData(pix2); pix2t = pixCreateTemplateNoInit(pix2); pixFreeData(pix2t); pixSetData(pix2t, data); Compare(pix2c, pix2t, &error); pixSaveTiled(pix2t, pixa, 4, 1, 30, 32); pixDestroy(&pix2); pixDestroy(&pix2c); pixDestroy(&pix2t); /* Extraction of data when pixs is cloned, putting * a copy of the data into a new template of pixs. */ pix1 = pixRead("weasel4.16c.png"); fprintf(stderr, "clone: before extraction and reinsertion of 1\n"); pix1c = pixClone(pix1); /* bump refcount of pix1 to 2 */ data = pixExtractData(pix1); /* should make a copy of data */ pix1t = pixCreateTemplateNoInit(pix1); pixFreeData(pix1t); pixSetData(pix1t, data); Compare(pix1c, pix1t, &error); pixSaveTiled(pix1t, pixa, 1, 0, 30, 32); pixDestroy(&pix1); pixDestroy(&pix1c); pixDestroy(&pix1t); pixd = pixaDisplay(pixa, 0, 0); pixDisplay(pixd, 100, 100); pixWrite("/tmp/junkpixmem.png", pixd, IFF_PNG); pixaDestroy(&pixa); pixDestroy(&pixd); if (error) fprintf(stderr, "Fail: an error occurred\n"); else fprintf(stderr, "Success: no errors\n"); return 0; }
int main(int argc, char **argv) { l_int32 i, j, w, h, empty; l_uint32 redval, greenval; l_float32 f; L_WSHED *wshed; PIX *pixs, *pixc, *pixd; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pix8; PIXA *pixac; PTA *pta; static char mainName[] = "watershedtest"; if (argc != 1) return ERROR_INT(" Syntax: watershedtest", mainName, 1); pixac = pixaCreate(0); pixs = pixCreate(500, 500, 8); pixGetDimensions(pixs, &w, &h, NULL); for (i = 0; i < 500; i++) { for (j = 0; j < 500; j++) { #if 1 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); #else 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); #endif pixSetPixel(pixs, j, i, (l_int32) f); } } pixSaveTiled(pixs, pixac, 1.0, 1, 10, 32); pixWrite("/tmp/pattern.png", pixs, IFF_PNG); startTimer(); pixLocalExtrema(pixs, 0, 0, &pix1, &pix2); fprintf(stderr, "Time for extrema: %7.3f\n", stopTimer()); pixSetOrClearBorder(pix1, 2, 2, 2, 2, PIX_CLR); composeRGBPixel(255, 0, 0, &redval); composeRGBPixel(0, 255, 0, &greenval); pixc = pixConvertTo32(pixs); pixPaintThroughMask(pixc, pix2, 0, 0, greenval); pixPaintThroughMask(pixc, pix1, 0, 0, redval); pixSaveTiled(pixc, pixac, 1.0, 0, 10, 32); pixWrite("/tmp/pixc.png", pixc, IFF_PNG); pixSaveTiled(pix1, pixac, 1.0, 0, 10, 32); pixSelectMinInConnComp(pixs, pix1, &pta, NULL); /* ptaWriteStream(stderr, pta, 1); */ pix3 = pixGenerateFromPta(pta, w, h); pixSaveTiled(pix3, pixac, 1.0, 1, 10, 32); pix4 = pixConvertTo32(pixs); pixPaintThroughMask(pix4, pix3, 0, 0, greenval); pixSaveTiled(pix4, pixac, 1.0, 0, 10, 32); pix5 = pixRemoveSeededComponents(NULL, pix3, pix1, 8, 2); pixSaveTiled(pix5, pixac, 1.0, 0, 10, 32); pixZero(pix5, &empty); fprintf(stderr, "Is empty? %d\n", empty); pixDestroy(&pix4); pixDestroy(&pix5); wshed = wshedCreate(pixs, pix3, 10, 0); startTimer(); wshedApply(wshed); fprintf(stderr, "Time for wshed: %7.3f\n", stopTimer()); pix6 = pixaDisplayRandomCmap(wshed->pixad, w, h); pixSaveTiled(pix6, pixac, 1.0, 1, 10, 32); numaWriteStream(stderr, wshed->nalevels); pix7 = wshedRenderFill(wshed); pixSaveTiled(pix7, pixac, 1.0, 0, 10, 32); pix8 = wshedRenderColors(wshed); pixSaveTiled(pix8, pixac, 1.0, 0, 10, 32); wshedDestroy(&wshed); pixd = pixaDisplay(pixac, 0, 0); pixDisplay(pixd, 100, 100); pixWrite("/tmp/wshed.png", pixd, IFF_PNG); pixDestroy(&pixd); pixaDestroy(&pixac); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix6); pixDestroy(&pix7); pixDestroy(&pix8); pixDestroy(&pixs); pixDestroy(&pixc); ptaDestroy(&pta); return 0; }
int main(int argc, char **argv) { char *infile; l_int32 w, d, threshval, ival, newval; l_uint32 val; PIX *pixs, *pixg, *pixg2; PIX *pix1, *pix2; PIXA *pixa; static char mainName[] = "binarize_set"; if (argc != 2) return ERROR_INT(" Syntax: binarize_set infile", mainName, 1); infile = argv[1]; pixa = pixaCreate(5); pixs = pixRead(infile); pixGetDimensions(pixs, &w, NULL, &d); pixSaveTiled(pixs, pixa, 1.0, 1, 50, 32); pixDisplay(pixs, 100, 0); #if ALL /* 1. Standard background normalization with a global threshold. */ pixg = pixConvertTo8(pixs, 0); pix1 = pixBackgroundNorm(pixg, NULL, NULL, 10, 15, 100, 50, 255, 2, 2); pix2 = pixThresholdToBinary(pix1, 160); pixWrite("/tmp/binar1.png", pix2, IFF_PNG); pixDisplay(pix2, 100, 0); pixSaveTiled(pix2, pixa, 1.0, 1, 50, 32); pixDestroy(&pixg); pixDestroy(&pix1); pixDestroy(&pix2); #endif #if ALL /* 2. Background normalization followed by Otsu thresholding. Otsu * binarization attempts to split the image into two roughly equal * sets of pixels, and it does a very poor job when there are large * amounts of dark background. By doing a background normalization * first (to get the background near 255), we remove this problem. * Then we use a modified Otsu to estimate the best global * threshold on the normalized image. */ 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); pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32); pixWrite("/tmp/binar2.png", pix1, IFF_PNG); pixDisplay(pix1, 100, 200); pixDestroy(&pixg); pixDestroy(&pix1); #endif #if ALL /* 3. Background normalization with Otsu threshold estimation and * masking for threshold selection. */ pixg = pixConvertTo8(pixs, 0); pix1 = pixMaskedThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100, 50, 2, 2, 0.10, &threshval); fprintf(stderr, "thresh val = %d\n", threshval); pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32); pixWrite("/tmp/binar3.png", pix1, IFF_PNG); pixDisplay(pix1, 100, 400); pixDestroy(&pixg); pixDestroy(&pix1); #endif #if ALL /* 4. Background normalization followed by Sauvola binarization */ if (d == 32) pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1); else pixg = pixConvertTo8(pixs, 0); pixg2 = pixContrastNorm(NULL, pixg, 20, 20, 130, 2, 2); pixSauvolaBinarizeTiled(pixg2, 25, 0.40, 1, 1, NULL, &pix1); pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32); pixWrite("/tmp/binar4.png", pix1, IFF_PNG); pixDisplay(pix1, 100, 600); pixDestroy(&pixg); pixDestroy(&pixg2); pixDestroy(&pix1); #endif #if ALL /* 5. Contrast normalization followed by background normalization, and * thresholding. */ if (d == 32) pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1); else pixg = pixConvertTo8(pixs, 0); pixOtsuAdaptiveThreshold(pixg, 5000, 5000, 0, 0, 0.1, &pix1, NULL); 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); pixDestroy(&pix1); pixContrastNorm(pixg, pixg, 50, 50, 130, 2, 2); pixg2 = pixBackgroundNorm(pixg, NULL, NULL, 20, 20, 70, 40, 200, 2, 2); ival = L_MIN(ival, 110); pix1 = pixThresholdToBinary(pixg2, ival); pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32); pixWrite("/tmp/binar5.png", pix1, IFF_PNG); pixDisplay(pix1, 100, 800); pixDestroy(&pixg); pixDestroy(&pixg2); pixDestroy(&pix1); #endif pix1 = pixaDisplayTiledInRows(pixa, 32, w + 100, 1.0, 0, 30, 2); pixWrite("/tmp/binar6.png", pix1, IFF_PNG); pixDisplay(pix1, 1000, 0); pixDestroy(&pix1); pixaDestroy(&pixa); pixDestroy(&pixs); return 0; }
main(int argc, char **argv) { char *str; l_int32 i, j, same, ok; l_float32 sum, avediff, rmsdiff; L_KERNEL *kel1, *kel2, *kel3, *kel4, *kelx, *kely; BOX *box; PIX *pix, *pixs, *pixb, *pixg, *pixr, *pixd, *pixp, *pixt; PIX *pixt1, *pixt2, *pixt3; PIXA *pixa; SARRAY *sa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixa = pixaCreate(0); /* Test creating from a string */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = kernelDisplayInPix(kel1, 41, 2); pixWrite("/tmp/pixkern.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/pixkern.png"); /* 0 */ pixSaveTiled(pixd, pixa, 1, 1, 20, 8); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test read/write for kernel. Note that both get * compared to the same golden file, which is * overwritten with a copy of /tmp/kern2.kel */ kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); kernelWrite("/tmp/kern1.kel", kel1); regTestCheckFile(rp, "/tmp/kern1.kel"); /* 1 */ kel2 = kernelRead("/tmp/kern1.kel"); kernelWrite("/tmp/kern2.kel", kel2); regTestCheckFile(rp, "/tmp/kern2.kel"); /* 2 */ regTestCompareFiles(rp, 1, 2); /* 3 */ kernelDestroy(&kel1); kernelDestroy(&kel2); /* Test creating from a file */ sa = sarrayCreate(0); sarrayAddString(sa, (char *)"# small 3x3 kernel", L_COPY); sarrayAddString(sa, (char *)"3 5", L_COPY); sarrayAddString(sa, (char *)"1 2", L_COPY); sarrayAddString(sa, (char *)"20.5 50 80 50 20", L_COPY); sarrayAddString(sa, (char *)"82. 120 180 120 80", L_COPY); sarrayAddString(sa, (char *)"22.1 50 80 50 20", L_COPY); str = sarrayToString(sa, 1); l_binaryWrite("/tmp/kernfile.kel", "w", str, strlen(str)); kel2 = kernelCreateFromFile("/tmp/kernfile.kel"); pixd = kernelDisplayInPix(kel2, 41, 2); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker1.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker1.png"); /* 4 */ pixDestroy(&pixd); sarrayDestroy(&sa); lept_free(str); kernelDestroy(&kel2); /* Test creating from a pix */ pixt = pixCreate(5, 3, 8); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 0, 50); pixSetPixel(pixt, 2, 0, 80); pixSetPixel(pixt, 3, 0, 50); pixSetPixel(pixt, 4, 0, 20); pixSetPixel(pixt, 0, 1, 80); pixSetPixel(pixt, 1, 1, 120); pixSetPixel(pixt, 2, 1, 180); pixSetPixel(pixt, 3, 1, 120); pixSetPixel(pixt, 4, 1, 80); pixSetPixel(pixt, 0, 0, 20); pixSetPixel(pixt, 1, 2, 50); pixSetPixel(pixt, 2, 2, 80); pixSetPixel(pixt, 3, 2, 50); pixSetPixel(pixt, 4, 2, 20); kel3 = kernelCreateFromPix(pixt, 1, 2); pixd = kernelDisplayInPix(kel3, 41, 2); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker2.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker2.png"); /* 5 */ pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel3); /* Test convolution with kel1 */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); pixSaveTiled(pixg, pixa, 1, 1, 20, 0); kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr); pixd = pixConvolve(pixg, kel1, 8, 1); pixSaveTiled(pixd, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker3.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker3.png"); /* 6 */ pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); kernelDestroy(&kel1); /* Test convolution with flat rectangular kel; also test * block convolution with tiling. */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN); kel2 = makeFlatKernel(11, 11, 5, 5); pixd = pixConvolve(pixg, kel2, 8, 1); pixSaveTiled(pixd, pixa, 1, 1, 20, 0); pixWrite("/tmp/ker4.png", pixd, IFF_PNG); regTestCheckFile(rp, "/tmp/ker4.png"); /* 7 */ pixt = pixBlockconv(pixg, 5, 5); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5.png"); /* 8 */ if (rp->display) pixCompareGray(pixd, pixt, L_COMPARE_ABS_DIFF, GPLOT_X11, NULL, NULL, NULL, NULL); pixt2 = pixBlockconvTiled(pixg, 5, 5, 3, 6); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker5a.png", pixt2, IFF_PNG); regTestCheckFile(rp, "/tmp/ker5a.png"); /* 9 */ pixDestroy(&pixt2); ok = TRUE; for (i = 1; i <= 7; i++) { for (j = 1; j <= 7; j++) { if (i == 1 && j == 1) continue; pixt2 = pixBlockconvTiled(pixg, 5, 5, j, i); pixEqual(pixt2, pixd, &same); if (!same) { fprintf(stderr," Error for nx = %d, ny = %d\n", j, i); ok = FALSE; } pixDestroy(&pixt2); } } if (ok) fprintf(stderr, "OK: Tiled results identical to pixConvolve()\n"); else fprintf(stderr, "ERROR: Tiled results not identical to pixConvolve()\n"); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); pixDestroy(&pixt); kernelDestroy(&kel2); /* Do another flat rectangular test; this time with white at edge. * About 1% of the pixels near the image edge differ by 1 between * the pixConvolve() and pixBlockconv(). For what it's worth, * pixConvolve() gives the more accurate result; namely, 255 for * pixels at the edge. */ pix = pixRead("pageseg1.tif"); box = boxCreate(100, 100, 2260, 3160); pixb = pixClipRectangle(pix, box, NULL); pixs = pixScaleToGray4(pixb); kel3 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt = pixConvolve(pixs, kel3, 8, 1); fprintf(stderr, "Generic convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt, pixa, 1, 1, 20, 0); pixWrite("/tmp/conv1.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/conv1.png"); /* 10 */ startTimer(); pixt2 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Flat block convolution time: %5.3f sec\n", stopTimer()); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv2.png", pixt2, IFF_PNG); /* ditto */ regTestCheckFile(rp, "/tmp/conv2.png"); /* 11 */ pixCompareGray(pixt, pixt2, L_COMPARE_ABS_DIFF, GPLOT_PNG, NULL, &avediff, &rmsdiff, NULL); #ifndef _WIN32 sleep(1); /* give gnuplot time to write out the file */ #else Sleep(1000); #endif /* _WIN32 */ pixp = pixRead("/tmp/grayroot.png"); pixSaveTiled(pixp, pixa, 1, 0, 20, 0); pixWrite("/tmp/conv3.png", pixp, IFF_PNG); regTestCheckFile(rp, "/tmp/conv3.png"); /* 12 */ fprintf(stderr, "Ave diff = %6.4f, RMS diff = %6.4f\n", avediff, rmsdiff); if (avediff <= 0.01) fprintf(stderr, "OK: avediff = %6.4f <= 0.01\n", avediff); else fprintf(stderr, "Bad?: avediff = %6.4f > 0.01\n", avediff); pixDestroy(&pixt); pixDestroy(&pixt2); pixDestroy(&pixs); pixDestroy(&pixp); pixDestroy(&pix); pixDestroy(&pixb); boxDestroy(&box); kernelDestroy(&kel3); /* Do yet another set of flat rectangular tests, this time * on an RGB image */ pixs = pixRead("test24.jpg"); kel4 = makeFlatKernel(7, 7, 3, 3); startTimer(); pixt1 = pixConvolveRGB(pixs, kel4); fprintf(stderr, "Time 7x7 non-separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv4.jpg", pixt1, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv4.jpg"); /* 13 */ kelx = makeFlatKernel(1, 7, 0, 3); kely = makeFlatKernel(7, 1, 3, 0); startTimer(); pixt2 = pixConvolveRGBSep(pixs, kelx, kely); fprintf(stderr, "Time 7x1,1x7 separable: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv5.jpg", pixt2, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv5.jpg"); /* 14 */ startTimer(); pixt3 = pixBlockconv(pixs, 3, 3); fprintf(stderr, "Time 7x7 blockconv: %7.3f sec\n", stopTimer()); pixWrite("/tmp/conv6.jpg", pixt3, IFF_JFIF_JPEG); regTestCheckFile(rp, "/tmp/conv6.jpg"); /* 15 */ regTestComparePix(rp, pixt1, pixt2); /* 16 */ regTestCompareSimilarPix(rp, pixt2, pixt3, 15, 0.0005, 0); /* 17 */ pixDestroy(&pixs); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); kernelDestroy(&kel4); kernelDestroy(&kelx); kernelDestroy(&kely); /* Test generation and convolution with gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeGaussianKernel(5, 5, 3.0, 5.0); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 1); pixt2 = pixConvolve(pixs, kel1, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker6.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker6.png"); /* 18 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kel1, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); /* Test generation and convolution with separable gaussian kernel */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); makeGaussianKernelSep(5, 5, 3.0, 5.0, &kelx, &kely); kernelGetSum(kelx, &sum); fprintf(stderr, "Sum for x gaussian kernel = %f\n", sum); kernelGetSum(kely, &sum); fprintf(stderr, "Sum for y gaussian kernel = %f\n", sum); kernelWrite("/tmp/gauss.kelx", kelx); kernelWrite("/tmp/gauss.kely", kely); pixt = pixConvolveSep(pixs, kelx, kely, 8, 1); pixt2 = pixConvolveSep(pixs, kelx, kely, 16, 0); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixSaveTiled(pixt2, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker7.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker7.png"); /* 19 */ pixDestroy(&pixt); pixDestroy(&pixt2); pixt = kernelDisplayInPix(kelx, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); pixt = kernelDisplayInPix(kely, 25, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kelx); kernelDestroy(&kely); pixDestroy(&pixs); /* Test generation and convolution with diff of gaussians kernel */ /* pixt = pixRead("marge.jpg"); pixs = pixConvertRGBToLuminance(pixt); pixDestroy(&pixt); */ pixs = pixRead("test8.jpg"); pixSaveTiled(pixs, pixa, 1, 1, 20, 0); kel1 = makeDoGKernel(7, 7, 1.5, 2.7); kernelGetSum(kel1, &sum); fprintf(stderr, "Sum for DoG kernel = %f\n", sum); kernelWrite("/tmp/dog.kel", kel1); pixt = pixConvolve(pixs, kel1, 8, 0); /* pixInvert(pixt, pixt); */ pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixWrite("/tmp/ker8.png", pixt, IFF_PNG); regTestCheckFile(rp, "/tmp/ker8.png"); /* 20 */ pixDestroy(&pixt); pixt = kernelDisplayInPix(kel1, 20, 2); pixSaveTiled(pixt, pixa, 1, 0, 20, 0); pixDestroy(&pixt); kernelDestroy(&kel1); pixDestroy(&pixs); pixd = pixaDisplay(pixa, 0, 0); pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); pixWrite("/tmp/kernel.jpg", pixd, IFF_JFIF_JPEG); pixDestroy(&pixd); pixaDestroy(&pixa); regTestCleanup(rp); return 0; }
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_int32 i, d, h; l_float32 rat; PIX *pixs, *pixgb, *pixt1, *pixt2, *pixt3, *pixt4, *pixg, *pixd; PIXA *pixa; PTA *ptas, *ptad; static char mainName[] = "bilinear_reg"; if (argc != 1) exit(ERROR_INT(" Syntax: bilinear_reg", mainName, 1)); pixs = pixRead("feyn.tif"); pixg = pixScaleToGray3(pixs); #if ALL /* Test non-invertability of sampling */ pixa = pixaCreate(0); for (i = 1; i < 3; i++) { pixgb = pixAddBorder(pixg, ADDED_BORDER_PIXELS, 255); MakePtas(i, &ptas, &ptad); pixt1 = pixBilinearSampledPta(pixgb, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt1, pixa, 2, 1, 20, 8); pixt2 = pixBilinearSampledPta(pixt1, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 2, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS); pixInvert(pixd, pixd); pixXor(pixd, pixd, pixg); pixSaveTiled(pixd, pixa, 2, 0, 20, 0); if (i == 0) pixWrite("/tmp/junksamp.png", pixt1, IFF_PNG); pixDestroy(&pixgb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkbilin1.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 300); pixDestroy(&pixt1); pixaDestroy(&pixa); #endif #if ALL /* Test non-invertability of interpolation */ pixa = pixaCreate(0); for (i = 1; i < 3; i++) { pixgb = pixAddBorder(pixg, ADDED_BORDER_PIXELS, 255); MakePtas(i, &ptas, &ptad); pixt1 = pixBilinearPta(pixgb, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt1, pixa, 2, 1, 20, 8); pixt2 = pixBilinearPta(pixt1, ptas, ptad, L_BRING_IN_WHITE); pixSaveTiled(pixt2, pixa, 2, 0, 20, 0); pixd = pixRemoveBorder(pixt2, ADDED_BORDER_PIXELS); pixInvert(pixd, pixd); pixXor(pixd, pixd, pixg); pixSaveTiled(pixd, pixa, 2, 0, 20, 0); if (i == 0) pixWrite("/tmp/junkinterp.png", pixt1, IFF_PNG); pixDestroy(&pixgb); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixd); ptaDestroy(&ptas); ptaDestroy(&ptad); } pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkbilin2.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 300); pixDestroy(&pixt1); pixaDestroy(&pixa); #endif #if ALL /* test with large distortion and inversion */ MakePtas(0, &ptas, &ptad); pixa = pixaCreate(0); startTimer(); pixt1 = pixBilinearSampledPta(pixg, ptas, ptad, L_BRING_IN_WHITE); fprintf(stderr, " Time for pixBilinearSampled(): %6.2f sec\n", stopTimer()); pixSaveTiled(pixt1, pixa, 2, 1, 20, 8); startTimer(); pixt2 = pixBilinearPta(pixg, ptas, ptad, L_BRING_IN_WHITE); fprintf(stderr, " Time for pixBilinearInterpolated(): %6.2f sec\n", stopTimer()); pixSaveTiled(pixt2, pixa, 2, 0, 20, 8); pixt3 = pixBilinearSampledPta(pixt1, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt3, pixa, 2, 0, 20, 8); pixt4 = pixBilinearPta(pixt2, ptad, ptas, L_BRING_IN_WHITE); pixSaveTiled(pixt4, pixa, 2, 0, 20, 8); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); pixDestroy(&pixt4); pixt1 = pixaDisplay(pixa, 0, 0); pixWrite("/tmp/junkbilin3.png", pixt1, IFF_PNG); pixDisplay(pixt1, 100, 300); pixDestroy(&pixt1); pixaDestroy(&pixa); pixDestroy(&pixs); pixDestroy(&pixg); ptaDestroy(&ptas); ptaDestroy(&ptad); #endif return 0; }