Файл src/pts.c

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

Функции

PTAptaCreate (l_int32 n)
void ptaDestroy (PTA **ppta)
PTAptaCopy (PTA *pta)
PTAptaClone (PTA *pta)
l_int32 ptaEmpty (PTA *pta)
l_int32 ptaAddPt (PTA *pta, l_float32 x, l_float32 y)
l_int32 ptaExtendArrays (PTA *pta)
l_int32 ptaJoin (PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
PTAptaReverse (PTA *ptas, l_int32 type)
PTAptaCyclicPerm (PTA *ptas, l_int32 xs, l_int32 ys)
PTAptaSort (PTA *ptas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
PTAptaRemoveDuplicates (PTA *ptas, l_uint32 factor)
l_int32 ptaGetRefcount (PTA *pta)
l_int32 ptaChangeRefcount (PTA *pta, l_int32 delta)
l_int32 ptaGetCount (PTA *pta)
l_int32 ptaGetPt (PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
l_int32 ptaGetIPt (PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
l_int32 ptaGetArrays (PTA *pta, NUMA **pnax, NUMA **pnay)
PTAAptaaCreate (l_int32 n)
void ptaaDestroy (PTAA **pptaa)
l_int32 ptaaAddPta (PTAA *ptaa, PTA *pta, l_int32 copyflag)
l_int32 ptaaExtendArray (PTAA *ptaa)
l_int32 ptaaGetCount (PTAA *ptaa)
PTAptaaGetPta (PTAA *ptaa, l_int32 index, l_int32 accessflag)
PTAAptaaRead (const char *filename)
PTAAptaaReadStream (FILE *fp)
l_int32 ptaaWrite (const char *filename, PTAA *ptaa, l_int32 type)
l_int32 ptaaWriteStream (FILE *fp, PTAA *ptaa, l_int32 type)
PTAptaRead (const char *filename)
PTAptaReadStream (FILE *fp)
l_int32 ptaWrite (const char *filename, PTA *pta, l_int32 type)
l_int32 ptaWriteStream (FILE *fp, PTA *pta, l_int32 type)
BOXptaGetExtent (PTA *pta)
PTAptaGetInsideBox (PTA *ptas, BOX *box)
PTApixFindCornerPixels (PIX *pixs)
l_int32 pixPlotAlongPta (PIX *pixs, PTA *pta, l_int32 outformat, const char *title)
l_int32 ptaContainsPt (PTA *pta, l_int32 x, l_int32 y)
l_int32 ptaTestIntersection (PTA *pta1, PTA *pta2)
PTAptaTransform (PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
PTAptaSubsample (PTA *ptas, l_int32 subfactor)
l_int32 ptaGetLinearLSF (PTA *pta, l_float32 *pa, l_float32 *pb, NUMA **pnafit)
PTAptaGetPixelsFromPix (PIX *pixs, BOX *box)
PIXpixGenerateFromPta (PTA *pta, l_int32 w, l_int32 h)
PTAptaGetBoundaryPixels (PIX *pixs, l_int32 type)
PTAAptaaGetBoundaryPixels (PIX *pixs, l_int32 type, l_int32 connectivity, BOXA **pboxa, PIXA **ppixa)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20
static const l_int32 DEFAULT_SPREADING_FACTOR = 7500

Функции

PTA* pixFindCornerPixels ( PIX pixs  ) 

pixFindCornerPixels()

Input: pixs (1 bpp) Return: pta, or null on error

Notes: (1) Finds the 4 corner-most pixels, as defined by a search inward from each corner, using a 45 degree line.

PIX* pixGenerateFromPta ( PTA pta,
l_int32  w,
l_int32  h 
)

pixGenerateFromPta()

Input: pta w, h (of pix) Return: pix (1 bpp), or null on error

Notes: (1) Points are rounded to nearest ints. (2) Any points outside (w,h) are silently discarded. (3) Output 1 bpp pix has values 1 for each point in the pta.

l_int32 pixPlotAlongPta ( PIX pixs,
PTA pta,
l_int32  outformat,
const char *  title 
)

pixPlotAlongPta()

Input: pixs (any depth) pta (set of points on which to plot) outformat (GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_X11, GPLOT_LATEX) title (<optional> for plot; can be null) Return: 0 if OK, 1 on error

Notes: (1) We remove any existing colormap and clip the pta to the input pixs. (2) This is a debugging function, and does not remove temporary plotting files that it generates. (3) If the image is RGB, three separate plots are generated.

l_int32 ptaaAddPta ( PTAA ptaa,
PTA pta,
l_int32  copyflag 
)

ptaaAddPta()

Input: ptaa pta (to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK, 1 on error

PTAA* ptaaCreate ( l_int32  n  ) 

ptaaCreate()

Input: n (initial number of ptrs) Return: ptaa, or null on error

l_int32 ptaAddPt ( PTA pta,
l_float32  x,
l_float32  y 
)

ptaAddPt()

Input: pta x, y Return: 0 if OK, 1 on error

void ptaaDestroy ( PTAA **  pptaa  ) 

ptaaDestroy()

Input: &ptaa <to be="" nulled>=""> Return: void

l_int32 ptaaExtendArray ( PTAA ptaa  ) 

ptaaExtendArray()

Input: ptaa Return: 0 if OK, 1 on error

PTAA* ptaaGetBoundaryPixels ( PIX pixs,
l_int32  type,
l_int32  connectivity,
BOXA **  pboxa,
PIXA **  ppixa 
)

ptaaGetBoundaryPixels()

Input: pixs (1 bpp) type (L_BOUNDARY_FG, L_BOUNDARY_BG) connectivity (4 or 8) &boxa (<optional return>=""> bounding boxes of the c.c.) &pixa (<optional return>=""> pixa of the c.c.) Return: ptaa, or null on error

Notes: (1) This generates a ptaa of either fg or bg boundary pixels, where each pta has the boundary pixels for a connected component. (2) We can't simply find all the boundary pixels and then select those within the bounding box of each component, because bounding boxes can overlap. It is necessary to extract and dilate or erode each component separately. Note also that special handling is required for bg pixels when the component touches the pix boundary.

l_int32 ptaaGetCount ( PTAA ptaa  ) 

ptaaGetCount()

Input: ptaa Return: count, or 0 if no ptaa

PTA* ptaaGetPta ( PTAA ptaa,
l_int32  index,
l_int32  accessflag 
)

ptaaGetPta()

Input: ptaa index (to the i-th pta) accessflag (L_COPY or L_CLONE) Return: pta, or null on error

PTAA* ptaaRead ( const char *  filename  ) 

ptaaRead()

Input: filename Return: ptaa, or null on error

PTAA* ptaaReadStream ( FILE *  fp  ) 

ptaaReadStream()

Input: stream Return: ptaa, or null on error

l_int32 ptaaWrite ( const char *  filename,
PTAA ptaa,
l_int32  type 
)

ptaaWrite()

Input: filename ptaa type (0 for float values; 1 for integer values) Return: 0 if OK, 1 on error

l_int32 ptaaWriteStream ( FILE *  fp,
PTAA ptaa,
l_int32  type 
)

ptaaWriteStream()

Input: stream ptaa type (0 for float values; 1 for integer values) Return: 0 if OK; 1 on error

l_int32 ptaChangeRefcount ( PTA pta,
l_int32  delta 
)

PTA* ptaClone ( PTA pta  ) 

ptaClone()

Input: pta Return: ptr to same pta, or null on error

l_int32 ptaContainsPt ( PTA pta,
l_int32  x,
l_int32  y 
)

ptaContainsPt()

Input: pta x, y (point) Return: 1 if contained, 0 otherwise or on error

PTA* ptaCopy ( PTA pta  ) 

ptaCopy()

Input: pta Return: copy of pta, or null on error

PTA* ptaCreate ( l_int32  n  ) 

ptaCreate()

Input: n (initial array sizes) Return: pta, or null on error.

PTA* ptaCyclicPerm ( PTA ptas,
l_int32  xs,
l_int32  ys 
)

ptaCyclicPerm()

Input: ptas xs, ys (start point; must be in ptas) Return: ptad (cyclic permutation, starting and ending at (xs, ys), or null on error

Note: we check to insure that ptas is a closed path where the first and last points are identical, and the resulting pta also starts and ends on the same point (which in this case is (xs, ys).

void ptaDestroy ( PTA **  ppta  ) 

ptaDestroy()

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

Note:

  • Decrements the ref count and, if 0, destroys the pta.
  • Always nulls the input ptr.

l_int32 ptaEmpty ( PTA pta  ) 

ptaEmpty()

Input: pta Return: 0 if OK, 1 on error

Note: this only resets the "n" field, for reuse

l_int32 ptaExtendArrays ( PTA pta  ) 

ptaExtendArrays()

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

l_int32 ptaGetArrays ( PTA pta,
NUMA **  pnax,
NUMA **  pnay 
)

ptaGetArrays()

Input: pta &nax, &nay (<return> numas of x and y arrays) Return: 0 if OK; 1 on error or if pta is empty

Notes: (1) This copies the internal arrays into new Numas, and returns them. (2) Manipulates internal arrays in pta and numa directly.

PTA* ptaGetBoundaryPixels ( PIX pixs,
l_int32  type 
)

ptaGetBoundaryPixels()

Input: pixs (1 bpp) type (L_BOUNDARY_FG, L_BOUNDARY_BG) Return: pta, or null on error

Notes: (1) This generates a pta of either fg or bg boundary pixels.

l_int32 ptaGetCount ( PTA pta  ) 

ptaGetCount()

Input: pta Return: count, or 0 if no pta

BOX* ptaGetExtent ( PTA pta  ) 

ptaGetExtent()

Input: pta Return: box, or null on error

Notes: (1) Returns a box of minimum size containing pts in pta.

PTA* ptaGetInsideBox ( PTA ptas,
BOX box 
)

ptaGetInsideBox()

Input: ptas (input pts) box Return: ptad (of pts in ptas that are inside the box), or null on error

l_int32 ptaGetIPt ( PTA pta,
l_int32  index,
l_int32 px,
l_int32 py 
)

ptaGetIPt()

Input: pta index (into arrays) &x, &y (<return> integer values) Return: 0 if OK; 1 on error

l_int32 ptaGetLinearLSF ( PTA pta,
l_float32 pa,
l_float32 pb,
NUMA **  pnafit 
)

ptaGetLinearLSF()

Input: pta &a (<optional return>=""> slope a of least square fit: y = ax + b) &b (<optional return>=""> intercept b of least square fit) &nafit (<optional return>=""> numa of least square fit) Return: 0 if OK, 1 on error

Notes: (1) At least one of: &a and &b must not be null. (2) If both &a and &b are defined, this returns a and b that minimize:

sum (yi - axi -b)^2 i

The method is simple: differentiate this expression w/rt a and b, and solve the resulting two equations for a and b in terms of various sums over the input data (xi, yi). (3) We also allow two special cases, where either a = 0 or b = 0: (a) If &a is given and &b = null, find the linear LSF that goes through the origin (b = 0). (b) If &b is given and &a = null, find the linear LSF with zero slope (a = 0). (4) If is defined, this returns an array of fitted values, corresponding to the two implicit Numa arrays (nax and nay) in pta. Thus, just as you can plot the data in pta as nay vs. nax, you can plot the linear least square fit as nafit vs. nax.

PTA* ptaGetPixelsFromPix ( PIX pixs,
BOX box 
)

ptaGetPixelsFromPix()

Input: pixs (1 bpp) box (<optional> can be null) Return: pta, or null on error

Notes: (1) Generates a pta of fg pixels in the pix, within the box. If box == NULL, it uses the entire pix.

l_int32 ptaGetPt ( PTA pta,
l_int32  index,
l_float32 px,
l_float32 py 
)

ptaGetPt()

Input: pta index (into arrays) &x, &y (<return> float values) Return: 0 if OK; 1 on error

l_int32 ptaGetRefcount ( PTA pta  ) 

l_int32 ptaJoin ( PTA ptad,
PTA ptas,
l_int32  istart,
l_int32  iend 
)

ptaJoin()

Input: ptad (dest pta; add to this one) ptas (source pta; add from this one) istart (starting index in ptas) iend (ending index in ptas; use 0 to cat all) Return: 0 if OK, 1 on error

Notes: (1) istart < 0 is taken to mean 'read from the start' (istart = 0) (2) iend <= 0 means 'read to the end'

PTA* ptaRead ( const char *  filename  ) 

ptaRead()

Input: filename Return: pta, or null on error

PTA* ptaReadStream ( FILE *  fp  ) 

ptaReadStream()

Input: stream Return: pta, or null on error

PTA* ptaRemoveDuplicates ( PTA ptas,
l_uint32  factor 
)

ptaRemoveDuplicates()

Input: ptas (assumed to be integer values) factor (should be larger than the largest point value; use 0 for default) Return: ptad (with duplicates removed), or null on error

PTA* ptaReverse ( PTA ptas,
l_int32  type 
)

ptaReverse()

Input: ptas type (0 for float values; 1 for integer values) Return: ptad (reversed pta), or null on error

PTA* ptaSort ( PTA ptas,
l_int32  sorttype,
l_int32  sortorder,
NUMA **  pnaindex 
)

ptaSort()

Input: ptas sorttype (L_SORT_BY_X, L_SORT_BY_Y) sortorder (L_SORT_INCREASING, L_SORT_DECREASING) &naindex (<optional return>=""> index of sorted order into original array) Return: ptad (sorted version of ptas), or null on error

PTA* ptaSubsample ( PTA ptas,
l_int32  subfactor 
)

ptaSubsample()

Input: ptas subfactor (subsample factor, >= 1) Return: ptad (evenly sampled pt values from ptas, or null on error

l_int32 ptaTestIntersection ( PTA pta1,
PTA pta2 
)

ptaTestIntersection()

Input: pta1, pta2 Return: bval which is 1 if they have any elements in common; 0 otherwise or on error.

PTA* ptaTransform ( PTA ptas,
l_int32  shiftx,
l_int32  shifty,
l_float32  scalex,
l_float32  scaley 
)

ptaTransform()

Input: pta shiftx, shifty scalex, scaley Return: pta, or null on error

Notes: (1) Shift first, then scale.

l_int32 ptaWrite ( const char *  filename,
PTA pta,
l_int32  type 
)

ptaWrite()

Input: filename pta type (0 for float values; 1 for integer values) Return: 0 if OK, 1 on error

l_int32 ptaWriteStream ( FILE *  fp,
PTA pta,
l_int32  type 
)

ptaWriteStream()

Input: stream pta type (0 for float values; 1 for integer values) Return: 0 if OK; 1 on error


Переменные

const l_int32 DEFAULT_SPREADING_FACTOR = 7500 [static]

const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9