/*! * dewarpDestroy() * * Input: &dew (<will be set to null before returning>) * Return: void */ void dewarpDestroy(L_DEWARP **pdew) { L_DEWARP *dew; PROCNAME("dewarpDestroy"); if (pdew == NULL) { L_WARNING("ptr address is null!", procName); return; } if ((dew = *pdew) == NULL) return; pixDestroy(&dew->pixs); pixDestroy(&dew->pixd); fpixDestroy(&dew->sampvdispar); fpixDestroy(&dew->samphdispar); fpixDestroy(&dew->fullvdispar); fpixDestroy(&dew->fullhdispar); numaDestroy(&dew->naflats); numaDestroy(&dew->nacurves); FREE(dew); *pdew = NULL; return; }
/*! * dewarpMinimize() * * Input: dew * Return: 0 if OK, 1 on error * * Notes: * (1) This removes all data that is not needed for serialization. * It keeps the subsampled disparity array(s), so the full * resolution arrays can be reconstructed. */ l_int32 dewarpMinimize(L_DEWARP *dew) { L_DEWARP *dewt; PROCNAME("dewarpMinimize"); if (!dew) return ERROR_INT("dew not defined", procName, 1); /* If dew is a ref, minimize the actual dewarp */ if (dew->hasref) dewt = dewarpaGetDewarp(dew->dewa, dew->refpage); else dewt = dew; if (!dewt) return ERROR_INT("dewt not found", procName, 1); pixDestroy(&dewt->pixs); fpixDestroy(&dewt->fullvdispar); fpixDestroy(&dewt->fullhdispar); numaDestroy(&dewt->namidys); numaDestroy(&dewt->nacurves); return 0; }
int main(int argc, char **argv) { char *filein; l_int32 ncontours; FPIX *fpix; PIX *pix; static char mainName[] = "fpixcontours"; if (argc != 2 && argc != 3) { fprintf(stderr, "Syntax: fpixcontours filein [ncontours]\n"); return 1; } filein = argv[1]; if (argc == 2) ncontours = 40; else /* argc == 3 */ ncontours = atoi(argv[2]); setLeptDebugOK(1); lept_mkdir("lept/fpix"); if ((fpix = fpixRead(filein)) == NULL) return ERROR_INT(mainName, "fpix not read", 1); pix = fpixAutoRenderContours(fpix, ncontours); pixWrite(fileout, pix, IFF_PNG); pixDisplay(pix, 100, 100); pixDestroy(&pix); fpixDestroy(&fpix); return 0; }
/*! * dewarpMinimize() * * Input: dew * Return: 0 if OK, 1 on error * * Notes: * (1) This removes all data that is not needed for serialization. * It keeps the subsampled disparity array(s), so the full * resolution arrays can be reconstructed. */ l_int32 dewarpMinimize(L_DEWARP *dew) { PROCNAME("dewarpMinimize"); if (!dew) return ERROR_INT("dew not defined", procName, 1); pixDestroy(&dew->pixs); pixDestroy(&dew->pixd); fpixDestroy(&dew->fullvdispar); fpixDestroy(&dew->fullhdispar); numaDestroy(&dew->naflats); numaDestroy(&dew->nacurves); return 0; }
/*! * \brief fpixaDisplayQuadtree() * * \param[in] fpixa mean, variance or root variance * \param[in] factor replication factor at lowest level * \param[in] fontsize 4, ... 20 * \return pixd 8 bpp, mosaic of quadtree images, or NULL on error * * <pre> * Notes: * (1) The mean and root variance fall naturally in the 8 bpp range, * but the variance is typically outside the range. This * function displays 8 bpp pix clipped to 255, so the image * pixels will mostly be 255 (white). * </pre> */ PIX * fpixaDisplayQuadtree(FPIXA *fpixa, l_int32 factor, l_int32 fontsize) { char buf[256]; l_int32 nlevels, i, mag, w; L_BMF *bmf; FPIX *fpix; PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixd; PIXA *pixat; PROCNAME("fpixaDisplayQuadtree"); if (!fpixa) return (PIX *)ERROR_PTR("fpixa not defined", procName, NULL); if ((nlevels = fpixaGetCount(fpixa)) == 0) return (PIX *)ERROR_PTR("pixas empty", procName, NULL); if ((bmf = bmfCreate(NULL, fontsize)) == NULL) L_ERROR("bmf not made; text will not be added", procName); pixat = pixaCreate(nlevels); for (i = 0; i < nlevels; i++) { fpix = fpixaGetFPix(fpixa, i, L_CLONE); pixt1 = fpixConvertToPix(fpix, 8, L_CLIP_TO_ZERO, 0); mag = factor * (1 << (nlevels - i - 1)); pixt2 = pixExpandReplicate(pixt1, mag); pixt3 = pixConvertTo32(pixt2); snprintf(buf, sizeof(buf), "Level %d\n", i); pixt4 = pixAddSingleTextblock(pixt3, bmf, buf, 0xff000000, L_ADD_BELOW, NULL); pixaAddPix(pixat, pixt4, L_INSERT); fpixDestroy(&fpix); pixDestroy(&pixt1); pixDestroy(&pixt2); pixDestroy(&pixt3); } w = pixGetWidth(pixt4); pixd = pixaDisplayTiledInRows(pixat, 32, nlevels * (w + 80), 1.0, 0, 30, 2); pixaDestroy(&pixat); bmfDestroy(&bmf); return pixd; }
l_int32 main(int argc, char **argv) { l_int32 irval, igval, ibval; l_float32 rval, gval, bval, fract, fgfract; L_BMF *bmf; BOX *box; BOXA *boxa; FPIX *fpix; PIX *pixs, *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7; PIX *pix8, *pix9, *pix10, *pix11, *pix12, *pix13, *pix14, *pix15; PIXA *pixa; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixa = pixaCreate(0); pixs = pixRead("breviar38.150.jpg"); /* pixs = pixRead("breviar32.150.jpg"); */ pixaAddPix(pixa, pixs, L_CLONE); regTestWritePixAndCheck(rp, pixs, IFF_JFIF_JPEG); /* 0 */ pixDisplayWithTitle(pixs, 0, 0, "Input image", rp->display); /* Extract the blue component, which is small in all the text * regions, including in the highlight color region */ pix1 = pixGetRGBComponent(pixs, COLOR_BLUE); pixaAddPix(pixa, pix1, L_CLONE); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 1 */ pixDisplayWithTitle(pix1, 200, 0, "Blue component", rp->display); /* Do a background normalization, with the background set to * approximately 200 */ pix2 = pixBackgroundNormSimple(pix1, NULL, NULL); pixaAddPix(pixa, pix2, L_COPY); regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 2 */ pixDisplayWithTitle(pix2, 400, 0, "BG normalized to 200", rp->display); /* Do a linear transform on the gray pixels, with 50 going to * black and 160 going to white. 50 is sufficiently low to * make both the red and black print quite dark. Quantize * to a few equally spaced gray levels. This is the image * to which highlight color will be applied. */ pixGammaTRC(pix2, pix2, 1.0, 50, 160); pix3 = pixThresholdOn8bpp(pix2, 7, 1); pixaAddPix(pixa, pix3, L_CLONE); regTestWritePixAndCheck(rp, pix3, IFF_JFIF_JPEG); /* 3 */ pixDisplayWithTitle(pix3, 600, 0, "Basic quantized with white bg", rp->display); /* Identify the regions of red text. First, make a mask * consisting of all pixels such that (R-B)/B is larger * than 2.0. This will have all the red, plus a lot of * the dark pixels. */ fpix = pixComponentFunction(pixs, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0); pix4 = fpixThresholdToPix(fpix, 2.0); pixInvert(pix4, pix4); /* red plus some dark text */ pixaAddPix(pixa, pix4, L_CLONE); regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 4 */ pixDisplayWithTitle(pix4, 800, 0, "Red plus dark pixels", rp->display); /* Make a mask consisting of all the red and background pixels */ pix5 = pixGetRGBComponent(pixs, COLOR_RED); pix6 = pixThresholdToBinary(pix5, 128); pixInvert(pix6, pix6); /* red plus background (white) */ /* Intersect the two masks to get a mask consisting of pixels * that are almost certainly red. This is the seed. */ pix7 = pixAnd(NULL, pix4, pix6); /* red only (seed) */ pixaAddPix(pixa, pix7, L_COPY); regTestWritePixAndCheck(rp, pix7, IFF_PNG); /* 5 */ pixDisplayWithTitle(pix7, 0, 600, "Seed for red color", rp->display); /* Make the clipping mask by thresholding the image with * the background cleaned to white. */ pix8 = pixThresholdToBinary(pix2, 230); /* mask */ pixaAddPix(pixa, pix8, L_CLONE); regTestWritePixAndCheck(rp, pix8, IFF_PNG); /* 6 */ pixDisplayWithTitle(pix8, 200, 600, "Clipping mask for red components", rp->display); /* Fill into the mask from the seed */ pixSeedfillBinary(pix7, pix7, pix8, 8); /* filled: red plus touching */ regTestWritePixAndCheck(rp, pix7, IFF_PNG); /* 7 */ pixDisplayWithTitle(pix7, 400, 600, "Red component mask filled", rp->display); /* Remove long horizontal and vertical lines from the filled result */ pix9 = pixMorphSequence(pix7, "o40.1", 0); pixSubtract(pix7, pix7, pix9); /* remove long horizontal lines */ pixDestroy(&pix9); pix9 = pixMorphSequence(pix7, "o1.40", 0); pixSubtract(pix7, pix7, pix9); /* remove long vertical lines */ /* Close the regions to be colored */ pix10 = pixMorphSequence(pix7, "c5.1", 0); pixaAddPix(pixa, pix10, L_CLONE); regTestWritePixAndCheck(rp, pix10, IFF_PNG); /* 8 */ pixDisplayWithTitle(pix10, 600, 600, "Components defining regions allowing coloring", rp->display); /* Sanity check on amount to be colored. Only accept images * with less than 10% of all the pixels with highlight color */ pixForegroundFraction(pix10, &fgfract); if (fgfract >= 0.10) { L_INFO("too much highlighting: fract = %6.3f; removing it\n", rp->testname, fgfract); pixClearAll(pix10); pixSetPixel(pix10, 0, 0, 1); } /* Get the bounding boxes of the regions to be colored */ boxa = pixConnCompBB(pix10, 8); /* Get a color to paint that is representative of the * actual highlight color in the image. Scale each * color component up from the average by an amount necessary * to saturate the red. Then divide the green and * blue components by 2.0. */ pixGetAverageMaskedRGB(pixs, pix7, 0, 0, 1, L_MEAN_ABSVAL, &rval, &gval, &bval); fract = 255.0 / rval; irval = lept_roundftoi(fract * rval); igval = lept_roundftoi(fract * gval / 2.0); ibval = lept_roundftoi(fract * bval / 2.0); fprintf(stderr, "(r,g,b) = (%d,%d,%d)\n", irval, igval, ibval); /* Color the quantized gray version in the selected regions */ pix11 = pixColorGrayRegions(pix3, boxa, L_PAINT_DARK, 220, irval, igval, ibval); pixaAddPix(pixa, pix11, L_CLONE); regTestWritePixAndCheck(rp, pix11, IFF_PNG); /* 9 */ pixDisplayWithTitle(pix11, 800, 600, "Final colored result", rp->display); pixaAddPix(pixa, pixs, L_CLONE); /* Test colorization on gray and cmapped gray */ pix12 = pixColorGrayRegions(pix2, boxa, L_PAINT_DARK, 220, 0, 255, 0); pixaAddPix(pixa, pix12, L_CLONE); regTestWritePixAndCheck(rp, pix12, IFF_PNG); /* 10 */ pixDisplayWithTitle(pix12, 900, 600, "Colorizing boxa gray", rp->display); box = boxCreate(200, 200, 250, 350); pix13 = pixCopy(NULL, pix2); pixColorGray(pix13, box, L_PAINT_DARK, 220, 0, 0, 255); pixaAddPix(pixa, pix13, L_CLONE); regTestWritePixAndCheck(rp, pix13, IFF_PNG); /* 11 */ pixDisplayWithTitle(pix13, 1000, 600, "Colorizing box gray", rp->display); pix14 = pixThresholdTo4bpp(pix2, 6, 1); pix15 = pixColorGrayRegions(pix14, boxa, L_PAINT_DARK, 220, 0, 0, 255); pixaAddPix(pixa, pix15, L_CLONE); regTestWritePixAndCheck(rp, pix15, IFF_PNG); /* 12 */ pixDisplayWithTitle(pix15, 1100, 600, "Colorizing boxa cmap", rp->display); pixColorGrayCmap(pix14, box, L_PAINT_DARK, 0, 255, 255); pixaAddPix(pixa, pix14, L_CLONE); regTestWritePixAndCheck(rp, pix14, IFF_PNG); /* 13 */ pixDisplayWithTitle(pix14, 1200, 600, "Colorizing box cmap", rp->display); boxDestroy(&box); /* Generate a pdf of the intermediate results */ lept_mkdir("lept"); L_INFO("Writing to /tmp/lept/colorize.pdf\n", rp->testname); pixaConvertToPdf(pixa, 90, 1.0, 0, 0, "Colorizing highlighted text", "/tmp/lept/colorize.pdf"); pixaDestroy(&pixa); fpixDestroy(&fpix); boxDestroy(&box); boxaDestroy(&boxa); pixDestroy(&pixs); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); pixDestroy(&pix7); pixDestroy(&pix8); pixDestroy(&pix9); pixDestroy(&pix10); pixDestroy(&pix11); pixDestroy(&pix12); pixDestroy(&pix13); pixDestroy(&pix14); pixDestroy(&pix15); /* Test the color detector */ pixa = pixaCreate(7); bmf = bmfCreate("./fonts", 4); pix1 = TestForRedColor(rp, "brev06.75.jpg", 1, bmf); /* 14 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev10.75.jpg", 0, bmf); /* 15 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev14.75.jpg", 1, bmf); /* 16 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev20.75.jpg", 1, bmf); /* 17 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev36.75.jpg", 0, bmf); /* 18 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev53.75.jpg", 1, bmf); /* 19 */ pixaAddPix(pixa, pix1, L_INSERT); pix1 = TestForRedColor(rp, "brev56.75.jpg", 1, bmf); /* 20 */ pixaAddPix(pixa, pix1, L_INSERT); /* Generate a pdf of the color detector results */ L_INFO("Writing to /tmp/lept/colordetect.pdf\n", rp->testname); pixaConvertToPdf(pixa, 45, 1.0, 0, 0, "Color detection", "/tmp/lept/colordetect.pdf"); pixaDestroy(&pixa); bmfDestroy(&bmf); return regTestCleanup(rp); }
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); }
int main(int argc, char **argv) { l_int32 i, j, sizex, sizey, bias; FPIX *fpixv, *fpixrv; L_KERNEL *kel1, *kel2, *kel3x, *kel3y; PIX *pixs, *pixacc, *pixg, *pixt, *pixd; PIX *pixb, *pixm, *pixms, *pixrv, *pix1, *pix2, *pix3, *pix4; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* Test pixBlockconvGray() on 8 bpp */ pixs = pixRead("test8.jpg"); pixacc = pixBlockconvAccum(pixs); pixd = pixBlockconvGray(pixs, pixacc, 3, 5); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 0 */ pixDisplayWithTitle(pixd, 100, 0, NULL, rp->display); pixDestroy(&pixacc); pixDestroy(&pixd); /* Test pixBlockconv() on 8 bpp */ pixd = pixBlockconv(pixs, 9, 8); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 1 */ pixDisplayWithTitle(pixd, 200, 0, NULL, rp->display); pixDestroy(&pixd); pixDestroy(&pixs); /* Test pixBlockrank() on 1 bpp */ pixs = pixRead("test1.png"); pixacc = pixBlockconvAccum(pixs); for (i = 0; i < 3; i++) { pixd = pixBlockrank(pixs, pixacc, 4, 4, 0.25 + 0.25 * i); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 2 - 4 */ pixDisplayWithTitle(pixd, 300 + 100 * i, 0, NULL, rp->display); pixDestroy(&pixd); } /* Test pixBlocksum() on 1 bpp */ pixd = pixBlocksum(pixs, pixacc, 16, 16); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 5 */ pixDisplayWithTitle(pixd, 700, 0, NULL, rp->display); pixDestroy(&pixd); pixDestroy(&pixacc); pixDestroy(&pixs); /* Test pixCensusTransform() */ pixs = pixRead("test24.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 2, COLOR_GREEN); pixd = pixCensusTransform(pixg, 10, NULL); regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 6 */ pixDisplayWithTitle(pixd, 800, 0, NULL, rp->display); pixDestroy(&pixd); /* Test generic convolution with kel1 */ kel1 = kernelCreateFromString(5, 5, 2, 2, kel1str); pixd = pixConvolve(pixg, kel1, 8, 1); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 7 */ pixDisplayWithTitle(pixd, 100, 500, NULL, rp->display); pixDestroy(&pixd); /* Test convolution with flat rectangular kel */ kel2 = kernelCreate(11, 11); kernelSetOrigin(kel2, 5, 5); for (i = 0; i < 11; i++) { for (j = 0; j < 11; j++) kernelSetElement(kel2, i, j, 1); } pixd = pixConvolve(pixg, kel2, 8, 1); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 8 */ pixDisplayWithTitle(pixd, 200, 500, NULL, rp->display); pixDestroy(&pixd); kernelDestroy(&kel1); kernelDestroy(&kel2); /* Test pixBlockconv() on 32 bpp */ pixt = pixScaleBySampling(pixs, 0.5, 0.5); pixd = pixBlockconv(pixt, 4, 6); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 9 */ pixDisplayWithTitle(pixd, 300, 500, NULL, rp->display); pixDestroy(&pixt); pixDestroy(&pixs); pixDestroy(&pixg); pixDestroy(&pixd); /* Test bias convolution non-separable with kel2 */ pixs = pixRead("marge.jpg"); pixg = pixScaleRGBToGrayFast(pixs, 2, COLOR_GREEN); kel2 = kernelCreateFromString(5, 5, 2, 2, kel2str); pixd = pixConvolveWithBias(pixg, kel2, NULL, TRUE, &bias); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 10 */ pixDisplayWithTitle(pixd, 400, 500, NULL, rp->display); fprintf(stderr, "bias = %d\n", bias); kernelDestroy(&kel2); pixDestroy(&pixd); /* Test bias convolution separable with kel3x and kel3y */ kel3x = kernelCreateFromString(1, 5, 0, 2, kel3xstr); kel3y = kernelCreateFromString(7, 1, 3, 0, kel3ystr); pixd = pixConvolveWithBias(pixg, kel3x, kel3y, TRUE, &bias); regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 11 */ pixDisplayWithTitle(pixd, 500, 500, NULL, rp->display); fprintf(stderr, "bias = %d\n", bias); kernelDestroy(&kel3x); kernelDestroy(&kel3y); pixDestroy(&pixd); pixDestroy(&pixs); pixDestroy(&pixg); /* Test pixWindowedMean() and pixWindowedMeanSquare() on 8 bpp */ pixs = pixRead("feyn-fract2.tif"); pixg = pixConvertTo8(pixs, 0); sizex = 5; sizey = 20; pixb = pixAddBorderGeneral(pixg, sizex + 1, sizex + 1, sizey + 1, sizey + 1, 0); pixm = pixWindowedMean(pixb, sizex, sizey, 1, 1); pixms = pixWindowedMeanSquare(pixb, sizex, sizey, 1); regTestWritePixAndCheck(rp, pixm, IFF_JFIF_JPEG); /* 12 */ pixDisplayWithTitle(pixm, 100, 0, NULL, rp->display); pixDestroy(&pixs); pixDestroy(&pixb); /* Test pixWindowedVariance() on 8 bpp */ pixWindowedVariance(pixm, pixms, &fpixv, &fpixrv); pixrv = fpixConvertToPix(fpixrv, 8, L_CLIP_TO_ZERO, 1); regTestWritePixAndCheck(rp, pixrv, IFF_JFIF_JPEG); /* 13 */ pixDisplayWithTitle(pixrv, 100, 250, NULL, rp->display); pix1 = fpixDisplayMaxDynamicRange(fpixv); pix2 = fpixDisplayMaxDynamicRange(fpixrv); pixDisplayWithTitle(pix1, 100, 500, "Variance", rp->display); pixDisplayWithTitle(pix2, 100, 750, "RMS deviation", rp->display); regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 14 */ regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); /* 15 */ fpixDestroy(&fpixv); fpixDestroy(&fpixrv); pixDestroy(&pixm); pixDestroy(&pixms); pixDestroy(&pixrv); /* Test again all windowed functions with simpler interface */ pixWindowedStats(pixg, sizex, sizey, 0, NULL, NULL, &fpixv, &fpixrv); pix3 = fpixDisplayMaxDynamicRange(fpixv); pix4 = fpixDisplayMaxDynamicRange(fpixrv); regTestComparePix(rp, pix1, pix3); /* 16 */ regTestComparePix(rp, pix2, pix4); /* 17 */ pixDestroy(&pixg); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); fpixDestroy(&fpixv); fpixDestroy(&fpixrv); return regTestCleanup(rp); }
int main(int argc, char **argv) { FPIX *fpix1, *fpix2, *fpix3, *fpix4; PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7, *pix8; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; /* Test orthogonal rotations */ pix1 = pixRead("marge.jpg"); pix2 = pixConvertTo8(pix1, 0); fpix1 = pixConvertToFPix(pix2, 1); fpix2 = fpixRotateOrth(fpix1, 1); pix3 = fpixConvertToPix(fpix2, 8, L_CLIP_TO_ZERO, 0); pix4 = pixRotateOrth(pix2, 1); regTestComparePix(rp, pix3, pix4); /* 0 */ pixDisplayWithTitle(pix3, 100, 100, NULL, rp->display); fpix3 = fpixRotateOrth(fpix1, 2); pix5 = fpixConvertToPix(fpix3, 8, L_CLIP_TO_ZERO, 0); pix6 = pixRotateOrth(pix2, 2); regTestComparePix(rp, pix5, pix6); /* 1 */ pixDisplayWithTitle(pix5, 560, 100, NULL, rp->display); fpix4 = fpixRotateOrth(fpix1, 3); pix7 = fpixConvertToPix(fpix4, 8, L_CLIP_TO_ZERO, 0); pix8 = pixRotateOrth(pix2, 3); regTestComparePix(rp, pix7, pix8); /* 2 */ pixDisplayWithTitle(pix7, 1170, 100, NULL, rp->display); pixDisplayWithTitle(pix2, 560, 580, NULL, rp->display); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); pixDestroy(&pix7); pixDestroy(&pix8); fpixDestroy(&fpix1); fpixDestroy(&fpix2); fpixDestroy(&fpix3); fpixDestroy(&fpix4); /* Test adding various borders */ pix1 = pixRead("marge.jpg"); pix2 = pixConvertTo8(pix1, 0); fpix1 = pixConvertToFPix(pix2, 1); fpix2 = fpixAddMirroredBorder(fpix1, 21, 21, 25, 25); pix3 = fpixConvertToPix(fpix2, 8, L_CLIP_TO_ZERO, 0); pix4 = pixAddMirroredBorder(pix2, 21, 21, 25, 25); regTestComparePix(rp, pix3, pix4); /* 3 */ pixDisplayWithTitle(pix3, 100, 1000, NULL, rp->display); fpix3 = fpixAddContinuedBorder(fpix1, 21, 21, 25, 25); pix5 = fpixConvertToPix(fpix3, 8, L_CLIP_TO_ZERO, 0); pix6 = pixAddContinuedBorder(pix2, 21, 21, 25, 25); regTestComparePix(rp, pix5, pix6); /* 4 */ pixDisplayWithTitle(pix5, 750, 1000, NULL, rp->display); pixDestroy(&pix1); pixDestroy(&pix2); pixDestroy(&pix3); pixDestroy(&pix4); pixDestroy(&pix5); pixDestroy(&pix6); fpixDestroy(&fpix1); fpixDestroy(&fpix2); fpixDestroy(&fpix3); return regTestCleanup(rp); }
main(int argc, char **argv) { l_float32 sum, sumx, sumy, diff; FPIX *fpixs, *fpixs2, *fpixs3, *fpixt1, *fpixt2, *fpixg, *fpixd; L_KERNEL *kel, *kelx, *kely; PIX *pixs, *pixs2, *pixs3, *pixt, *pixd, *pixg; PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6; PIXA *pixa; 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(&pixd); pixaDestroy(&pixa); regTestCleanup(rp); pixDestroy(&pixs); pixDestroy(&pixg); kernelDestroy(&kel); kernelDestroy(&kelx); kernelDestroy(&kely); return 0; }
/*! * dewarpPopulateFullRes() * * Input: dew * pix (<optional>, to give size of actual image) * x, y (origin for generation of disparity arrays) * Return: 0 if OK, 1 on error * * Notes: * (1) If the full resolution vertical and horizontal disparity * arrays do not exist, they are built from the subsampled ones. * (2) If pixs is not given, the size of the arrays is determined * by the original image from which the sampled version was * generated. Any values of (x,y) are ignored. * (3) If pixs is given, the full resolution disparity arrays must * be large enough to accommodate it. * (a) If the arrays do not exist, the value of (x,y) determines * the origin of the full resolution arrays without extension, * relative to pixs. Thus, (x,y) gives the amount of * slope extension in (left, top). The (right, bottom) * extension is then determined by the size of pixs and * (x,y); the values should never be < 0. * (b) If the arrays exist and pixs is too large, the existing * full res arrays are destroyed and new ones are made, * again using (x,y) to determine the extension in the * four directions. */ l_int32 dewarpPopulateFullRes(L_DEWARP *dew, PIX *pix, l_int32 x, l_int32 y) { l_int32 width, height, fw, fh, deltaw, deltah, redfactor; FPIX *fpixt1, *fpixt2; PROCNAME("dewarpPopulateFullRes"); if (!dew) return ERROR_INT("dew not defined", procName, 1); if (!dew->sampvdispar) return ERROR_INT("no sampled vert disparity", procName, 1); if (x < 0) x = 0; if (y < 0) y = 0; /* Establish the target size for the full res arrays */ if (pix) pixGetDimensions(pix, &width, &height, NULL); else { width = dew->w; height = dew->h; } /* Destroy the existing arrays if they are too small */ if (dew->fullvdispar) { fpixGetDimensions(dew->fullvdispar, &fw, &fh); if (width > fw || height > fw) fpixDestroy(&dew->fullvdispar); } if (dew->fullhdispar) { fpixGetDimensions(dew->fullhdispar, &fw, &fh); if (width > fw || height > fw) fpixDestroy(&dew->fullhdispar); } /* Find the required width and height expansion deltas */ deltaw = width - dew->sampling * (dew->nx - 1) + 2; deltah = height - dew->sampling * (dew->ny - 1) + 2; redfactor = dew->redfactor; deltaw = redfactor * L_MAX(0, deltaw); deltah = redfactor * L_MAX(0, deltah); /* Generate the full res vertical array if it doesn't exist, * extending it as required to make it big enough. Use x,y * to determine the amounts on each side. */ if (!dew->fullvdispar) { fpixt1 = fpixCopy(NULL, dew->sampvdispar); if (redfactor == 2) fpixAddMultConstant(fpixt1, 0.0, (l_float32)redfactor); fpixt2 = fpixScaleByInteger(fpixt1, dew->sampling * redfactor); fpixDestroy(&fpixt1); if (deltah == 0 && deltaw == 0) { dew->fullvdispar = fpixt2; } else { dew->fullvdispar = fpixAddSlopeBorder(fpixt2, x, deltaw - x, y, deltah - y); fpixDestroy(&fpixt2); } } /* Similarly, generate the full res horizontal array if it * doesn't exist. Do this even if useboth == 0. */ if (!dew->fullhdispar && dew->samphdispar) { fpixt1 = fpixCopy(NULL, dew->samphdispar); if (redfactor == 2) fpixAddMultConstant(fpixt1, 0.0, (l_float32)redfactor); fpixt2 = fpixScaleByInteger(fpixt1, dew->sampling * redfactor); fpixDestroy(&fpixt1); if (deltah == 0 && deltaw == 0) { dew->fullhdispar = fpixt2; } else { dew->fullhdispar = fpixAddSlopeBorder(fpixt2, x, deltaw - x, y, deltah - y); fpixDestroy(&fpixt2); } } return 0; }
l_int32 main(int argc, char **argv) { l_int32 i, n; l_float32 a, b, c; L_DEWARP *dew, *dew2; DPIX *dpix1, *dpix2, *dpix3; FPIX *fpix1, *fpix2, *fpix3; NUMA *nax, *nafit; PIX *pixs, *pixn, *pixg, *pixb, *pixt1, *pixt2; PIX *pixs2, *pixn2, *pixg2, *pixb2; PTA *pta, *ptad; PTAA *ptaa1, *ptaa2; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("1555-7.jpg"); /* Normalize for varying background and binarize */ pixn = pixBackgroundNormSimple(pixs, NULL, NULL); pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2); pixb = pixThresholdToBinary(pixg, 130); pixDestroy(&pixn); pixDestroy(&pixg); regTestWritePixAndCheck(rp, pixb, IFF_PNG); /* 0 */ pixDisplayWithTitle(pixb, 0, 0, "binarized input", rp->display); /* Get the textline centers */ ptaa1 = pixGetTextlineCenters(pixb, 0); pixt1 = pixCreateTemplate(pixs); pixt2 = pixDisplayPtaa(pixt1, ptaa1); regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 1 */ pixDisplayWithTitle(pixt2, 0, 500, "textline centers", rp->display); pixDestroy(&pixt1); /* Remove short lines */ ptaa2 = ptaaRemoveShortLines(pixb, ptaa1, 0.8, 0); /* Fit to quadratic */ n = ptaaGetCount(ptaa2); for (i = 0; i < n; i++) { pta = ptaaGetPta(ptaa2, i, L_CLONE); ptaGetArrays(pta, &nax, NULL); ptaGetQuadraticLSF(pta, &a, &b, &c, &nafit); ptad = ptaCreateFromNuma(nax, nafit); pixDisplayPta(pixt2, pixt2, ptad); ptaDestroy(&pta); ptaDestroy(&ptad); numaDestroy(&nax); numaDestroy(&nafit); } regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 2 */ pixDisplayWithTitle(pixt2, 300, 500, "fitted lines superimposed", rp->display); ptaaDestroy(&ptaa1); ptaaDestroy(&ptaa2); pixDestroy(&pixt2); /* Run with only vertical disparity correction */ if ((dew = dewarpCreate(pixb, 7, 30, 15, 0)) == NULL) return ERROR_INT("\n\n\n FAILURE !!! \n\n\n", rp->testname, 1); dewarpBuildModel(dew, 0); dewarpApplyDisparity(dew, pixb, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 3 */ pixDisplayWithTitle(dew->pixd, 400, 0, "fixed for vert disparity", rp->display); dewarpDestroy(&dew); /* Run with both vertical and horizontal disparity correction */ if ((dew = dewarpCreate(pixb, 7, 30, 15, 1)) == NULL) return ERROR_INT("\n\n\n FAILURE !!! \n\n\n", rp->testname, 1); dewarpBuildModel(dew, 0); dewarpApplyDisparity(dew, pixb, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 4 */ pixDisplayWithTitle(dew->pixd, 800, 0, "fixed for both disparities", rp->display); /* Read another image, normalize background and binarize */ pixs2 = pixRead("1555-3.jpg"); pixn2 = pixBackgroundNormSimple(pixs2, NULL, NULL); pixg2 = pixConvertRGBToGray(pixn2, 0.5, 0.3, 0.2); pixb2 = pixThresholdToBinary(pixg2, 130); pixDestroy(&pixn2); pixDestroy(&pixg2); regTestWritePixAndCheck(rp, pixb, IFF_PNG); /* 5 */ pixDisplayWithTitle(pixb, 0, 400, "binarized input (2)", rp->display); /* Minimize and re-apply previous disparity to this image */ dewarpMinimize(dew); dewarpApplyDisparity(dew, pixb2, 0); regTestWritePixAndCheck(rp, dew->pixd, IFF_PNG); /* 6 */ pixDisplayWithTitle(dew->pixd, 400, 400, "fixed (2) for both disparities", rp->display); /* Write and read back minimized dewarp struct */ dewarpWrite("/tmp/dewarp.7.dew", dew); regTestCheckFile(rp, "/tmp/dewarp.7.dew"); /* 7 */ dew2 = dewarpRead("/tmp/dewarp.7.dew"); dewarpWrite("/tmp/dewarp.8.dew", dew2); regTestCheckFile(rp, "/tmp/dewarp.8.dew"); /* 8 */ regTestCompareFiles(rp, 7, 8); /* 9 */ /* Apply dew2 to pixb2 */ dewarpApplyDisparity(dew2, pixb2, 0); regTestWritePixAndCheck(rp, dew2->pixd, IFF_PNG); /* 10 */ pixDisplayWithTitle(dew->pixd, 800, 400, "fixed (3) for both disparities", rp->display); /* Minimize, repopulate disparity arrays, and apply again */ dewarpMinimize(dew2); dewarpApplyDisparity(dew2, pixb2, 0); regTestWritePixAndCheck(rp, dew2->pixd, IFF_PNG); /* 11 */ regTestCompareFiles(rp, 10, 11); /* 12 */ pixDisplayWithTitle(dew->pixd, 900, 400, "fixed (4) for both disparities", rp->display); /* Test a few of the fpix functions */ fpix1 = fpixClone(dew->sampvdispar); fpixWrite("/tmp/sampv.13.fpix", fpix1); regTestCheckFile(rp, "/tmp/sampv.13.fpix"); /* 13 */ fpix2 = fpixRead("/tmp/sampv.13.fpix"); fpixWrite("/tmp/sampv.14.fpix", fpix2); regTestCheckFile(rp, "/tmp/sampv.14.fpix"); /* 14 */ regTestCompareFiles(rp, 13, 14); /* 15 */ fpix3 = fpixScaleByInteger(fpix2, 30); pixt1 = fpixRenderContours(fpix3, -2., 2.0, 0.2); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 16 */ pixDisplayWithTitle(pixt1, 0, 800, "v. disparity contours", rp->display); fpixDestroy(&fpix1); fpixDestroy(&fpix2); fpixDestroy(&fpix3); pixDestroy(&pixt1); /* Test a few of the dpix functions */ dpix1 = fpixConvertToDPix(dew->sampvdispar); dpixWrite("/tmp/sampv.17.dpix", dpix1); regTestCheckFile(rp, "/tmp/sampv.17.dpix"); /* 17 */ dpix2 = dpixRead("/tmp/sampv.17.dpix"); dpixWrite("/tmp/sampv.18.dpix", dpix2); regTestCheckFile(rp, "/tmp/sampv.18.dpix"); /* 18 */ regTestCompareFiles(rp, 17, 18); /* 19 */ dpix3 = dpixScaleByInteger(dpix2, 30); fpix3 = dpixConvertToFPix(dpix3); pixt1 = fpixRenderContours(fpix3, -2., 2.0, 0.2); regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 20 */ pixDisplayWithTitle(pixt1, 400, 800, "v. disparity contours", rp->display); regTestCompareFiles(rp, 16, 20); /* 21 */ dpixDestroy(&dpix1); dpixDestroy(&dpix2); dpixDestroy(&dpix3); fpixDestroy(&fpix3); pixDestroy(&pixt1); dewarpDestroy(&dew); dewarpDestroy(&dew2); pixDestroy(&pixs); pixDestroy(&pixb); pixDestroy(&pixs2); pixDestroy(&pixb2); regTestCleanup(rp); return 0; }