Exemple #1
0
/*!
 *  pixDisplayHitMissSel()
 *
 *      Input:  pixs (1 bpp)
 *              sel (hit-miss in general)
 *              scalefactor (an integer >= 1; use 0 for default)
 *              hitcolor (RGB0 color for center of hit pixels)
 *              misscolor (RGB0 color for center of miss pixels)
 *      Return: pixd (RGB showing both pixs and sel), or null on error
 *  Notes:
 *    (1) We don't allow scalefactor to be larger than MAX_SEL_SCALEFACTOR
 *    (2) The colors are conveniently given as 4 bytes in hex format,
 *        such as 0xff008800.  The least significant byte is ignored.
 */
PIX *
pixDisplayHitMissSel(PIX      *pixs,
                     SEL      *sel,
                     l_int32   scalefactor,
                     l_uint32  hitcolor,
                     l_uint32  misscolor)
{
l_int32    i, j, type;
l_float32  fscale;
PIX       *pixt, *pixd;
PIXCMAP   *cmap;

    PROCNAME("pixDisplayHitMissSel");

    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (pixGetDepth(pixs) != 1)
        return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, NULL);
    if (!sel)
        return (PIX *)ERROR_PTR("sel not defined", procName, NULL);

    if (scalefactor <= 0)
        scalefactor = DEFAULT_SEL_SCALEFACTOR;
    if (scalefactor > MAX_SEL_SCALEFACTOR) {
        L_WARNING("scalefactor too large; using max value", procName);
        scalefactor = MAX_SEL_SCALEFACTOR;
    }

        /* Generate a version of pixs with a colormap */
    pixt = pixConvert1To8(NULL, pixs, 0, 1);
    cmap = pixcmapCreate(8);
    pixcmapAddColor(cmap, 255, 255, 255);
    pixcmapAddColor(cmap, 0, 0, 0);
    pixcmapAddColor(cmap, hitcolor >> 24, (hitcolor >> 16) & 0xff,
                    (hitcolor >> 8) & 0xff);
    pixcmapAddColor(cmap, misscolor >> 24, (misscolor >> 16) & 0xff,
                    (misscolor >> 8) & 0xff);
    pixSetColormap(pixt, cmap);

        /* Color the hits and misses */
    for (i = 0; i < sel->sy; i++) {
        for (j = 0; j < sel->sx; j++) {
            selGetElement(sel, i, j, &type);
            if (type == SEL_DONT_CARE)
                continue;
            if (type == SEL_HIT)
                pixSetPixel(pixt, j, i, 2);
            else  /* type == SEL_MISS */
                pixSetPixel(pixt, j, i, 3);
        }
    }

        /* Scale it up */
    fscale = (l_float32)scalefactor;
    pixd = pixScaleBySampling(pixt, fscale, fscale);

    pixDestroy(&pixt);
    return pixd;
}
Exemple #2
0
main(int    argc,
     char **argv)
{
    char        *filein, *fileout;
    l_int32      d;
    l_float32    scalex, scaley;
    PIX         *pixs, *pixd;
    static char  mainName[] = "scaletest1";

    if (argc != 5)
        return ERROR_INT(" Syntax:  scaletest1 filein scalex scaley fileout",
                         mainName, 1);

    filein = argv[1];
    scalex = atof(argv[2]);
    scaley = atof(argv[3]);
    fileout = argv[4];

    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);

    /* choose type of scaling operation */
#if 1
    pixd = pixScale(pixs, scalex, scaley);
#elif 0
    pixd = pixScaleLI(pixs, scalex, scaley);
#elif 0
    pixd = pixScaleSmooth(pixs, scalex, scaley);
#elif 0
    pixd = pixScaleAreaMap(pixs, scalex, scaley);
#elif 0
    pixd = pixScaleBySampling(pixs, scalex, scaley);
#else
    pixd = pixScaleToGray(pixs, scalex);
#endif

    d = pixGetDepth(pixd);

#if 1
    if (d <= 8)
        pixWrite(fileout, pixd, IFF_PNG);
    else
        pixWrite(fileout, pixd, IFF_JFIF_JPEG);
#else
    pixWrite(fileout, pixd, IFF_PNG);
#endif

    pixDestroy(&pixs);
    pixDestroy(&pixd);
    return 0;
}
Exemple #3
0
/*!
 *  selaAddTJunctions()
 *
 *      Input:  sela (<optional>)
 *              hlsize (length of each line of hits from origin)
 *              mdist (distance of misses from the origin)
 *              norient (number of orientations; max of 8)
 *              debugflag (1 for debug output)
 *      Return: sela with additional sels, or null on error
 *
 *  Notes:
 *      (1) Adds hitmiss Sels for the T-junction of two lines.
 *          If the lines are very thin, they must be nearly orthogonal
 *          to register.
 *      (2) The number of Sels generated is 4 * @norient.
 *      (3) It is suggested that @hlsize be chosen at least 1 greater
 *          than @mdist.  Try values of (@hlsize, @mdist) such as
 *          (6,5), (7,6), (8,7), (9,7), etc.
 */
SELA *
selaAddTJunctions(SELA      *sela,
                  l_float32  hlsize,
                  l_float32  mdist,
                  l_int32    norient,
                  l_int32    debugflag)
{
char       name[L_BUF_SIZE];
l_int32    i, j, k, w, xc, yc;
l_float64  pi, halfpi, radincr, jang, radang;
l_float64  angle[3], dist[3];
PIX       *pixc, *pixm, *pixt;
PIXA      *pixa;
PTA       *pta1, *pta2, *pta3;
SEL       *sel;

    PROCNAME("selaAddTJunctions");

    if (hlsize <= 2)
        return (SELA *)ERROR_PTR("hlsizel not > 1", procName, NULL);
    if (norient < 1 || norient > 8)
        return (SELA *)ERROR_PTR("norient not in [1, ... 8]", procName, NULL);

    if (!sela) {
        if ((sela = selaCreate(0)) == NULL)
            return (SELA *)ERROR_PTR("sela not made", procName, NULL);
    }

    pi = 3.1415926535;
    halfpi = 3.1415926535 / 2.0;
    radincr = halfpi / (l_float32)norient;
    w = (l_int32)(2.4 * (L_MAX(hlsize, mdist) + 0.5));
    if (w % 2 == 0)
        w++;
    xc = w / 2;
    yc = w / 2;

    pixa = pixaCreate(4 * norient);
    for (i = 0; i < norient; i++) {
        for (j = 0; j < 4; j++) {  /* 4 orthogonal orientations */
            jang = (l_float32)j * halfpi;

                /* Set the don't cares */
            pixc = pixCreate(w, w, 32);
            pixSetAll(pixc);

                /* Add the green lines of hits */
            pixm = pixCreate(w, w, 1);
            radang = (l_float32)i * radincr;
            pta1 = generatePtaLineFromPt(xc, yc, hlsize + 1, jang + radang);
            pta2 = generatePtaLineFromPt(xc, yc, hlsize + 1,
                                         jang + radang + halfpi);
            pta3 = generatePtaLineFromPt(xc, yc, hlsize + 1,
                                         jang + radang + pi);
            ptaJoin(pta1, pta2, 0, -1);
            ptaJoin(pta1, pta3, 0, -1);
            pixRenderPta(pixm, pta1, L_SET_PIXELS);
            pixPaintThroughMask(pixc, pixm, 0, 0, 0x00ff0000);
            ptaDestroy(&pta1);
            ptaDestroy(&pta2);
            ptaDestroy(&pta3);

                /* Add red misses between the lines */
            angle[0] = radang + jang - halfpi;
            angle[1] = radang + jang + 0.5 * halfpi;
            angle[2] = radang + jang + 1.5 * halfpi;
            dist[0] = 0.8 * mdist;
            dist[1] = dist[2] = mdist;
            for (k = 0; k < 3; k++) {
                pixSetPixel(pixc, xc + (l_int32)(dist[k] * cos(angle[k])),
                            yc + (l_int32)(dist[k] * sin(angle[k])),
                            0xff000000);
            }

                /* Add dark green for origin */
            pixSetPixel(pixc, xc, yc, 0x00550000);

                /* Generate the sel */
            sel = selCreateFromColorPix(pixc, NULL);
            sprintf(name, "sel_cross_%d", 4 * i + j);
            selaAddSel(sela, sel, name, 0);

            if (debugflag) {
                pixt = pixScaleBySampling(pixc, 10.0, 10.0);
                pixaAddPix(pixa, pixt, L_INSERT);
            }
            pixDestroy(&pixm);
            pixDestroy(&pixc);
        }
    }

    if (debugflag) {
        l_int32  w;
        pixaGetPixDimensions(pixa, 0, &w, NULL, NULL);
        pixt = pixaDisplayTiledAndScaled(pixa, 32, w, 4, 0, 10, 2);
        pixWriteTempfile("/tmp", "tsel1.png", pixt, IFF_PNG, 0);
        pixDisplay(pixt, 0, 100);
        pixDestroy(&pixt);
        pixt = selaDisplayInPix(sela, 15, 2, 20, 4);
        pixWriteTempfile("/tmp", "tsel2.png", pixt, IFF_PNG, 0);
        pixDisplay(pixt, 500, 100);
        pixDestroy(&pixt);
        selaWriteStream(stderr, sela);
    }
    pixaDestroy(&pixa);

    return sela;
}
/*!
 *  dewarpaShowArrays()
 *
 *      Input:  dewa
 *              scalefact (on contour images; typ. 0.5)
 *              first (first page model to render)
 *              last (last page model to render; use 0 to go to end)
 *              fontdir (for text bitmap fonts)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) Generates a pdf of contour plots of the disparity arrays.
 *      (2) This only shows actual models; not ref models
 */
l_int32
dewarpaShowArrays(L_DEWARPA   *dewa,
                  l_float32    scalefact,
                  l_int32      first,
                  l_int32      last,
                  const char  *fontdir)
{
char       buf[256];
char      *pathname;
l_int32    i, svd, shd;
L_BMF     *bmf;
L_DEWARP  *dew;
PIX       *pixv, *pixvs, *pixh, *pixhs, *pixt, *pixd;
PIXA      *pixa;

    PROCNAME("dewarpaShowArrays");

    if (!dewa)
        return ERROR_INT("dew not defined", procName, 1);
    if (first < 0 || first > dewa->maxpage)
        return ERROR_INT("first out of bounds", procName, 1);
    if (last <= 0 || last > dewa->maxpage) last = dewa->maxpage;
    if (last < first)
        return ERROR_INT("last < first", procName, 1);

    lept_rmdir("lept");
    lept_mkdir("lept");
    if ((bmf = bmfCreate(fontdir, 8)) == NULL)
              L_ERROR("bmf not made; page info not displayed", procName);

    fprintf(stderr, "Generating contour plots\n");
    for (i = first; i <= last; i++) {
        if (i && ((i % 10) == 0))
            fprintf(stderr, " .. %d", i);
        dew = dewarpaGetDewarp(dewa, i);
        if (!dew) continue;
        if (dew->hasref == 1) continue;
        svd = shd = 0;
        if (dew->sampvdispar) svd = 1;
        if (dew->samphdispar) shd = 1;
        if (!svd) {
            L_ERROR("sampvdispar not made for page %d!\n", procName, i);
            continue;
        }

            /* Generate contour plots at reduced resolution */
        dewarpPopulateFullRes(dew, NULL, 0, 0);
        pixv = fpixRenderContours(dew->fullvdispar, 3.0, 0.15);
        pixvs = pixScaleBySampling(pixv, scalefact, scalefact);
        pixDestroy(&pixv);
        if (shd) {
            pixh = fpixRenderContours(dew->fullhdispar, 3.0, 0.15);
            pixhs = pixScaleBySampling(pixh, scalefact, scalefact);
            pixDestroy(&pixh);
        }
        dewarpMinimize(dew);

            /* Save side-by-side */
        pixa = pixaCreate(2);
        pixaAddPix(pixa, pixvs, L_INSERT);
        if (shd)
            pixaAddPix(pixa, pixhs, L_INSERT);
        pixt = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 30, 2);
        snprintf(buf, sizeof(buf), "Page %d", i);
        pixd = pixAddSingleTextblock(pixt, bmf, buf, 0x0000ff00,
                                     L_ADD_BELOW, NULL);
        snprintf(buf, sizeof(buf), "arrays_%04d.png", i);
        pathname = genPathname("/tmp/lept", buf);
        pixWrite(pathname, pixd, IFF_PNG);
        pixaDestroy(&pixa);
        pixDestroy(&pixt);
        pixDestroy(&pixd);
        FREE(pathname);
    }
    bmfDestroy(&bmf);
    fprintf(stderr, "\n");

    fprintf(stderr, "Generating pdf of contour plots\n");
    convertFilesToPdf("/tmp/lept", "arrays_", 90, 1.0, L_FLATE_ENCODE,
                      0, "Disparity arrays", "/tmp/lept/disparity_arrays.pdf");
    fprintf(stderr, "Output written to: /tmp/lept/disparity_arrays.pdf\n");
    return 0;
}
main(int    argc,
     char **argv)
{
l_int32       i, j, x, y, rval, gval, bval;
l_uint32      pixel;
l_float32     frval, fgval, fbval;
NUMA         *nahue, *nasat, *napk;
PIX          *pixs, *pixhsv, *pixh, *pixg, *pixf, *pixd;
PIX          *pixr, *pixt1, *pixt2, *pixt3;
PIXA         *pixa, *pixapk;
PTA          *ptapk;
L_REGPARAMS  *rp;
	l_chooseDisplayProg(L_DISPLAY_WITH_XV);

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

        /* Make a graded frame color */
    pixs = pixCreate(650, 900, 32);
    for (i = 0; i < 900; i++) {
        rval = 40 + i / 30;
        for (j = 0; j < 650; j++) {
            gval = 255 - j / 30;
            bval = 70 + j / 30;
            composeRGBPixel(rval, gval, bval, &pixel);
            pixSetPixel(pixs, j, i, pixel);
        }
    }
            
        /* Place an image inside the frame and convert to HSV */
    pixt1 = pixRead("1555-3.jpg");
    pixt2 = pixScale(pixt1, 0.5, 0.5);
    pixRasterop(pixs, 100, 100, 2000, 2000, PIX_SRC, pixt2, 0, 0);
    pixDestroy(&pixt1);
    pixDestroy(&pixt2);
    pixDisplayWithTitle(pixs, 400, 0, "Input image", rp->display);
    pixa = pixaCreate(0);
    pixhsv = pixConvertRGBToHSV(NULL, pixs);

        /* Work in the HS projection of HSV */
    pixh = pixMakeHistoHS(pixhsv, 5, &nahue, &nasat);
    pixg = pixMaxDynamicRange(pixh, L_LOG_SCALE);
    pixf = pixConvertGrayToFalseColor(pixg, 1.0);
    regTestWritePixAndCheck(rp, pixf, IFF_PNG);   /* 0 */
    pixDisplayWithTitle(pixf, 100, 0, "False color HS histo", rp->display);
    pixaAddPix(pixa, pixs, L_COPY);
    pixaAddPix(pixa, pixhsv, L_INSERT);
    pixaAddPix(pixa, pixg, L_INSERT);
    pixaAddPix(pixa, pixf, L_INSERT);
    gplotSimple1(nahue, GPLOT_PNG, "/tmp/junkhue", "Histogram of hue values");
#ifndef  _WIN32
    sleep(1);
#else
    Sleep(1000);
#endif  /* _WIN32 */
    pixt3 = pixRead("/tmp/junkhue.png");
    regTestWritePixAndCheck(rp, pixt3, IFF_PNG);  /* 1 */
    pixDisplayWithTitle(pixt3, 100, 300, "Histo of hue", rp->display);
    pixaAddPix(pixa, pixt3, L_INSERT);
    gplotSimple1(nasat, GPLOT_PNG, "/tmp/junksat",
                 "Histogram of saturation values");
#ifndef  _WIN32
    sleep(1);
#else
    Sleep(1000);
#endif  /* _WIN32 */
    pixt3 = pixRead("/tmp/junksat.png");
    regTestWritePixAndCheck(rp, pixt3, IFF_PNG);  /* 2 */
    pixDisplayWithTitle(pixt3, 100, 800, "Histo of saturation", rp->display);
    pixaAddPix(pixa, pixt3, L_INSERT);
    pixd = pixaDisplayTiledAndScaled(pixa, 32, 270, 7, 0, 30, 3);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 3 */
    pixDisplayWithTitle(pixd, 0, 400, "Hue and Saturation Mosaic", rp->display);
    pixDestroy(&pixd);
    pixaDestroy(&pixa);
    numaDestroy(&nahue);
    numaDestroy(&nasat);

        /* Find all the peaks */
    pixFindHistoPeaksHSV(pixh, L_HS_HISTO, 20, 20, 6, 2.0,
                         &ptapk, &napk, &pixapk);
    numaWriteStream(stderr, napk);
    ptaWriteStream(stderr, ptapk, 1);
    pixd = pixaDisplayTiledInRows(pixapk, 32, 1400, 1.0, 0, 30, 2);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 4 */
    pixDisplayWithTitle(pixd, 0, 550, "Peaks in HS", rp->display);
    pixDestroy(&pixh);
    pixDestroy(&pixd);
    pixaDestroy(&pixapk);

        /* Make masks for each of the peaks */
    pixa = pixaCreate(0);
    pixr = pixScaleBySampling(pixs, 0.4, 0.4);
    for (i = 0; i < 6; i++) {
        ptaGetIPt(ptapk, i, &x, &y);
        pixt1 = pixMakeRangeMaskHS(pixr, y, 20, x, 20, L_INCLUDE_REGION);
        pixaAddPix(pixa, pixt1, L_INSERT);
        pixGetAverageMaskedRGB(pixr, pixt1, 0, 0, 1, L_MEAN_ABSVAL,
                               &frval, &fgval, &fbval);
        composeRGBPixel((l_int32)frval, (l_int32)fgval, (l_int32)fbval,
                        &pixel);
        pixt2 = pixCreateTemplate(pixr);
        pixSetAll(pixt2);
        pixPaintThroughMask(pixt2, pixt1, 0, 0, pixel);
        pixaAddPix(pixa, pixt2, L_INSERT);
        pixt3 = pixCreateTemplate(pixr);
        pixSetAllArbitrary(pixt3, pixel);
        pixaAddPix(pixa, pixt3, L_INSERT);
    }
    pixd = pixaDisplayTiledAndScaled(pixa, 32, 225, 3, 0, 30, 3);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 5 */
    pixDisplayWithTitle(pixd, 600, 0, "Masks over peaks", rp->display);
    pixDestroy(&pixs);
    pixDestroy(&pixr);
    pixDestroy(&pixd);
    pixaDestroy(&pixa);
    ptaDestroy(&ptapk);
    numaDestroy(&napk);

    regTestCleanup(rp);
    return 0;
}
Exemple #6
0
main(int    argc,
     char **argv)
{
l_int32      i;
l_float32    pi, scale, angle;
PIX         *pixc, *pixm, *pix1, *pix2, *pix3;
PIXA        *pixa;
PTA         *pta1, *pta2, *pta3, *pta4;
static char  mainName[] = "smallpix_reg";

        /* Make a small test image, the hard way! */
    pi = 3.1415926535;
    pixc = pixCreate(9, 9, 32);
    pixm = pixCreate(9, 9, 1);
    pta1 = generatePtaLineFromPt(4, 4, 3.1, 0.0);
    pta2 = generatePtaLineFromPt(4, 4, 3.1, 0.5 * pi);
    pta3 = generatePtaLineFromPt(4, 4, 3.1, pi);
    pta4 = generatePtaLineFromPt(4, 4, 3.1, 1.5 * pi);
    ptaJoin(pta1, pta2, 0, 0);
    ptaJoin(pta1, pta3, 0, 0);
    ptaJoin(pta1, pta4, 0, 0);
    pixRenderPta(pixm, pta1, L_SET_PIXELS);
    pixPaintThroughMask(pixc, pixm, 0, 0, 0x00ff0000);
    ptaDestroy(&pta1);
    ptaDestroy(&pta2);
    ptaDestroy(&pta3);
    ptaDestroy(&pta4);
    pixDestroy(&pixm);

        /* Results differ for scaleSmoothLow() w/ and w/out + 0.5.
         * Neither is properly symmetric (with symm pattern on odd-sized
         * pix, because the smoothing is destroying the symmetry. */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 2);
    for (i = 0; i < 11; i++) {
        scale = 0.30 + 0.035 * (l_float32)i;
        pix2 = pixScaleSmooth(pix1, scale, scale);
        pix3 = pixExpandReplicate(pix2, 6);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 100, NULL);

        /* Results same for pixScaleAreaMap w/ and w/out + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 2);
    for (i = 0; i < 11; i++) {
        scale = 0.30 + 0.035 * (l_float32)i;
        pix2 = pixScaleAreaMap(pix1, scale, scale);
        pix3 = pixExpandReplicate(pix2, 6);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 200, NULL);

        /* Results better for pixScaleBySampling with + 0.5, for small,
         * odd-dimension pix.  */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 2);
    for (i = 0; i < 11; i++) {
        scale = 0.30 + 0.035 * (l_float32)i;
        pix2 = pixScaleBySampling(pix1, scale, scale);
        pix3 = pixExpandReplicate(pix2, 6);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 300, NULL);

        /* Results same for pixRotateAM w/ and w/out + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        angle = 0.10 + 0.05 * (l_float32)i;
        pix2 = pixRotateAM(pix1, angle, L_BRING_IN_BLACK);
        pix3 = pixExpandReplicate(pix2, 8);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 400, NULL);

        /* If the size is odd, we express the center exactly, and the
         * results are better for pixRotateBySampling() w/out 0.5
         * However, if the size is even, the center value is not
         * exact, and if we choose it 0.5 smaller than the actual
         * center, we get symmetrical results with +0.5. 
         * So we choose not to include + 0.5. */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        angle = 0.10 + 0.05 * (l_float32)i;
        pix2 = pixRotateBySampling(pix1, 4, 4, angle, L_BRING_IN_BLACK);
        pix3 = pixExpandReplicate(pix2, 8);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 500, NULL);

        /* Results same for pixRotateAMCorner w/ and w/out + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        angle = 0.10 + 0.05 * (l_float32)i;
        pix2 = pixRotateAMCorner(pix1, angle, L_BRING_IN_BLACK);
        pix3 = pixExpandReplicate(pix2, 8);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 600, NULL);

        /* Results better for pixRotateAMColorFast without + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        angle = 0.10 + 0.05 * (l_float32)i;
        pix2 = pixRotateAMColorFast(pix1, angle, 0);
        pix3 = pixExpandReplicate(pix2, 8);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 700, NULL);

        /* Results slightly better for pixScaleColorLI() w/out + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        scale = 1.0 + 0.2 * (l_float32)i;
        pix2 = pixScaleColorLI(pix1, scale, scale);
        pix3 = pixExpandReplicate(pix2, 4);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 800, NULL);

        /* Results slightly better for pixScaleColorLI() w/out + 0.5 */
    pixa = pixaCreate(11);
    pix1 = pixExpandReplicate(pixc, 1);
    for (i = 0; i < 11; i++) {
        scale = 1.0 + 0.2 * (l_float32)i;
        pix2 = pixScaleLI(pix1, scale, scale);
        pix3 = pixExpandReplicate(pix2, 4);
        pixSaveTiled(pix3, pixa, 1, (i == 0), 20, 32);
        pixDestroy(&pix2);
        pixDestroy(&pix3);
    }
    pixDestroy(&pix1);
    DisplayPix(&pixa, 100, 940, NULL);

    pixDestroy(&pixc);
    return 0;
}
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);
}
Exemple #8
0
main(int    argc,
     char **argv)
{
PIX         *pixs;
l_int32      d;
static char  mainName[] = "scaletest2";

    if (argc != 2)
	return ERROR_INT(" Syntax:  scaletest2 filein", mainName, 1);

    if ((pixs = pixRead(argv[1])) == NULL)
	return ERROR_INT("pixs not made", mainName, 1);
    d = pixGetDepth(pixs);
	    
#if 1
        /* Integer scale-to-gray functions */
    if (d == 1)
    {
    PIX  *pixd;

        pixd = pixScaleToGray2(pixs);
        pixWrite("/tmp/s2g_2x", pixd, IFF_PNG);
        pixDestroy(&pixd);
        pixd = pixScaleToGray3(pixs);
        pixWrite("/tmp/s2g_3x", pixd, IFF_PNG);
        pixDestroy(&pixd);
        pixd = pixScaleToGray4(pixs);
        pixWrite("/tmp/s2g_4x", pixd, IFF_PNG);
        pixDestroy(&pixd);
        pixd = pixScaleToGray6(pixs);
        pixWrite("/tmp/s2g_6x", pixd, IFF_PNG);
        pixDestroy(&pixd);
        pixd = pixScaleToGray8(pixs);
        pixWrite("/tmp/s2g_8x", pixd, IFF_PNG);
        pixDestroy(&pixd);
        pixd = pixScaleToGray16(pixs);
        pixWrite("/tmp/s2g_16x", pixd, IFF_PNG);
        pixDestroy(&pixd);
    }
#endif

#if 1
        /* Various non-integer scale-to-gray, compared with
	 * with different ways of getting similar results */
    if (d == 1)
    {
    PIX  *pixt, *pixd;

        pixd = pixScaleToGray8(pixs);
        pixWrite("/tmp/s2g_8.png", pixd, IFF_PNG);
        pixDestroy(&pixd);

        pixd = pixScaleToGray(pixs, 0.124);
        pixWrite("/tmp/s2g_124.png", pixd, IFF_PNG);
        pixDestroy(&pixd);

        pixd = pixScaleToGray(pixs, 0.284);
        pixWrite("/tmp/s2g_284.png", pixd, IFF_PNG);
        pixDestroy(&pixd);

        pixt = pixScaleToGray4(pixs);
        pixd = pixScaleBySampling(pixt, 284./250., 284./250.);
        pixWrite("/tmp/s2g_284.2.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixt = pixScaleToGray4(pixs);
        pixd = pixScaleGrayLI(pixt, 284./250., 284./250.);
        pixWrite("/tmp/s2g_284.3.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixt = pixScaleBinary(pixs, 284./250., 284./250.);
        pixd = pixScaleToGray4(pixt);
        pixWrite("/tmp/s2g_284.4.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixt = pixScaleToGray4(pixs);
        pixd = pixScaleGrayLI(pixt, 0.49, 0.49);
        pixWrite("/tmp/s2g_42.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixt = pixScaleToGray4(pixs);
        pixd = pixScaleSmooth(pixt, 0.49, 0.49);
        pixWrite("/tmp/s2g_4sm.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixt = pixScaleBinary(pixs, .16/.125, .16/.125);
        pixd = pixScaleToGray8(pixt);
        pixWrite("/tmp/s2g_16.png", pixd, IFF_PNG);
        pixDestroy(&pixt);
        pixDestroy(&pixd);

        pixd = pixScaleToGray(pixs, .16);
        pixWrite("/tmp/s2g_16.2.png", pixd, IFF_PNG);
        pixDestroy(&pixd);
    }
#endif

#if 1
        /* Antialiased (smoothed) reduction, along with sharpening */
    if (d != 1)
    {
    PIX *pixt1, *pixt2;
        startTimer();
        pixt1 = pixScaleSmooth(pixs, 0.154, 0.154);
        fprintf(stderr, "fast scale: %5.3f sec\n", stopTimer());
        pixDisplayWithTitle(pixt1, 0, 0, "smooth scaling", DISPLAY);
        pixWrite("/tmp/smooth1.png", pixt1, IFF_PNG);
        pixt2 = pixUnsharpMasking(pixt1, 1, 0.3);
        pixWrite("/tmp/smooth2.png", pixt2, IFF_PNG);
        pixDisplayWithTitle(pixt2, 200, 0, "sharp scaling", DISPLAY);
        pixDestroy(&pixt1);
        pixDestroy(&pixt2);
    }
#endif


#if 1
        /* Test a large range of scale-to-gray reductions */
    if (d == 1)
    {
    l_int32    i;
    l_float32  scale;
    PIX       *pixd;
        for (i = 2; i < 15; i++) {
            scale = 1. / (l_float32)i;
            startTimer();
            pixd = pixScaleToGray(pixs, scale);
            fprintf(stderr, "Time for scale %7.3f: %7.3f sec\n",
            scale, stopTimer());
            pixDisplayWithTitle(pixd, 75 * i, 100, "scaletogray", DISPLAY);
            pixDestroy(&pixd);
        }
        for (i = 8; i < 14; i++) {
            scale = 1. / (l_float32)(2 * i);
            startTimer();
            pixd = pixScaleToGray(pixs, scale);
            fprintf(stderr, "Time for scale %7.3f: %7.3f sec\n",
            scale, stopTimer());
            pixDisplayWithTitle(pixd, 100 * i, 600, "scaletogray", DISPLAY);
            pixDestroy(&pixd);
        }
    }
#endif


#if 1
        /* Test the same range of scale-to-gray mipmap reductions */
    if (d == 1)
    {
    l_int32    i;
    l_float32  scale;
    PIX       *pixd;
        for (i = 2; i < 15; i++) {
            scale = 1. / (l_float32)i;
            startTimer();
            pixd = pixScaleToGrayMipmap(pixs, scale);
            fprintf(stderr, "Time for scale %7.3f: %7.3f sec\n",
            scale, stopTimer());
            pixDisplayWithTitle(pixd, 75 * i, 100, "scale mipmap", DISPLAY);
            pixDestroy(&pixd);
        }
        for (i = 8; i < 12; i++) {
            scale = 1. / (l_float32)(2 * i);
            startTimer();
            pixd = pixScaleToGrayMipmap(pixs, scale);
            fprintf(stderr, "Time for scale %7.3f: %7.3f sec\n",
            scale, stopTimer());
            pixDisplayWithTitle(pixd, 100 * i, 600, "scale mipmap", DISPLAY);
            pixDestroy(&pixd);
        }
    }
#endif

#if 1
        /* Test several methods for antialiased reduction,
	 * along with sharpening */
    if (d != 1)
    {
        PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6, *pixt7;
        l_float32 SCALING = 0.27;
        l_int32   SIZE = 7;
        l_int32   smooth;
        l_float32 FRACT = 1.0;

        smooth = SIZE / 2;

        startTimer();
        pixt1 = pixScaleSmooth(pixs, SCALING, SCALING);
        fprintf(stderr, "fast scale: %5.3f sec\n", stopTimer());
        pixDisplayWithTitle(pixt1, 0, 0, "smooth scaling", DISPLAY);
        pixWrite("/tmp/sm_1.png", pixt1, IFF_PNG);
        pixt2 = pixUnsharpMasking(pixt1, 1, 0.3);
        pixDisplayWithTitle(pixt2, 150, 0, "sharpened scaling", DISPLAY);

        startTimer();
        pixt3 = pixBlockconv(pixs, smooth, smooth);
        pixt4 = pixScaleBySampling(pixt3, SCALING, SCALING);
        fprintf(stderr, "slow scale: %5.3f sec\n", stopTimer());
        pixDisplayWithTitle(pixt4, 200, 200, "sampled scaling", DISPLAY);
        pixWrite("/tmp/sm_2.png", pixt4, IFF_PNG);

        startTimer();
        pixt5 = pixUnsharpMasking(pixs, smooth, FRACT);
        pixt6 = pixBlockconv(pixt5, smooth, smooth);
        pixt7 = pixScaleBySampling(pixt6, SCALING, SCALING);
        fprintf(stderr, "very slow scale + sharp: %5.3f sec\n", stopTimer());
        pixDisplayWithTitle(pixt7, 500, 200, "sampled scaling", DISPLAY);
        pixWrite("/tmp/sm_3.jpg", pixt7, IFF_JFIF_JPEG);

        pixDestroy(&pixt1);
        pixDestroy(&pixt2);
        pixDestroy(&pixt3);
        pixDestroy(&pixt4);
        pixDestroy(&pixt5);
        pixDestroy(&pixt6);
        pixDestroy(&pixt7);
    }
#endif


#if 1
        /* Test the color scaling function, comparing the
	 * special case of scaling factor 2.0 with the 
	 * general case. */
    if (d == 32) 
    {
    PIX    *pix1, *pix2, *pixd;
    NUMA   *nar, *nag, *nab, *naseq;
    GPLOT  *gplot;

        startTimer();
        pix1 = pixScaleColorLI(pixs, 2.00001, 2.0);
        fprintf(stderr, " Time with regular LI: %7.3f\n", stopTimer());
        pixWrite("/tmp/color1.jpg", pix1, IFF_JFIF_JPEG);
        startTimer();
        pix2 = pixScaleColorLI(pixs, 2.0, 2.0);
        fprintf(stderr, " Time with 2x LI: %7.3f\n", stopTimer());
        pixWrite("/tmp/color2.jpg", pix2, IFF_JFIF_JPEG);

        pixd = pixAbsDifference(pix1, pix2);
        pixGetColorHistogram(pixd, 1, &nar, &nag, &nab);
        naseq = numaMakeSequence(0., 1., 256);
        gplot = gplotCreate("/tmp/plot_absdiff", GPLOT_X11, "Number vs diff",
                            "diff", "number");
        gplotSetScaling(gplot, GPLOT_LOG_SCALE_Y);
        gplotAddPlot(gplot, naseq, nar, GPLOT_POINTS, "red");
        gplotAddPlot(gplot, naseq, nag, GPLOT_POINTS, "green");
        gplotAddPlot(gplot, naseq, nab, GPLOT_POINTS, "blue");
        gplotMakeOutput(gplot);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
        pixDestroy(&pixd);
        numaDestroy(&naseq);
        numaDestroy(&nar);
        numaDestroy(&nag);
        numaDestroy(&nab);
        gplotDestroy(&gplot);
    }
#endif


#if 1
        /* Test the gray LI scaling function, comparing the
	 * special cases of scaling factor 2.0 and 4.0 with the 
	 * general case */
    if (d == 8 || d == 32)
    {
    PIX    *pixt, *pix0, *pix1, *pix2, *pixd;
    NUMA   *nagray, *naseq;
    GPLOT  *gplot;

        if (d == 8)
            pixt = pixClone(pixs);
        else
            pixt = pixConvertRGBToGray(pixs, 0.33, 0.34, 0.33);
        pix0 = pixScaleGrayLI(pixt, 0.5, 0.5);

#if 1
        startTimer();
        pix1 = pixScaleGrayLI(pix0, 2.00001, 2.0);
        fprintf(stderr, " Time with regular LI 2x: %7.3f\n", stopTimer());
        startTimer();
        pix2 = pixScaleGrayLI(pix0, 2.0, 2.0);
        fprintf(stderr, " Time with 2x LI: %7.3f\n", stopTimer());
#else
        startTimer();
        pix1 = pixScaleGrayLI(pix0, 4.00001, 4.0);
        fprintf(stderr, " Time with regular LI 4x: %7.3f\n", stopTimer());
        startTimer();
        pix2 = pixScaleGrayLI(pix0, 4.0, 4.0);
        fprintf(stderr, " Time with 2x LI: %7.3f\n", stopTimer());
#endif
        pixWrite("/tmp/gray1", pix1, IFF_JFIF_JPEG);
        pixWrite("/tmp/gray2", pix2, IFF_JFIF_JPEG);

        pixd = pixAbsDifference(pix1, pix2);
        nagray = pixGetGrayHistogram(pixd, 1);
        naseq = numaMakeSequence(0., 1., 256);
        gplot = gplotCreate("/tmp/g_absdiff", GPLOT_X11, "Number vs diff",
                            "diff", "number");
        gplotSetScaling(gplot, GPLOT_LOG_SCALE_Y);
        gplotAddPlot(gplot, naseq, nagray, GPLOT_POINTS, "gray");
        gplotMakeOutput(gplot);
        pixDestroy(&pixt);
        pixDestroy(&pix0);
        pixDestroy(&pix1);
        pixDestroy(&pix2);
        pixDestroy(&pixd);
        numaDestroy(&naseq);
        numaDestroy(&nagray);
        gplotDestroy(&gplot);
    }
#endif

    pixDestroy(&pixs);
    return 0;
}
Exemple #9
0
main(int    argc,
     char **argv)
{
l_int32       i, w, h, bx, by, bw, bh, index, rval, gval, bval;
BOX          *box;
BOXA         *boxa;
PIX          *pixm, *pixs, *pixg, *pixt, *pixd;
PIXA         *pixa;
PIXCMAP      *cmap;
PTA          *pta;
PTAA         *ptaa;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
	return 1;
    pixa = pixaCreate(0);

    /* ---------------- Shortest path in binary maze ---------------- */
        /* Generate the maze */
    pixm = generateBinaryMaze(200, 200, 20, 20, 0.65, 0.25);
    pixd = pixExpandBinaryReplicate(pixm, 3);
    pixSaveTiledOutline(pixd, pixa, 1, 1, 20, 2, 32);
    pixDestroy(&pixd);

        /* Find the shortest path between two points */
    pta = pixSearchBinaryMaze(pixm, 20, 20, 170, 170, NULL);
    pixt = pixDisplayPta(NULL, pixm, pta);
    pixd = pixScaleBySampling(pixt, 3., 3.);
    pixSaveTiledOutline(pixd, pixa, 1, 0, 20, 2, 32);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 0 */
    ptaDestroy(&pta);
    pixDestroy(&pixt);
    pixDestroy(&pixd);
    pixDestroy(&pixm);


    /* ---------------- Shortest path in gray maze ---------------- */
    pixg = pixRead("test8.jpg");
    pixGetDimensions(pixg, &w, &h, NULL);
    ptaa = ptaaCreate(NPATHS);
    for (i = 0; i < NPATHS; i++) {
        if (x0[i] >= w || x1[i] >= w || y0[i] >= h || y1[i] >= h) {
            fprintf(stderr, "path %d extends beyond image; skipping\n", i);
            continue;
        }
        pta = pixSearchGrayMaze(pixg, x0[i], y0[i], x1[i], y1[i], NULL);
        ptaaAddPta(ptaa, pta, L_INSERT);
    }

    pixt = pixDisplayPtaa(pixg, ptaa);
    pixd = pixScaleBySampling(pixt, 2., 2.);
    pixSaveTiledOutline(pixd, pixa, 1, 1, 20, 2, 32);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 1 */
    ptaaDestroy(&ptaa);
    pixDestroy(&pixg);
    pixDestroy(&pixt);
    pixDestroy(&pixd);


    /* ---------------- Largest rectangles in image ---------------- */
    pixs = pixRead("test1.png");
    pixd = pixConvertTo8(pixs, FALSE);
    cmap = pixcmapCreateRandom(8, 1, 1);
    pixSetColormap(pixd, cmap);

    boxa = boxaCreate(0);
    for (i = 0; i < NBOXES; i++) {
        pixFindLargestRectangle(pixs, POLARITY, &box, NULL);
        boxGetGeometry(box, &bx, &by, &bw, &bh);
        pixSetInRect(pixs, box);
        fprintf(stderr, "bx = %5d, by = %5d, bw = %5d, bh = %5d, area = %d\n",
                bx, by, bw, bh, bw * bh);
        boxaAddBox(boxa, box, L_INSERT);
    }

    for (i = 0; i < NBOXES; i++) {
        index = 32 + (i & 254);
        pixcmapGetColor(cmap, index, &rval, &gval, &bval);
        box = boxaGetBox(boxa, i, L_CLONE);
        pixRenderHashBoxArb(pixd, box, 6, 2, L_NEG_SLOPE_LINE, 1,
                            rval, gval, bval);
        boxDestroy(&box);
    }
    pixSaveTiledOutline(pixd, pixa, 1, 1, 20, 2, 32);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 2 */
    pixDestroy(&pixs);
    pixDestroy(&pixd);
    boxaDestroy(&boxa);

    pixd = pixaDisplay(pixa, 0, 0);
    regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 3 */
    pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
    pixDestroy(&pixd);
    pixaDestroy(&pixa);

    return regTestCleanup(rp);
}
Exemple #10
0
/*!
 * \brief   selaAddCrossJunctions()
 *
 * \param[in]    sela [optional]
 * \param[in]    hlsize length of each line of hits from origin
 * \param[in]    mdist distance of misses from the origin
 * \param[in]    norient number of orientations; max of 8
 * \param[in]    debugflag 1 for debug output
 * \return  sela with additional sels, or NULL on error
 *
 * <pre>
 * Notes:
 *      (1) Adds hitmiss Sels for the intersection of two lines.
 *          If the lines are very thin, they must be nearly orthogonal
 *          to register.
 *      (2) The number of Sels generated is equal to %norient.
 *      (3) If %norient == 2, this generates 2 Sels of crosses, each with
 *          two perpendicular lines of hits.  One Sel has horizontal and
 *          vertical hits; the other has hits along lines at +-45 degrees.
 *          Likewise, if %norient == 3, this generates 3 Sels of crosses
 *          oriented at 30 degrees with each other.
 *      (4) It is suggested that %hlsize be chosen at least 1 greater
 *          than %mdist.  Try values of (%hlsize, %mdist) such as
 *          (6,5), (7,6), (8,7), (9,7), etc.
 * </pre>
 */
SELA *
selaAddCrossJunctions(SELA      *sela,
                      l_float32  hlsize,
                      l_float32  mdist,
                      l_int32    norient,
                      l_int32    debugflag)
{
char       name[L_BUF_SIZE];
l_int32    i, j, w, xc, yc;
l_float64  pi, halfpi, radincr, radang;
l_float64  angle;
PIX       *pixc, *pixm, *pixt;
PIXA      *pixa;
PTA       *pta1, *pta2, *pta3, *pta4;
SEL       *sel;

    PROCNAME("selaAddCrossJunctions");

    if (hlsize <= 0)
        return (SELA *)ERROR_PTR("hlsize not > 0", procName, NULL);
    if (norient < 1 || norient > 8)
        return (SELA *)ERROR_PTR("norient not in [1, ... 8]", procName, NULL);

    if (!sela) {
        if ((sela = selaCreate(0)) == NULL)
            return (SELA *)ERROR_PTR("sela not made", procName, NULL);
    }

    pi = 3.1415926535;
    halfpi = 3.1415926535 / 2.0;
    radincr = halfpi / (l_float64)norient;
    w = (l_int32)(2.2 * (L_MAX(hlsize, mdist) + 0.5));
    if (w % 2 == 0)
        w++;
    xc = w / 2;
    yc = w / 2;

    pixa = pixaCreate(norient);
    for (i = 0; i < norient; i++) {

            /* Set the don't cares */
        pixc = pixCreate(w, w, 32);
        pixSetAll(pixc);

            /* Add the green lines of hits */
        pixm = pixCreate(w, w, 1);
        radang = (l_float32)i * radincr;
        pta1 = generatePtaLineFromPt(xc, yc, hlsize + 1, radang);
        pta2 = generatePtaLineFromPt(xc, yc, hlsize + 1, radang + halfpi);
        pta3 = generatePtaLineFromPt(xc, yc, hlsize + 1, radang + pi);
        pta4 = generatePtaLineFromPt(xc, yc, hlsize + 1, radang + pi + halfpi);
        ptaJoin(pta1, pta2, 0, -1);
        ptaJoin(pta1, pta3, 0, -1);
        ptaJoin(pta1, pta4, 0, -1);
        pixRenderPta(pixm, pta1, L_SET_PIXELS);
        pixPaintThroughMask(pixc, pixm, 0, 0, 0x00ff0000);
        ptaDestroy(&pta1);
        ptaDestroy(&pta2);
        ptaDestroy(&pta3);
        ptaDestroy(&pta4);

            /* Add red misses between the lines */
        for (j = 0; j < 4; j++) {
            angle = radang + (j - 0.5) * halfpi;
            pixSetPixel(pixc, xc + (l_int32)(mdist * cos(angle)),
                        yc + (l_int32)(mdist * sin(angle)), 0xff000000);
        }

            /* Add dark green for origin */
        pixSetPixel(pixc, xc, yc, 0x00550000);

            /* Generate the sel */
        sel = selCreateFromColorPix(pixc, NULL);
        sprintf(name, "sel_cross_%d", i);
        selaAddSel(sela, sel, name, 0);

        if (debugflag) {
            pixt = pixScaleBySampling(pixc, 10.0, 10.0);
            pixaAddPix(pixa, pixt, L_INSERT);
        }
        pixDestroy(&pixm);
        pixDestroy(&pixc);
    }

    if (debugflag) {
        l_int32  w;
        lept_mkdir("lept/sel");
        pixaGetPixDimensions(pixa, 0, &w, NULL, NULL);
        pixt = pixaDisplayTiledAndScaled(pixa, 32, w, 1, 0, 10, 2);
        pixWrite("/tmp/lept/sel/xsel1.png", pixt, IFF_PNG);
        pixDisplay(pixt, 0, 100);
        pixDestroy(&pixt);
        pixt = selaDisplayInPix(sela, 15, 2, 20, 1);
        pixWrite("/tmp/lept/sel/xsel2.png", pixt, IFF_PNG);
        pixDisplay(pixt, 500, 100);
        pixDestroy(&pixt);
        selaWriteStream(stderr, sela);
    }
    pixaDestroy(&pixa);

    return sela;
}