Leptonica  1.54
Файл src/sel1.c
#include <string.h>
#include "allheaders.h"

Классы

struct  CompParameterMap

Макросы

#define L_BUF_SIZE   256

Функции

static SELselCreateFromSArray (SARRAY *sa, l_int32 first, l_int32 last)
SELAselaCreate (l_int32 n)
void selaDestroy (SELA **psela)
SELselCreate (l_int32 height, l_int32 width, const char *name)
void selDestroy (SEL **psel)
SELselCopy (SEL *sel)
SELselCreateBrick (l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
SELselCreateComb (l_int32 factor1, l_int32 factor2, l_int32 direction)
l_int32 ** create2dIntArray (l_int32 sy, l_int32 sx)
l_int32 selaAddSel (SELA *sela, SEL *sel, const char *selname, l_int32 copyflag)
l_int32 selaExtendArray (SELA *sela)
l_int32 selaGetCount (SELA *sela)
SELselaGetSel (SELA *sela, l_int32 i)
char * selGetName (SEL *sel)
l_int32 selSetName (SEL *sel, const char *name)
l_int32 selaFindSelByName (SELA *sela, const char *name, l_int32 *pindex, SEL **psel)
l_int32 selGetElement (SEL *sel, l_int32 row, l_int32 col, l_int32 *ptype)
l_int32 selSetElement (SEL *sel, l_int32 row, l_int32 col, l_int32 type)
l_int32 selGetParameters (SEL *sel, l_int32 *psy, l_int32 *psx, l_int32 *pcy, l_int32 *pcx)
l_int32 selSetOrigin (SEL *sel, l_int32 cy, l_int32 cx)
l_int32 selGetTypeAtOrigin (SEL *sel, l_int32 *ptype)
char * selaGetBrickName (SELA *sela, l_int32 hsize, l_int32 vsize)
char * selaGetCombName (SELA *sela, l_int32 size, l_int32 direction)
l_int32 getCompositeParameters (l_int32 size, l_int32 *psize1, l_int32 *psize2, char **pnameh1, char **pnameh2, char **pnamev1, char **pnamev2)
SARRAYselaGetSelnames (SELA *sela)
l_int32 selFindMaxTranslations (SEL *sel, l_int32 *pxp, l_int32 *pyp, l_int32 *pxn, l_int32 *pyn)
SELselRotateOrth (SEL *sel, l_int32 quads)
SELAselaRead (const char *fname)
SELAselaReadStream (FILE *fp)
SELselRead (const char *fname)
SELselReadStream (FILE *fp)
l_int32 selaWrite (const char *fname, SELA *sela)
l_int32 selaWriteStream (FILE *fp, SELA *sela)
l_int32 selWrite (const char *fname, SEL *sel)
l_int32 selWriteStream (FILE *fp, SEL *sel)
SELselCreateFromString (const char *text, l_int32 h, l_int32 w, const char *name)
char * selPrintToString (SEL *sel)
SELAselaCreateFromFile (const char *filename)
SELselCreateFromPta (PTA *pta, l_int32 cy, l_int32 cx, const char *name)
SELselCreateFromPix (PIX *pix, l_int32 cy, l_int32 cx, const char *name)
SELselReadFromColorImage (const char *pathname)
SELselCreateFromColorPix (PIX *pixs, char *selname)
PIXselDisplayInPix (SEL *sel, l_int32 size, l_int32 gthick)
PIXselaDisplayInPix (SELA *sela, l_int32 size, l_int32 gthick, l_int32 spacing, l_int32 ncols)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 50
static const l_int32 MANY_SELS = 1000
static struct CompParameterMap comp_parameter_map []

Макросы

#define L_BUF_SIZE   256

Функции

create2dIntArray()

Input: sy (rows == height) sx (columns == width) Return: doubly indexed array (i.e., an array of sy row pointers, each of which points to an array of sx ints)

Notes: (1) The array[sy][sx] is indexed in standard "matrix notation", with the row index first.

l_int32 getCompositeParameters ( l_int32  size,
l_int32 psize1,
l_int32 psize2,
char **  pnameh1,
char **  pnameh2,
char **  pnamev1,
char **  pnamev2 
)

getCompositeParameters()

Input: size &size1 (<optional return>=""> brick factor size) &size2 (<optional return>=""> comb factor size) &nameh1 (<optional return>=""> name of horiz brick) &nameh2 (<optional return>=""> name of horiz comb) &namev1 (<optional return>=""> name of vert brick) &namev2 (<optional return>=""> name of vert comb) Return: 0 if OK, 1 on error

Notes: (1) This uses the big lookup table at the top of this file. (2) All returned strings are copies that must be freed.

l_int32 selaAddSel ( SELA sela,
SEL sel,
const char *  selname,
l_int32  copyflag 
)

selaAddSel()

Input: sela sel to be added selname (ignored if already defined in sel; req'd in sel when added to a sela) copyflag (for sel: 0 inserts, 1 copies) Return: 0 if OK; 1 on error

Notes: (1) This adds a sel, either inserting or making a copy. (2) Because every sel in a sela must have a name, it copies the input name if necessary. You can input NULL for selname if the sel already has a name.

selaCreate()

Input: n (initial number of sel ptrs; use 0 for default) Return: sela, or null on error

SELA* selaCreateFromFile ( const char *  filename)

selaCreateFromFile()

Input: filename Return: sela, or null on error

Notes: (1) The file contains a sequence of Sel descriptions. (2) Each Sel is formatted as follows:

  • Any number of comment lines starting with '#' are ignored
  • The next line contains the selname
  • The next lines contain the Sel data. They must be formatted similarly to the string format in selCreateFromString(), with each line beginning and ending with a double-quote, and showing the 2D layout.
  • Each Sel ends when a blank line, a comment line, or the end of file is reached. (3) See selCreateFromString() for a description of the string format for the Sel data. As an example, here are the lines of is a valid file for a single Sel. In the file, all lines are left-justified: # diagonal sel sel_5diag "x " " x " " X " " x " " x"
void selaDestroy ( SELA **  psela)

selaDestroy()

Input: &sela (<to be="" nulled>="">) Return: void

PIX* selaDisplayInPix ( SELA sela,
l_int32  size,
l_int32  gthick,
l_int32  spacing,
l_int32  ncols 
)

selaDisplayInPix()

Input: sela size (of grid interiors; odd; minimum size of 13 is enforced) gthick (grid thickness; minimum size of 2 is enforced) spacing (between sels, both horizontally and vertically) ncols (number of sels per "line") Return: pix (display of all sels in sela), or null on error

Notes: (1) This gives a visual representation of all the sels in a sela. (2) See notes in selDisplayInPix() for display params of each sel. (3) This gives the nicest results when all sels in the sela are the same size.

selaExtendArray()

Input: sela Return: 0 if OK; 1 on error

l_int32 selaFindSelByName ( SELA sela,
const char *  name,
l_int32 pindex,
SEL **  psel 
)

selaFindSelByName()

Input: sela sel name &index (<optional, return>) &sel (<optional, return> sel (not a copy)) Return: 0 if OK; 1 on error

char* selaGetBrickName ( SELA sela,
l_int32  hsize,
l_int32  vsize 
)

selaGetBrickName()

Input: sela hsize, vsize (of brick sel) Return: sel name (new string), or null if no name or on error

char* selaGetCombName ( SELA sela,
l_int32  size,
l_int32  direction 
)

selaGetCombName()

Input: sela size (the product of sizes of the brick and comb parts) direction (L_HORIZ, L_VERT) Return: sel name (new string), or null if name not found or on error

Notes: (1) Combs are by definition 1-dimensional, either horiz or vert. (2) Use this with comb Sels; e.g., from selaAddDwaCombs().

l_int32 selaGetCount ( SELA sela)

selaGetCount()

Input: sela Return: count, or 0 on error

SEL* selaGetSel ( SELA sela,
l_int32  i 
)

selaGetSel()

Input: sela index of sel to be retrieved (not copied) Return: sel, or null on error

Notes: (1) This returns a ptr to the sel, not a copy, so the caller must not destroy it!

SARRAY* selaGetSelnames ( SELA sela)

selaGetSelnames()

Input: sela Return: sa (of all sel names), or null on error

SELA* selaRead ( const char *  fname)

selaRead()

Input: filename Return: sela, or null on error

SELA* selaReadStream ( FILE *  fp)

selaReadStream()

Input: stream Return: sela, or null on error

l_int32 selaWrite ( const char *  fname,
SELA sela 
)

selaWrite()

Input: filename sela Return: 0 if OK, 1 on error

l_int32 selaWriteStream ( FILE *  fp,
SELA sela 
)

selaWriteStream()

Input: stream sela Return: 0 if OK, 1 on error

SEL* selCopy ( SEL sel)

selCopy()

Input: sel Return: a copy of the sel, or null on error

SEL* selCreate ( l_int32  height,
l_int32  width,
const char *  name 
)

selCreate()

Input: height, width name (<optional> sel name; can be null) Return: sel, or null on error

Notes: (1) selCreate() initializes all values to 0. (2) After this call, (cy,cx) and nonzero data values must be assigned. If a text name is not assigned here, it will be needed later when the sel is put into a sela.

SEL* selCreateBrick ( l_int32  h,
l_int32  w,
l_int32  cy,
l_int32  cx,
l_int32  type 
)

selCreateBrick()

Input: height, width cy, cx (origin, relative to UL corner at 0,0) type (SEL_HIT, SEL_MISS, or SEL_DONT_CARE) Return: sel, or null on error

Notes: (1) This is a rectangular sel of all hits, misses or don't cares.

SEL* selCreateComb ( l_int32  factor1,
l_int32  factor2,
l_int32  direction 
)

selCreateComb()

Input: factor1 (contiguous space between comb tines) factor2 (number of comb tines) direction (L_HORIZ, L_VERT) Return: sel, or null on error

Notes: (1) This generates a comb Sel of hits with the origin as near the center as possible.

SEL* selCreateFromColorPix ( PIX pixs,
char *  selname 
)

selCreateFromColorPix()

Input: pixs (cmapped or rgb) selname (<optional> sel name; can be null) Return: sel if OK, null on error

Notes: (1) The sel size is given by the size of pixs. (2) In pixs, hits are represented by green pixels, misses by red pixels, and don't-cares by white pixels. (3) In pixs, there may be no misses, but there must be at least 1 hit. (4) At most there can be only one origin pixel, which is optionally specified by using a lower-intensity pixel: if a hit: dark green if a miss: dark red if a don't care: gray If there is no such pixel, the origin defaults to the approximate center of the sel.

SEL* selCreateFromPix ( PIX pix,
l_int32  cy,
l_int32  cx,
const char *  name 
)

selCreateFromPix()

Input: pix cy, cx (origin of sel) name (<optional> sel name; can be null) Return: sel, or null on error

Notes: (1) The origin must be positive.

SEL* selCreateFromPta ( PTA pta,
l_int32  cy,
l_int32  cx,
const char *  name 
)

selCreateFromPta()

Input: pta cy, cx (origin of sel) name (<optional> sel name; can be null) Return: sel (of minimum required size), or null on error

Notes: (1) The origin and all points in the pta must be positive.

static SEL * selCreateFromSArray ( SARRAY sa,
l_int32  first,
l_int32  last 
) [static]

selCreateFromSArray()

Input: sa first (line of sarray where Sel begins) last (line of sarray where Sel ends) Return: sela, or null on error

Notes: (1) The Sel contains the following lines:

  • The first line is the selname
  • The remaining lines contain the Sel data. They must be formatted similarly to the string format in selCreateFromString(), with each line beginning and ending with a double-quote, and showing the 2D layout.
  • 'last' gives the last line in the Sel data. (2) See selCreateFromString() for a description of the string format for the Sel data. As an example, here are the lines of is a valid file for a single Sel. In the file, all lines are left-justified: # diagonal sel sel_5diag "x " " x " " X " " x " " x"
SEL* selCreateFromString ( const char *  text,
l_int32  h,
l_int32  w,
const char *  name 
)

selCreateFromString()

Input: text height, width name (<optional> sel name; can be null) Return: sel of the given size, or null on error

Notes: (1) The text is an array of chars (in row-major order) where each char can be one of the following: 'x': hit 'o': miss ' ': don't-care (2) Use an upper case char to indicate the origin of the Sel. When the origin falls on a don't-care, use 'C' as the uppecase for ' '. (3) The text can be input in a format that shows the 2D layout; e.g., static const char *seltext = "x " "x Oo " "x " "xxxxx";

void selDestroy ( SEL **  psel)

selDestroy()

Input: &sel (<to be="" nulled>="">) Return: void

PIX* selDisplayInPix ( SEL sel,
l_int32  size,
l_int32  gthick 
)

selDisplayInPix()

Input: sel size (of grid interiors; odd; minimum size of 13 is enforced) gthick (grid thickness; minimum size of 2 is enforced) Return: pix (display of sel), or null on error

Notes: (1) This gives a visual representation of a general (hit-miss) sel. (2) The empty sel is represented by a grid of intersecting lines. (3) Three different patterns are generated for the sel elements:

  • hit (solid black circle)
  • miss (black ring; inner radius is radius2)
  • origin (cross, XORed with whatever is there)
l_int32 selFindMaxTranslations ( SEL sel,
l_int32 pxp,
l_int32 pyp,
l_int32 pxn,
l_int32 pyn 
)

selFindMaxTranslations()

Input: sel &xp, &yp, &xn, &yn (<return> max shifts) Return: 0 if OK; 1 on error

Note: these are the maximum shifts for the erosion operation. For example, when j < cx, the shift of the image is +x to the cx. This is a positive xp shift.

l_int32 selGetElement ( SEL sel,
l_int32  row,
l_int32  col,
l_int32 ptype 
)

selGetElement()

Input: sel row col &type (<return> SEL_HIT, SEL_MISS, SEL_DONT_CARE) Return: 0 if OK; 1 on error

char* selGetName ( SEL sel)

selGetName()

Input: sel Return: sel name (not copied), or null if no name or on error

l_int32 selGetParameters ( SEL sel,
l_int32 psy,
l_int32 psx,
l_int32 pcy,
l_int32 pcx 
)

selGetParameters()

Input: sel &sy, &sx, &cy, &cx (<optional return>="">; each can be null) Return: 0 if OK, 1 on error

l_int32 selGetTypeAtOrigin ( SEL sel,
l_int32 ptype 
)

selGetTypeAtOrigin()

Input: sel &type (<return> SEL_HIT, SEL_MISS, SEL_DONT_CARE) Return: 0 if OK; 1 on error or if origin is not found

char* selPrintToString ( SEL sel)

selPrintToString()

Input: sel Return: str (string; caller must free)

Notes: (1) This is an inverse function of selCreateFromString. It prints a textual representation of the SEL to a malloc'd string. The format is the same as selCreateFromString except that newlines are inserted into the output between rows. (2) This is useful for debugging. However, if you want to save some Sels in a file, put them in a Sela and write them out with selaWrite(). They can then be read in with selaRead().

SEL* selRead ( const char *  fname)

selRead()

Input: filename Return: sel, or null on error

SEL* selReadFromColorImage ( const char *  pathname)

selReadFromColorImage()

Input: pathname Return: sel if OK; null on error

Notes: (1) Loads an image from a file and creates a (hit-miss) sel. (2) The sel name is taken from the pathname without the directory and extension.

SEL* selReadStream ( FILE *  fp)

selReadStream()

Input: stream Return: sel, or null on error

SEL* selRotateOrth ( SEL sel,
l_int32  quads 
)

selRotateOrth()

Input: sel quads (0 - 4; number of 90 degree cw rotations) Return: seld, or null on error

l_int32 selSetElement ( SEL sel,
l_int32  row,
l_int32  col,
l_int32  type 
)

selSetElement()

Input: sel row col type (SEL_HIT, SEL_MISS, SEL_DONT_CARE) Return: 0 if OK; 1 on error

Notes: (1) Because we use row and column to index into an array, they are always non-negative. The location of the origin (and the type of operation) determine the actual direction of the rasterop.

l_int32 selSetName ( SEL sel,
const char *  name 
)

selSetName()

Input: sel name (<optional>; can be null) Return: 0 if OK, 1 on error

Notes: (1) Always frees the existing sel name, if defined. (2) If name is not defined, just clears any existing sel name.

l_int32 selSetOrigin ( SEL sel,
l_int32  cy,
l_int32  cx 
)

selSetOrigin()

Input: sel cy, cx Return: 0 if OK; 1 on error

l_int32 selWrite ( const char *  fname,
SEL sel 
)

selWrite()

Input: filename sel Return: 0 if OK, 1 on error

l_int32 selWriteStream ( FILE *  fp,
SEL sel 
)

selWriteStream()

Input: stream sel Return: 0 if OK, 1 on error


Переменные

const l_int32 INITIAL_PTR_ARRAYSIZE = 50 [static]
const l_int32 MANY_SELS = 1000 [static]