Leptonica 1.68
C Image Processing Library

morphtest1.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  * morphtest1.c
00018  *
00019  *   - Timing test for rasterop-based morphological operations
00020  *   - Example repository of binary morph operations
00021  */
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include "allheaders.h"
00026 
00027 #define   NTIMES         100
00028 #define   IMAGE_SIZE     8.     /* megapixels */
00029 #define   SEL_SIZE       9
00030 #define   BASIC_OPS      1.     /* 1 for erosion/dilation; 2 for open/close */
00031 #define   CPU_SPEED      866.   /* MHz: set it for the machine you're using */
00032 
00033 
00034 
00035 main(int    argc,
00036      char **argv)
00037 {
00038 l_int32      i, index;
00039 l_float32    cputime, epo;
00040 char        *filein, *fileout;
00041 PIX         *pixs, *pixd;
00042 SEL         *sel;
00043 SELA        *sela;
00044 static char  mainName[] = "morphtest1";
00045 
00046     if (argc != 3)
00047         exit(ERROR_INT(" Syntax:  morphtest1 filein fileout", mainName, 1));
00048 
00049     filein = argv[1];
00050     fileout = argv[2];
00051 
00052     if ((pixs = pixRead(filein)) == NULL)
00053         exit(ERROR_INT("pix not made", mainName, 1));
00054     sela = selaAddBasic(NULL);
00055 
00056     /* ------------------------   Timing  -------------------------------*/
00057 #if 1
00058     selaFindSelByName(sela, "sel_9h", &index, &sel);
00059     selWriteStream(stderr, sel);
00060     pixd = pixCreateTemplate(pixs);
00061 
00062     startTimer();
00063     for (i = 0; i < NTIMES; i++)  {
00064         pixDilate(pixd, pixs, sel);
00065 /*      if ((i % 10) == 0) fprintf(stderr, "%d iters\n", i); */
00066     }
00067     cputime = stopTimer();
00068         /* Get the elementary pixel operations/sec */
00069     epo = BASIC_OPS * SEL_SIZE * NTIMES * IMAGE_SIZE /(cputime * CPU_SPEED);
00070 
00071     fprintf(stderr, "Time: %7.3f sec\n", cputime);
00072     fprintf(stderr, "Speed: %7.3f epo/cycle\n", epo);
00073     pixWrite(fileout, pixd, IFF_PNG);
00074     pixDestroy(&pixd);
00075 #endif
00076 
00077     /* ------------------  Example operation from repository --------------*/
00078 #if 1
00079         /* Select a structuring element */
00080     selaFindSelByName(sela, "sel_50h", &index, &sel);
00081     selWriteStream(stderr, sel);
00082 
00083         /* Do these operations.  See below for other ops
00084          * that can be substituted here. */
00085     pixd = pixOpen(NULL, pixs, sel);
00086     pixXor(pixd, pixd, pixs);
00087     pixWrite(fileout, pixd, IFF_PNG);
00088     pixDestroy(&pixd);
00089 #endif
00090 
00091     pixDestroy(&pixs);
00092     exit(0);
00093 }
00094 
00095 
00096 /* ==================================================================== */
00097 
00098 /* -------------------------------------------------------------------- *
00099  *                 Repository for selecting various operations          *
00100  *                              that might be used                      *
00101  * -------------------------------------------------------------------- */
00102 #if 0
00103     pixd = pixCreateTemplate(pixs);
00104 
00105     pixd = pixDilate(NULL, pixs, sel);
00106     pixd = pixErode(NULL, pixs, sel);
00107     pixd = pixOpen(NULL, pixs, sel);
00108     pixd = pixClose(NULL, pixs, sel);
00109 
00110     pixDilate(pixd, pixs, sel);
00111     pixErode(pixd, pixs, sel);
00112     pixOpen(pixd, pixs, sel);
00113     pixClose(pixd, pixs, sel);
00114 
00115     pixAnd(pixd, pixd, pixs);
00116     pixOr(pixd, pixd, pixs);
00117     pixXor(pixd, pixd, pixs);
00118     pixSubtract(pixd, pixd, pixs);
00119     pixInvert(pixd, pixs);
00120 
00121     pixd = pixAnd(NULL, pixd, pixs);
00122     pixd = pixOr(NULL, pixd, pixs);
00123     pixd = pixXor(NULL, pixd, pixs);
00124     pixd = pixSubtract(NULL, pixd, pixs);
00125     pixd = pixInvert(NULL, pixs);
00126 
00127     pixInvert(pixs, pixs);
00128 #endif  /* 0 */
00129 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines