Leptonica 1.68
C Image Processing Library

graymorph2_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  * graymorph2_reg.c
00018  *
00019  *   Compares graymorph results with special (3x1, 1x3, 3x3) cases
00020  *   against the general case.  Require exact equality.
00021  */
00022 
00023 #include "allheaders.h"
00024 
00025 main(int    argc,
00026      char **argv)
00027 {
00028 PIX          *pixs, *pixt1, *pixt2, *pixd;
00029 PIXA         *pixa;
00030 L_REGPARAMS  *rp;
00031 
00032     if (regTestSetup(argc, argv, &rp))
00033         return 1;
00034 
00035     pixs = pixRead("test8.jpg");
00036 
00037         /* Dilation */
00038     pixa = pixaCreate(0);
00039     pixSaveTiled(pixs, pixa, 1, 1, 20, 8);
00040     pixt1 = pixDilateGray3(pixs, 3, 1);
00041     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00042     pixt2 = pixDilateGray(pixs, 3, 1);
00043     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00044     regTestComparePix(rp, pixt1, pixt2);  /* 0 */
00045     pixDestroy(&pixt1);
00046     pixDestroy(&pixt2);
00047 
00048     pixt1 = pixDilateGray3(pixs, 1, 3);
00049     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00050     pixt2 = pixDilateGray(pixs, 1, 3);
00051     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00052     regTestComparePix(rp, pixt1, pixt2);  /* 1 */
00053     pixDestroy(&pixt1);
00054     pixDestroy(&pixt2);
00055 
00056     pixt1 = pixDilateGray3(pixs, 3, 3);
00057     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00058     pixt2 = pixDilateGray(pixs, 3, 3);
00059     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00060     regTestComparePix(rp, pixt1, pixt2);  /* 2 */
00061     pixDestroy(&pixt1);
00062     pixDestroy(&pixt2);
00063 
00064     pixd = pixaDisplay(pixa, 0, 0);
00065     pixDisplayWithTitle(pixd, 0, 100, "Dilation", rp->display);
00066     pixDestroy(&pixd);
00067     pixaDestroy(&pixa);
00068 
00069         /* Erosion */
00070     pixa = pixaCreate(0);
00071     pixSaveTiled(pixs, pixa, 1, 1, 20, 8);
00072     pixt1 = pixErodeGray3(pixs, 3, 1);
00073     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00074     pixt2 = pixErodeGray(pixs, 3, 1);
00075     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00076     regTestComparePix(rp, pixt1, pixt2);  /* 3 */
00077     pixDestroy(&pixt1);
00078     pixDestroy(&pixt2);
00079 
00080     pixt1 = pixErodeGray3(pixs, 1, 3);
00081     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00082     pixt2 = pixErodeGray(pixs, 1, 3);
00083     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00084     regTestComparePix(rp, pixt1, pixt2);  /* 4 */
00085     pixDestroy(&pixt1);
00086     pixDestroy(&pixt2);
00087 
00088     pixt1 = pixErodeGray3(pixs, 3, 3);
00089     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00090     pixt2 = pixErodeGray(pixs, 3, 3);
00091     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00092     regTestComparePix(rp, pixt1, pixt2);  /* 5 */
00093     pixDestroy(&pixt1);
00094     pixDestroy(&pixt2);
00095 
00096     pixd = pixaDisplay(pixa, 0, 0);
00097     pixDisplayWithTitle(pixd, 250, 100, "Erosion", rp->display);
00098     pixDestroy(&pixd);
00099     pixaDestroy(&pixa);
00100 
00101         /* Opening */
00102     pixa = pixaCreate(0);
00103     pixSaveTiled(pixs, pixa, 1, 1, 20, 8);
00104     pixt1 = pixOpenGray3(pixs, 3, 1);
00105     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00106     pixt2 = pixOpenGray(pixs, 3, 1);
00107     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00108     regTestComparePix(rp, pixt1, pixt2);  /* 6 */
00109     pixDestroy(&pixt1);
00110     pixDestroy(&pixt2);
00111 
00112     pixt1 = pixOpenGray3(pixs, 1, 3);
00113     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00114     pixt2 = pixOpenGray(pixs, 1, 3);
00115     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00116     regTestComparePix(rp, pixt1, pixt2);  /* 7 */
00117     pixDestroy(&pixt1);
00118     pixDestroy(&pixt2);
00119 
00120     pixt1 = pixOpenGray3(pixs, 3, 3);
00121     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00122     pixt2 = pixOpenGray(pixs, 3, 3);
00123     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00124     regTestComparePix(rp, pixt1, pixt2);  /* 8 */
00125     pixDestroy(&pixt1);
00126     pixDestroy(&pixt2);
00127 
00128     pixd = pixaDisplay(pixa, 0, 0);
00129     pixDisplayWithTitle(pixd, 500, 100, "Opening", rp->display);
00130     pixDestroy(&pixd);
00131     pixaDestroy(&pixa);
00132 
00133         /* Closing */
00134     pixa = pixaCreate(0);
00135     pixSaveTiled(pixs, pixa, 1, 1, 20, 8);
00136     pixt1 = pixCloseGray3(pixs, 3, 1);
00137     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00138     pixt2 = pixCloseGray(pixs, 3, 1);
00139     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00140     regTestComparePix(rp, pixt1, pixt2);  /* 9 */
00141     pixDestroy(&pixt1);
00142     pixDestroy(&pixt2);
00143 
00144     pixt1 = pixCloseGray3(pixs, 1, 3);
00145     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00146     pixt2 = pixCloseGray(pixs, 1, 3);
00147     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00148     regTestComparePix(rp, pixt1, pixt2);  /* 10 */
00149     pixDestroy(&pixt1);
00150     pixDestroy(&pixt2);
00151 
00152     pixt1 = pixCloseGray3(pixs, 3, 3);
00153     pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
00154     pixt2 = pixCloseGray(pixs, 3, 3);
00155     pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
00156     regTestComparePix(rp, pixt1, pixt2);  /* 11 */
00157     pixDestroy(&pixt1);
00158     pixDestroy(&pixt2);
00159 
00160     pixd = pixaDisplay(pixa, 0, 0);
00161     pixDisplayWithTitle(pixd, 750, 100, "Closing", rp->display);
00162     pixDestroy(&pixd);
00163     pixaDestroy(&pixa);
00164 
00165     regTestCleanup(rp);
00166     pixDestroy(&pixs);
00167     return 0;
00168 }
00169 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines