Leptonica 1.68
C Image Processing Library

fmorphauto.c File Reference

Code generator, writes dwa code for erosion, dilation, opening and closing, for user-supplied Sels. More...

#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Defines

#define OUTROOT   "fmorphgen"
#define TEMPLATE1   "morphtemplate1.txt"
#define TEMPLATE2   "morphtemplate2.txt"
#define BUFFER_SIZE   512
#define PROTOARGS   "(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);"

Functions

static char * makeBarrelshiftString (l_int32 delx, l_int32 dely)
static SARRAYsarrayMakeInnerLoopDWACode (SEL *sel, l_int32 index)
static SARRAYsarrayMakeWplsCode (SEL *sel)
l_int32 fmorphautogen (SELA *sela, l_int32 fileindex, const char *filename)
l_int32 fmorphautogen1 (SELA *sela, l_int32 fileindex, const char *filename)
l_int32 fmorphautogen2 (SELA *sela, l_int32 fileindex, const char *filename)

Variables

static char wpldecls [][53]
static char wplgendecls [][30]
static char wpldefs [][25]
static char wplstrp [][10]
static char wplstrm [][10]

Detailed Description

Code generator, writes dwa code for erosion, dilation, opening and closing, for user-supplied Sels.

  Main function calls:
     l_int32             fmorphautogen()
     l_int32             fmorphautogen1()
     l_int32             fmorphautogen2()

  Static helpers:
     static SARRAY      *sarrayMakeWplsCode()
     static SARRAY      *sarrayMakeInnerLoopDWACode()
     static char        *makeBarrelshiftString()


  This automatically generates dwa code for erosion and dilation.
  Here's a road map for how it all works.

  (1) You generate an array (a SELA) of structuring elements (SELs).
      This can be done in several ways, including
         (a) calling the function selaAddBasic() for
             pre-compiled SELs
         (b) generating the SELA in code in line
         (c) reading in a SELA from file, using selaRead() or
             various other formats.

  (2) You call fmorphautogen1() and fmorphautogen2() on this SELA.
      These use the text files morphtemplate1.txt and
      morphtemplate2.txt for building up the source code.  See the file
      prog/fmorphautogen.c for an example of how this is done.
      The output is written to files named fmorphgen.*.c
      and fmorphgenlow.*.c, where "*" is an integer that you
      input to this function.  That integer labels both
      the output files, as well as all the functions that
      are generated.  That way, using different integers,
      you can invoke fmorphautogen() any number of times
      to get functions that all have different names so that
      they can be linked into one program.
      
  (3) You copy the generated source files back to your src
      directory for compilation.  Put their names in the
      Makefile, regenerate the prototypes, and recompile
      the library.  Look at the Makefile to see how I've
      included morphgen.1.c and fmorphgenlow.1.c.  These files
      provide the high-level interfaces for erosion, dilation,
      opening and closing, and the low-level interfaces to
      do the actual work, for all 58 SELs in the SEL array.

  (4) In an application, you now use this interface.  Again
      for the example files in the library, using integer "1":

          PIX   *pixMorphDwa_1(PIX *pixd, PIX, *pixs,
                               l_int32 operation, char *selname);

               or

          PIX   *pixFMorphopGen_1(PIX *pixd, PIX *pixs,
                                  l_int32 operation, char *selname);

      where the operation is one of {L_MORPH_DILATE, L_MORPH_ERODE.
      L_MORPH_OPEN, L_MORPH_CLOSE}, and the selname is one
      of the set that were defined as the name field of sels.
      This set is listed at the beginning of the file fmorphgen.1.c.
      For examples of use, see the file prog/binmorph_reg1.c, which
      verifies the consistency of the various implementations by
      comparing the dwa result with that of full-image rasterops. 

Definition in file fmorphauto.c.


Define Documentation

#define OUTROOT   "fmorphgen"

Definition at line 87 of file fmorphauto.c.

Referenced by fmorphautogen1(), and fmorphautogen2().

#define TEMPLATE1   "morphtemplate1.txt"

Definition at line 88 of file fmorphauto.c.

Referenced by fmorphautogen1().

#define TEMPLATE2   "morphtemplate2.txt"

Definition at line 89 of file fmorphauto.c.

Referenced by fmorphautogen2().

#define BUFFER_SIZE   512
#define PROTOARGS   "(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);"

Definition at line 93 of file fmorphauto.c.

Referenced by fmorphautogen2().


Function Documentation

static char * makeBarrelshiftString ( l_int32  delx,
l_int32  dely 
) [static]
static SARRAY * sarrayMakeInnerLoopDWACode ( SEL sel,
l_int32  index 
) [static]
static SARRAY * sarrayMakeWplsCode ( SEL sel) [static]
l_int32 fmorphautogen ( SELA sela,
l_int32  fileindex,
const char *  filename 
)

fmorphautogen()

Input: sela fileindex filename (<optional>; can be null) Return: 0 if OK; 1 on error

Notes: (1) This function generates all the code for implementing dwa morphological operations using all the sels in the sela. (2) See fmorphautogen1() and fmorphautogen2() for details.

Definition at line 228 of file fmorphauto.c.

References ERROR_INT, fmorphautogen1(), fmorphautogen2(), and PROCNAME.

Referenced by main().

l_int32 fmorphautogen1 ( SELA sela,
l_int32  fileindex,
const char *  filename 
)

fmorphautogen1()

Input: sela fileindex filename (<optional>; can be null) Return: 0 if OK; 1 on error

Notes: (1) This function uses morphtemplate1.txt to create a top-level file that contains two functions. These functions will carry out dilation, erosion, opening or closing for any of the sels in the input sela. (2) The fileindex parameter is inserted into the output filename, as described below. (3) If filename == NULL, the output file is fmorphgen.<n>.c, where <n> is equal to the 'fileindex' parameter. (4) If filename != NULL, the output file is <filename>.<n>.c.

Definition at line 266 of file fmorphauto.c.

References BUFFER_SIZE, ERROR_INT, FREE, l_binaryRead(), l_binaryWrite(), L_COPY, L_INSERT, NULL, OUTROOT, PROCNAME, sarrayAddString(), sarrayAppendRange(), sarrayCreate(), sarrayCreateLinesFromString(), sarrayDestroy(), sarrayGetString(), sarrayParseRange(), sarrayToString(), selaGetCount(), selaGetSelnames(), size, stringNew(), and TEMPLATE1.

Referenced by fmorphautogen().


Variable Documentation

char wpldecls[][53] [static]

Definition at line 99 of file fmorphauto.c.

Referenced by sarrayMakeWplsCode().

char wplgendecls[][30] [static]

Definition at line 131 of file fmorphauto.c.

Referenced by sarrayMakeWplsCode().

char wpldefs[][25] [static]

Definition at line 163 of file fmorphauto.c.

Referenced by sarrayMakeWplsCode().

char wplstrp[][10] [static]
Initial value:
 {"+ wpls", "+ wpls2", "+ wpls3", "+ wpls4",
                             "+ wpls5", "+ wpls6", "+ wpls7", "+ wpls8",
                             "+ wpls9", "+ wpls10", "+ wpls11", "+ wpls12",
                             "+ wpls13", "+ wpls14", "+ wpls15", "+ wpls16",
                             "+ wpls17", "+ wpls18", "+ wpls19", "+ wpls20",
                             "+ wpls21", "+ wpls22", "+ wpls23", "+ wpls24",
                             "+ wpls25", "+ wpls26", "+ wpls27", "+ wpls28",
                             "+ wpls29", "+ wpls30", "+ wpls31"}

Definition at line 195 of file fmorphauto.c.

Referenced by makeBarrelshiftString().

char wplstrm[][10] [static]
Initial value:
 {"- wpls", "- wpls2", "- wpls3", "- wpls4",
                             "- wpls5", "- wpls6", "- wpls7", "- wpls8",
                             "- wpls9", "- wpls10", "- wpls11", "- wpls12",
                             "- wpls13", "- wpls14", "- wpls15", "- wpls16",
                             "- wpls17", "- wpls18", "- wpls19", "- wpls20",
                             "- wpls21", "- wpls22", "- wpls23", "- wpls24",
                             "- wpls25", "- wpls26", "- wpls27", "- wpls28",
                             "- wpls29", "- wpls30", "- wpls31"}

Definition at line 204 of file fmorphauto.c.

Referenced by makeBarrelshiftString().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines