Leptonica 1.68
C Image Processing Library

gammatest.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  * gammatest.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include "allheaders.h"
00025 
00026 #define  NPLOTS      5
00027 
00028 #define  MINVAL      30
00029 #define  MAXVAL      210
00030 
00031 main(int    argc,
00032      char **argv)
00033 {
00034 char        *filein, *fileout;
00035 char         bigbuf[512];
00036 l_int32      iplot;
00037 l_float32    gam;
00038 l_float64    gamma[NPLOTS] = {.5, 1.0, 1.5, 2.0, 2.5};
00039 GPLOT       *gplot;
00040 NUMA        *na, *nax;
00041 PIX         *pixs, *pixd;
00042 static char  mainName[] = "gammatest";
00043 
00044     if (argc != 4)
00045         exit(ERROR_INT(" Syntax:  gammatest filein gam fileout", mainName, 1));
00046 
00047     filein = argv[1];
00048     gam = atof(argv[2]);
00049     fileout = argv[3];
00050 
00051     if ((pixs = pixRead(filein)) == NULL)
00052         exit(ERROR_INT("pixs not made", mainName, 1));
00053             
00054 #if 1
00055     startTimer();
00056     pixGammaTRC(pixs, pixs, gam, MINVAL, MAXVAL);
00057     fprintf(stderr, "Time for gamma: %7.3f sec\n", stopTimer());
00058     pixWrite(fileout, pixs, IFF_JFIF_JPEG);
00059     pixDestroy(&pixs);
00060 #endif
00061 
00062 #if 0
00063     startTimer();
00064     pixd = pixGammaTRC(NULL, pixs, gam, MINVAL, MAXVAL);
00065     fprintf(stderr, "Time for gamma: %7.3f sec\n", stopTimer());
00066     pixWrite(fileout, pixd, IFF_JFIF_JPEG);
00067     pixDestroy(&pixs);
00068     pixDestroy(&pixd);
00069 #endif
00070 
00071     na = numaGammaTRC(gam, MINVAL, MAXVAL);
00072     gplotSimple1(na, GPLOT_X11, "/tmp/junkroot", "gamma trc");
00073     numaDestroy(&na);
00074 
00075 #if 1     /* plot gamma TRC maps */
00076     gplot = gplotCreate("/tmp/junkmap", GPLOT_X11,
00077                         "Mapping function for gamma correction",
00078                         "value in", "value out");
00079     nax = numaMakeSequence(0.0, 1.0, 256);
00080     for (iplot = 0; iplot < NPLOTS; iplot++) {
00081         na = numaGammaTRC(gamma[iplot], 30, 215);
00082         sprintf(bigbuf, "gamma = %3.1f", gamma[iplot]);
00083         gplotAddPlot(gplot, nax, na, GPLOT_LINES, bigbuf);
00084         numaDestroy(&na);
00085     }
00086     gplotMakeOutput(gplot);
00087     gplotDestroy(&gplot);
00088     numaDestroy(&nax);
00089 #endif
00090 
00091     exit(0);
00092 }
00093 
00094 
00095 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines