Leptonica 1.68
C Image Processing Library

histotest.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  * histotest.c
00018  *
00019  *    Makes histograms of grayscale and color pixels
00020  *    from a pix.  For RGB color, this uses
00021  *    rgb --> octcube indexing.
00022  *
00023  *       histotest filein sigbits
00024  *
00025  *    where the number of octcubes is 8^(sigbits)
00026  *
00027  *    For gray, sigbits is ignored.
00028  */
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include "allheaders.h"
00033 
00034 
00035 main(int    argc,
00036      char **argv)
00037 {
00038 char        *filein;
00039 l_int32      d, sigbits;
00040 GPLOT       *gplot;
00041 NUMA        *na;
00042 PIX         *pixs, *pixd;
00043 static char  mainName[] = "histotest";
00044 
00045     if (argc != 3)
00046         exit(ERROR_INT(" Syntax:  histotest filein sigbits", mainName, 1));
00047 
00048     filein = argv[1];
00049     sigbits = atoi(argv[2]);
00050 
00051     if ((pixs = pixRead(filein)) == NULL)
00052         exit(ERROR_INT("pixs not made", mainName, 1));
00053     d = pixGetDepth(pixs);
00054     if (d != 8 && d != 32)
00055         exit(ERROR_INT("depth not 8 or 32 bpp", mainName, 1));
00056             
00057     if (d == 32) {
00058         startTimer();
00059         if ((na = pixOctcubeHistogram(pixs, sigbits, NULL)) == NULL)
00060             exit(ERROR_INT("na not made", mainName, 1));
00061         fprintf(stderr, "histo time = %7.3f sec\n", stopTimer());
00062         gplot = gplotCreate("/tmp/junkrootc", GPLOT_X11,
00063                 "color histogram with octcube indexing",
00064                 "octcube index", "number of pixels in cube");
00065         gplotAddPlot(gplot, NULL, na, GPLOT_LINES, "input pix");
00066         gplotMakeOutput(gplot);
00067         gplotDestroy(&gplot);
00068     }
00069     else {
00070         if ((na = pixGetGrayHistogram(pixs, 1)) == NULL)
00071             exit(ERROR_INT("na not made", mainName, 1));
00072         numaWrite("/tmp/junkna", na);
00073         gplot = gplotCreate("/tmp/junkrootg", GPLOT_X11, "grayscale histogram",
00074                             "gray value", "number of pixels");
00075         gplotSetScaling(gplot, GPLOT_LOG_SCALE_Y);
00076         gplotAddPlot(gplot, NULL, na, GPLOT_LINES, "input pix");
00077         gplotMakeOutput(gplot);
00078         gplotDestroy(&gplot);
00079     }
00080 
00081     pixDestroy(&pixs);
00082     numaDestroy(&na);
00083     exit(0);
00084 }
00085 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines