Beispiel #1
0
int main(int    argc,
         char **argv)
{
char        *filein, *fileout;
char         bigbuf[512];
l_int32      iplot, same;
l_float32    gam;
l_float64    gamma[] = {.5, 1.0, 1.5, 2.0, 2.5, -1.0};
GPLOT       *gplot;
NUMA        *na, *nax;
PIX         *pixs, *pixd;
static char  mainName[] = "gammatest";

    if (argc != 4)
        return ERROR_INT(" Syntax:  gammatest filein gam fileout", mainName, 1);

    lept_mkdir("lept/gamma");

    filein = argv[1];
    gam = atof(argv[2]);
    fileout = argv[3];
    if ((pixs = pixRead(filein)) == NULL)
        return ERROR_INT("pixs not made", mainName, 1);

    startTimer();
    pixd = pixGammaTRC(NULL, pixs, gam, MINVAL, MAXVAL);
    fprintf(stderr, "Time for gamma: %7.3f sec\n", stopTimer());
    pixGammaTRC(pixs, pixs, gam, MINVAL, MAXVAL);
    pixEqual(pixs, pixd, &same);
    if (!same)
        fprintf(stderr, "Error in pixGammaTRC!\n");
    pixWrite(fileout, pixs, IFF_JFIF_JPEG);
    pixDestroy(&pixs);

    na = numaGammaTRC(gam, MINVAL, MAXVAL);
    gplotSimple1(na, GPLOT_PNG, "/tmp/lept/gamma/trc", "gamma trc");
    l_fileDisplay("/tmp/lept/gamma/trc.png", 100, 100, 1.0);
    numaDestroy(&na);

        /* Plot gamma TRC maps */
    gplot = gplotCreate("/tmp/lept/gamma/corr", GPLOT_PNG,
                        "Mapping function for gamma correction",
                        "value in", "value out");
    nax = numaMakeSequence(0.0, 1.0, 256);
    for (iplot = 0; gamma[iplot] >= 0.0; iplot++) {
        na = numaGammaTRC(gamma[iplot], 30, 215);
        sprintf(bigbuf, "gamma = %3.1f", gamma[iplot]);
        gplotAddPlot(gplot, nax, na, GPLOT_LINES, bigbuf);
        numaDestroy(&na);
    }
    gplotMakeOutput(gplot);
    gplotDestroy(&gplot);
    l_fileDisplay("/tmp/lept/gamma/corr.png", 100, 100, 1.0);
    numaDestroy(&nax);
    return 0;
}
/*!
 *  pixcmapGammaTRC()
 *
 *      Input:  colormap
 *              gamma (gamma correction; must be > 0.0)
 *              minval  (input value that gives 0 for output; can be < 0)
 *              maxval  (input value that gives 255 for output; can be > 255)
 *      Return: 0 if OK; 1 on error
 *
 *  Notes:
 *      - in-place transform
 *      - see pixGammaTRC() and numaGammaTRC() in enhance.c for
 *        description and use of transform
 */
l_int32
pixcmapGammaTRC(PIXCMAP   *cmap,
                l_float32  gamma,
                l_int32    minval,
                l_int32    maxval)
{
l_int32   rval, gval, bval, trval, tgval, tbval, i, ncolors;
NUMA     *nag;

    PROCNAME("pixcmapGammaTRC");

    if (!cmap)
        return ERROR_INT("cmap not defined", procName, 1);
    if (gamma <= 0.0) {
        L_WARNING("gamma must be > 0.0; setting to 1.0", procName);
        gamma = 1.0;
    }
    if (minval >= maxval)
        return ERROR_INT("minval not < maxval", procName, 1);

    if (gamma == 1.0 && minval == 0 && maxval == 255)  /* no-op */
        return 0;

    if ((nag = numaGammaTRC(gamma, minval, maxval)) == NULL)
        return ERROR_INT("nag not made", procName, 1);

    ncolors = pixcmapGetCount(cmap);
    for (i = 0; i < ncolors; i++) {
        pixcmapGetColor(cmap, i, &rval, &gval, &bval);
        numaGetIValue(nag, rval, &trval);
        numaGetIValue(nag, gval, &tgval);
        numaGetIValue(nag, bval, &tbval);
        pixcmapResetColor(cmap, i, trval, tgval, tbval);
    }

    numaDestroy(&nag);
    return 0;
}
Beispiel #3
0
main(int    argc,
     char **argv)
{
char        *filein, *fileout;
char         bigbuf[512];
l_int32      iplot;
l_float32    gam;
l_float64    gamma[NPLOTS] = {.5, 1.0, 1.5, 2.0, 2.5};
GPLOT       *gplot;
NUMA        *na, *nax;
PIX         *pixs, *pixd;
static char  mainName[] = "gammatest";

    if (argc != 4)
	exit(ERROR_INT(" Syntax:  gammatest filein gam fileout", mainName, 1));

    filein = argv[1];
    gam = atof(argv[2]);
    fileout = argv[3];

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

#if 1
    startTimer();
    pixGammaTRC(pixs, pixs, gam, MINVAL, MAXVAL);
    fprintf(stderr, "Time for gamma: %7.3f sec\n", stopTimer());
    pixWrite(fileout, pixs, IFF_JFIF_JPEG);
    pixDestroy(&pixs);
#endif

#if 0
    startTimer();
    pixd = pixGammaTRC(NULL, pixs, gam, MINVAL, MAXVAL);
    fprintf(stderr, "Time for gamma: %7.3f sec\n", stopTimer());
    pixWrite(fileout, pixd, IFF_JFIF_JPEG);
    pixDestroy(&pixs);
    pixDestroy(&pixd);
#endif

    na = numaGammaTRC(gam, MINVAL, MAXVAL);
    gplotSimple1(na, GPLOT_X11, "/tmp/junkroot", "gamma trc");
    numaDestroy(&na);

#if 1     /* plot gamma TRC maps */
    gplot = gplotCreate("/tmp/junkmap", GPLOT_X11,
                        "Mapping function for gamma correction",
		       	"value in", "value out");
    nax = numaMakeSequence(0.0, 1.0, 256);
    for (iplot = 0; iplot < NPLOTS; iplot++) {
        na = numaGammaTRC(gamma[iplot], 30, 215);
	sprintf(bigbuf, "gamma = %3.1f", gamma[iplot]);
        gplotAddPlot(gplot, nax, na, GPLOT_LINES, bigbuf);
	numaDestroy(&na);
    }
    gplotMakeOutput(gplot);
    gplotDestroy(&gplot);
    numaDestroy(&nax);
#endif

    return 0;
}