Leptonica 1.68
C Image Processing Library

seedfilltest.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 /*
00018  * seedfilltest.c
00019  *
00020  */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include "allheaders.h"
00025 
00026 #define  NTIMES             5
00027 #define  CONNECTIVITY       8
00028 #define  XS                 150
00029 #define  YS                 150
00030 
00031 #define  DFLAG              1
00032 
00033 main(int    argc,
00034      char **argv)
00035 {
00036 char        *filein, *fileout;
00037 l_int32      i;
00038 l_uint32     val;
00039 l_float32    size;
00040 PIX         *pixs, *pixd, *pixm, *pixmi, *pixt1, *pixt2, *pixt3;
00041 static char  mainName[] = "seedfilltest";
00042 
00043     if (argc != 3)
00044         exit(ERROR_INT(" Syntax:  seedfilltest filein fileout", mainName, 1));
00045 
00046     filein = argv[1];
00047     fileout = argv[2];
00048     pixd = NULL;
00049 
00050     if ((pixm = pixRead(filein)) == NULL)
00051         exit(ERROR_INT("pixm not made", mainName, 1));
00052     pixmi = pixInvert(NULL, pixm);
00053             
00054     size = pixGetWidth(pixm) * pixGetHeight(pixm);
00055     pixs = pixCreateTemplate(pixm);
00056     for (i = 0; i < 100; i++) {
00057         pixGetPixel(pixm, XS + 5 * i, YS + 5 * i, &val);
00058         if (val == 0) break;
00059     }
00060     if (i == 100)
00061         exit(ERROR_INT("no seed pixel found", mainName, 1));
00062     pixSetPixel(pixs, XS + 5 * i, YS + 5 * i, 1);
00063 
00064 #if 0
00065         /* hole filling; use "hole-filler.png" */
00066     pixt1 = pixHDome(pixmi, 100, 4);
00067     pixt2 = pixThresholdToBinary(pixt1, 10);
00068 /*    pixInvert(pixt1, pixt1); */
00069     pixDisplay(pixt1, 100, 500);
00070     pixDisplay(pixt2, 600, 500);
00071     pixt3 = pixHolesByFilling(pixt2, 4);
00072     pixDilateBrick(pixt3, pixt3, 7, 7);
00073     pixd = pixConvertTo8(pixt3, FALSE);
00074     pixDisplay(pixd, 0, 100);
00075     pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
00076     pixInvert(pixd, pixd);
00077     pixDisplay(pixmi, 500, 100);
00078     pixDisplay(pixd, 1000, 100);
00079     pixWrite("/tmp/junkpixm.png", pixmi, IFF_PNG);
00080     pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG);
00081 #endif
00082 
00083 #if 0
00084         /* hole filling; use "hole-filler.png" */
00085     pixt1 = pixThresholdToBinary(pixm, 110);
00086     pixInvert(pixt1, pixt1);
00087     pixDisplay(pixt1, 100, 500);
00088     pixt2 = pixHolesByFilling(pixt1, 4);
00089     pixd = pixConvertTo8(pixt2, FALSE);
00090     pixDisplay(pixd, 0, 100);
00091     pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
00092     pixInvert(pixd, pixd);
00093     pixDisplay(pixmi, 500, 100);
00094     pixDisplay(pixd, 1000, 100);
00095     pixWrite("/tmp/junkpixm.png", pixmi, IFF_PNG);
00096     pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG);
00097 #endif
00098 
00099 #if 0
00100         /* hole filling; use "hole-filler.png" */
00101     pixd = pixInvert(NULL, pixm);
00102     pixAddConstantGray(pixd, -50);
00103     pixDisplay(pixd, 0, 100);
00104 /*    pixt1 = pixThresholdToBinary(pixd, 20);
00105     pixDisplayWithTitle(pixt1, 600, 600, "pixt1", DFLAG); */
00106     pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
00107 /*    pixInvert(pixd, pixd); */
00108     pixDisplay(pixmi, 500, 100);
00109     pixDisplay(pixd, 1000, 100);
00110     pixWrite("/tmp/junkpixm.png", pixmi, IFF_PNG);
00111     pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG);
00112 #endif
00113 
00114 #if 0  
00115         /* test in-place seedfill for speed */
00116     pixd = pixClone(pixs);
00117     startTimer();
00118     pixSeedfillBinary(pixs, pixs, pixmi, CONNECTIVITY);
00119     fprintf(stderr, "Filling rate: %7.4f Mpix/sec\n",
00120         (size/1000000.) / stopTimer());
00121 
00122     pixWrite(fileout, pixd, IFF_PNG);
00123     pixOr(pixd, pixd, pixm);
00124     pixWrite("/tmp/junkout1.png", pixd, IFF_PNG);
00125 #endif
00126 
00127 #if 0
00128         /* test seedfill to dest for speed */
00129     pixd = pixCreateTemplate(pixm);
00130     startTimer();
00131     for (i = 0; i < NTIMES; i++) {
00132         pixSeedfillBinary(pixd, pixs, pixmi, CONNECTIVITY);
00133     }
00134     fprintf(stderr, "Filling rate: %7.4f Mpix/sec\n",
00135         (size/1000000.) * NTIMES / stopTimer());
00136 
00137     pixWrite(fileout, pixd, IFF_PNG);
00138     pixOr(pixd, pixd, pixm);
00139     pixWrite("/tmp/junkout1.png", pixd, IFF_PNG);
00140 #endif
00141 
00142         /* use same connectivity to compare with the result of the
00143          * slow parallel operation */
00144 #if 0
00145     pixDestroy(&pixd);
00146     pixd = pixSeedfillMorph(pixs, pixmi, CONNECTIVITY);
00147     pixOr(pixd, pixd, pixm);
00148     pixWrite("/tmp/junkout2.png", pixd, IFF_PNG);
00149 #endif
00150 
00151     pixDestroy(&pixs);
00152     pixDestroy(&pixm);
00153     pixDestroy(&pixmi);
00154     pixDestroy(&pixd);
00155 
00156     return 0;
00157 }
00158 
00159 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines