Leptonica 1.68
C Image Processing Library

projection_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  *  projection_reg.c
00018  *
00019  *    Tests projection stats for rows and columns.
00020  *    Just for interest, a number of different tests are done.
00021  */
00022 
00023 #ifndef  _WIN32
00024 #include <unistd.h>
00025 #else
00026 #include <windows.h>   /* for Sleep() */
00027 #endif  /* _WIN32 */
00028 #include "allheaders.h"
00029 
00030 void TestProjection(L_REGPARAMS *rp, PIX *pix);
00031 
00032 main(int    argc,
00033      char **argv)
00034 {
00035 PIX          *pixs, *pixg1, *pixg2;
00036 L_REGPARAMS  *rp;
00037 
00038     if (regTestSetup(argc, argv, &rp))
00039         return 1;
00040 
00041         /* Use for input two different images */
00042     pixs = pixRead("projectionstats.jpg");
00043     pixg1 = pixConvertTo8(pixs, 0);
00044     pixDestroy(&pixs);
00045     pixs = pixRead("feyn.tif");
00046     pixg2 = pixScaleToGray4(pixs);
00047     pixDestroy(&pixs);
00048 
00049     TestProjection(rp, pixg1);
00050     TestProjection(rp, pixg2);
00051     pixDestroy(&pixg1);
00052     pixDestroy(&pixg2);
00053     regTestCleanup(rp);
00054     return 0;
00055 }
00056 
00057 
00058 /*
00059  *  Test both vertical and horizontal projections on this image.
00060  *  We rotate the image by 90 degrees for the horizontal projection,
00061  *  so that the two results should be identical.
00062  */
00063 void
00064 TestProjection(L_REGPARAMS  *rp,
00065                PIX          *pixs)
00066 {
00067 l_int32  outline;
00068 NUMA    *na1, *na2, *na3, *na4, *na5, *na6;
00069 NUMA    *na7, *na8, *na9, *na10, *na11, *na12;
00070 PIX     *pixd, *pixt;
00071 PIXA    *pixa;
00072 
00073     outline = 2;
00074     pixColumnStats(pixs, &na1, &na3, &na5, &na7, &na9, &na11);
00075     pixd = pixRotateOrth(pixs, 1);
00076     pixRowStats(pixd, &na2, &na4, &na6, &na8, &na10, &na12);
00077 
00078         /* The png plot files are written to "/tmp/proj.0.png", etc.
00079          * These temp files are overwritten each time this
00080          * function is called. */
00081     gplotSimple1(na1, GPLOT_PNG, "/tmp/proj.0", "Mean value");
00082     gplotSimple1(na2, GPLOT_PNG, "/tmp/proj.1", "Mean value");
00083     gplotSimple1(na3, GPLOT_PNG, "/tmp/proj.2", "Median value");
00084     gplotSimple1(na4, GPLOT_PNG, "/tmp/proj.3", "Median value");
00085     gplotSimple1(na5, GPLOT_PNG, "/tmp/proj.4", "Mode value");
00086     gplotSimple1(na6, GPLOT_PNG, "/tmp/proj.5", "Mode value");
00087     gplotSimple1(na7, GPLOT_PNG, "/tmp/proj.6", "Mode count");
00088     gplotSimple1(na8, GPLOT_PNG, "/tmp/proj.7", "Mode count");
00089     gplotSimple1(na9, GPLOT_PNG, "/tmp/proj.8", "Variance");
00090     gplotSimple1(na10, GPLOT_PNG, "/tmp/proj.9", "Variance");
00091     gplotSimple1(na11, GPLOT_PNG, "/tmp/proj.10", "Square Root Variance");
00092     gplotSimple1(na12, GPLOT_PNG, "/tmp/proj.11", "Square Root Variance");
00093 #ifndef  _WIN32
00094     sleep(1);
00095 #else
00096     Sleep(1000);
00097 #endif  /* _WIN32 */
00098 
00099         /* Each of the 12 plot files is read into a pix and then:
00100          *    (1) saved into a pixa for display
00101          *    (2) saved as a golden file (generate stage) or compared
00102          *        to the existing golden file (testing stage)    */
00103     pixa = pixaCreate(13);
00104     pixSaveTiledOutline(pixs, pixa, 1, 1, 30, outline, 32);
00105     pixt = pixRead("/tmp/proj.0.png");
00106     regTestWritePixAndCheck(rp, pixt, IFF_PNG);   /* 0 */
00107     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00108     pixDestroy(&pixt);
00109     pixt = pixRead("/tmp/proj.1.png");
00110     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 1 */
00111     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00112     pixDestroy(&pixt);
00113     pixt = pixRead("/tmp/proj.2.png");
00114     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 2 */
00115     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00116     pixDestroy(&pixt);
00117     pixt = pixRead("/tmp/proj.3.png");
00118     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 3 */
00119     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00120     pixDestroy(&pixt);
00121     pixt = pixRead("/tmp/proj.4.png");
00122     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 4 */
00123     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00124     pixDestroy(&pixt);
00125     pixt = pixRead("/tmp/proj.5.png");
00126     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 5 */
00127     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00128     pixDestroy(&pixt);
00129     pixt = pixRead("/tmp/proj.6.png");
00130     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 6 */
00131     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00132     pixDestroy(&pixt);
00133     pixt = pixRead("/tmp/proj.7.png");
00134     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 7 */
00135     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00136     pixDestroy(&pixt);
00137     pixt = pixRead("/tmp/proj.8.png");
00138     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 8 */
00139     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00140     pixDestroy(&pixt);
00141     pixt = pixRead("/tmp/proj.9.png");
00142     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 9 */
00143     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00144     pixDestroy(&pixt);
00145     pixt = pixRead("/tmp/proj.10.png");
00146     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 10 */
00147     pixSaveTiledOutline(pixt, pixa, 1, 1, 30, outline, 32);
00148     pixDestroy(&pixt);
00149     pixt = pixRead("/tmp/proj.11.png");
00150     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 11 */
00151     pixSaveTiledOutline(pixt, pixa, 1, 0, 30, outline, 32);
00152     pixDestroy(&pixt);
00153 
00154         /* The pixa is composited into a pix and 'goldened'/tested */
00155     pixt = pixaDisplay(pixa, 0, 0);
00156     regTestWritePixAndCheck(rp, pixt, IFF_PNG);  /* 12 */
00157     pixDisplayWithTitle(pixt, 100, 0, NULL, rp->display);
00158     pixDestroy(&pixt);
00159     pixaDestroy(&pixa);
00160 
00161         /* The 12 plot files are tested in pairs for identity */
00162     regTestCompareFiles(rp, 0, 1);
00163     regTestCompareFiles(rp, 2, 3);
00164     regTestCompareFiles(rp, 4, 5);
00165     regTestCompareFiles(rp, 6, 7);
00166     regTestCompareFiles(rp, 8, 9);
00167     regTestCompareFiles(rp, 10, 11);
00168 
00169     pixDestroy(&pixd);
00170     numaDestroy(&na1);
00171     numaDestroy(&na2);
00172     numaDestroy(&na3);
00173     numaDestroy(&na4);
00174     numaDestroy(&na5);
00175     numaDestroy(&na6);
00176     numaDestroy(&na7);
00177     numaDestroy(&na8);
00178     numaDestroy(&na9);
00179     numaDestroy(&na10);
00180     numaDestroy(&na11);
00181     numaDestroy(&na12);
00182     return;
00183 }
00184 
00185 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines