Leptonica 1.68
C Image Processing Library

numaranktest.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  * numaranktest.c
00018  *
00019  *     test on 8 bpp grayscale (e.g., w91frag.jpg)
00020  */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include "allheaders.h"
00025 
00026 static const l_int32   BIN_SIZE = 1;
00027 
00028 main(int    argc,
00029      char **argv)
00030 {
00031 char        *filein;
00032 l_int32      i, j, w, h, d, sampling;
00033 l_float32    rank, rval;
00034 l_uint32     val;
00035 NUMA        *na, *nah, *nar, *nav;
00036 PIX         *pix;
00037 static char  mainName[] = "numaranktest";
00038 
00039     if (argc != 3)
00040         exit(ERROR_INT(" Syntax:  numaranktest filein sampling", mainName, 1));
00041 
00042     filein = argv[1];
00043     sampling = atoi(argv[2]);
00044 
00045     if ((pix = pixRead(filein)) == NULL)
00046         exit(ERROR_INT("pix not made", mainName, 1));
00047     pixGetDimensions(pix, &w, &h, &d);
00048     if (d != 8)
00049         return ERROR_INT("d != 8 bpp", mainName, 1);
00050 
00051     na = numaCreate(0);
00052     for (i = 0; i < h; i += sampling) {
00053         for (j = 0; j < w; j += sampling) {
00054             pixGetPixel(pix, j, i, &val);
00055             numaAddNumber(na, val);
00056         }
00057     }
00058     nah = numaMakeHistogramClipped(na, BIN_SIZE, 255);
00059 
00060     nar = numaCreate(0);
00061     for (rval = 0.0; rval < 256.0; rval += 2.56) {
00062         numaHistogramGetRankFromVal(nah, rval, &rank);
00063         numaAddNumber(nar, rank);
00064     }
00065     gplotSimple1(nar, GPLOT_X11, "/tmp/junkroot1", "rank vs val");
00066 
00067     nav = numaCreate(0);
00068     for (rank = 0.0; rank <= 1.0; rank += 0.01) {
00069         numaHistogramGetValFromRank(nah, rank, &rval);
00070         numaAddNumber(nav, rval);
00071     }
00072     gplotSimple1(nav, GPLOT_X11, "/tmp/junkroot2", "val vs rank");
00073 
00074     pixDestroy(&pix);
00075     numaDestroy(&na);
00076     numaDestroy(&nah);
00077     numaDestroy(&nar);
00078     numaDestroy(&nav);
00079     return 0;
00080 }
00081 
00082 
00083 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines