Leptonica 1.68
C Image Processing Library

rankbin_reg.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  * rankbin_reg.c
00018  *
00019  *   Tests rank bin functions:
00020  *      (1) numaDiscretizeRankAndIntensity()
00021  *      (2) numaGetRankBinValues()
00022  */
00023 
00024 #ifndef  _WIN32
00025 #include <unistd.h>
00026 #else
00027 #include <windows.h>   /* for Sleep() */
00028 #endif  /* _WIN32 */
00029 
00030 #include "allheaders.h"
00031 
00032 
00033 main(int    argc,
00034      char **argv)
00035 {
00036 l_int32       i, n, w, h;
00037 BOXA         *boxa;
00038 NUMA         *naindex, *naw, *nah, *naw_med, *nah_med;
00039 PIX          *pixs, *pixt, *pixd;
00040 L_REGPARAMS  *rp;
00041 
00042     if (regTestSetup(argc, argv, &rp))
00043         return 1;
00044 
00045         /* Generate arrays of word widths and heights */
00046     pixs = pixRead("feyn.tif");
00047     pixGetWordBoxesInTextlines(pixs, 1, 6, 6, 500, 50, &boxa, &naindex);
00048     n = boxaGetCount(boxa);
00049     naw = numaCreate(0);
00050     nah = numaCreate(0);
00051     for (i = 0; i < n; i++) {
00052         boxaGetBoxGeometry(boxa, i, NULL, NULL, &w, &h);
00053         numaAddNumber(naw, w);
00054         numaAddNumber(nah, h);
00055     }
00056     boxaDestroy(&boxa);
00057     numaDestroy(&naindex);
00058 
00059         /* Make the rank bin arrays of median values, with 10 bins */
00060     numaGetRankBinValues(naw, 10, NULL, &naw_med);
00061     numaGetRankBinValues(nah, 10, NULL, &nah_med);
00062     gplotSimple1(naw_med, GPLOT_PNG, "/tmp/w_10bin", 
00063                  "width vs rank bins (10)");
00064     gplotSimple1(nah_med, GPLOT_PNG, "/tmp/h_10bin", 
00065                  "height vs rank bins (10)");
00066     numaDestroy(&naw_med);
00067     numaDestroy(&nah_med);
00068 
00069         /* Make the rank bin arrays of median values, with 30 bins */
00070     numaGetRankBinValues(naw, 30, NULL, &naw_med);
00071     numaGetRankBinValues(nah, 30, NULL, &nah_med);
00072     gplotSimple1(naw_med, GPLOT_PNG, "/tmp/w_30bin", 
00073                  "width vs rank bins (30)");
00074     gplotSimple1(nah_med, GPLOT_PNG, "/tmp/h_30bin", 
00075                  "height vs rank bins (30)");
00076     numaDestroy(&naw_med);
00077     numaDestroy(&nah_med);
00078 
00079         /* Give gnuplot time to write out the files */
00080 #ifndef  _WIN32
00081     sleep(2);
00082 #else
00083     Sleep(2000);
00084 #endif  /* _WIN32 */
00085 
00086         /* Save as golden files, or check against them */
00087     regTestCheckFile(rp, "/tmp/w_10bin.png");  /* 0 */
00088     regTestCheckFile(rp, "/tmp/h_10bin.png");  /* 1 */
00089     regTestCheckFile(rp, "/tmp/w_30bin.png");  /* 2 */
00090     regTestCheckFile(rp, "/tmp/h_30bin.png");  /* 3 */
00091 
00092         /* Display results for debugging */
00093     pixt = pixRead("/tmp/w_10bin.png");
00094     pixDisplayWithTitle(pixt, 0, 0, NULL, rp->display);
00095     pixDestroy(&pixt);
00096     pixt = pixRead("/tmp/h_10bin.png");
00097     pixDisplayWithTitle(pixt, 650, 0, NULL, rp->display);
00098     pixDestroy(&pixt);
00099     pixt = pixRead("/tmp/w_30bin.png");
00100     pixDisplayWithTitle(pixt, 0, 550, NULL, rp->display);
00101     pixDestroy(&pixt);
00102     pixt = pixRead("/tmp/h_30bin.png");
00103     pixDisplayWithTitle(pixt, 650, 550, NULL, rp->display);
00104     pixDestroy(&pixt);
00105 
00106     pixDestroy(&pixs);
00107     numaDestroy(&naw);
00108     numaDestroy(&nah);
00109     regTestCleanup(rp);
00110     return 0;
00111 }
00112 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines