Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
ptafunc1.c File Reference
#include <math.h>
#include "allheaders.h"
#include "pix_internal.h"

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846
 

Functions

PTAptaSubsample (PTA *ptas, l_int32 subfactor)
 
l_ok ptaJoin (PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
 
l_ok ptaaJoin (PTAA *ptaad, PTAA *ptaas, l_int32 istart, l_int32 iend)
 
PTAptaReverse (PTA *ptas, l_int32 type)
 
PTAptaTranspose (PTA *ptas)
 
PTAptaCyclicPerm (PTA *ptas, l_int32 xs, l_int32 ys)
 
PTAptaSelectRange (PTA *ptas, l_int32 first, l_int32 last)
 
BOXptaGetBoundingRegion (PTA *pta)
 
l_ok ptaGetRange (PTA *pta, l_float32 *pminx, l_float32 *pmaxx, l_float32 *pminy, l_float32 *pmaxy)
 
PTAptaGetInsideBox (PTA *ptas, BOX *box)
 
PTApixFindCornerPixels (PIX *pixs)
 
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)
 
l_int32 ptaPtInsidePolygon (PTA *pta, l_float32 x, l_float32 y, l_int32 *pinside)
 
l_float32 l_angleBetweenVectors (l_float32 x1, l_float32 y1, l_float32 x2, l_float32 y2)
 
l_int32 ptaPolygonIsConvex (PTA *pta, l_int32 *pisconvex)
 
l_ok ptaGetMinMax (PTA *pta, l_float32 *pxmin, l_float32 *pymin, l_float32 *pxmax, l_float32 *pymax)
 
PTAptaSelectByValue (PTA *ptas, l_float32 xth, l_float32 yth, l_int32 type, l_int32 relation)
 
PTAptaCropToMask (PTA *ptas, PIX *pixm)
 
l_ok ptaGetLinearLSF (PTA *pta, l_float32 *pa, l_float32 *pb, NUMA **pnafit)
 
l_ok ptaGetQuadraticLSF (PTA *pta, l_float32 *pa, l_float32 *pb, l_float32 *pc, NUMA **pnafit)
 
l_ok ptaGetCubicLSF (PTA *pta, l_float32 *pa, l_float32 *pb, l_float32 *pc, l_float32 *pd, NUMA **pnafit)
 
l_ok ptaGetQuarticLSF (PTA *pta, l_float32 *pa, l_float32 *pb, l_float32 *pc, l_float32 *pd, l_float32 *pe, NUMA **pnafit)
 
l_ok ptaNoisyLinearLSF (PTA *pta, l_float32 factor, PTA **pptad, l_float32 *pa, l_float32 *pb, l_float32 *pmederr, NUMA **pnafit)
 
l_ok ptaNoisyQuadraticLSF (PTA *pta, l_float32 factor, PTA **pptad, l_float32 *pa, l_float32 *pb, l_float32 *pc, l_float32 *pmederr, NUMA **pnafit)
 
l_ok applyLinearFit (l_float32 a, l_float32 b, l_float32 x, l_float32 *py)
 
l_ok applyQuadraticFit (l_float32 a, l_float32 b, l_float32 c, l_float32 x, l_float32 *py)
 
l_ok applyCubicFit (l_float32 a, l_float32 b, l_float32 c, l_float32 d, l_float32 x, l_float32 *py)
 
l_ok applyQuarticFit (l_float32 a, l_float32 b, l_float32 c, l_float32 d, l_float32 e, l_float32 x, l_float32 *py)
 
l_ok pixPlotAlongPta (PIX *pixs, PTA *pta, l_int32 outformat, const char *title)
 
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)
 
PTAAptaaIndexLabeledPixels (PIX *pixs, l_int32 *pncc)
 
PTAptaGetNeighborPixLocs (PIX *pixs, l_int32 x, l_int32 y, l_int32 conn)
 
PTAnumaConvertToPta1 (NUMA *na)
 
PTAnumaConvertToPta2 (NUMA *nax, NUMA *nay)
 
l_ok ptaConvertToNuma (PTA *pta, NUMA **pnax, NUMA **pnay)
 
PIXpixDisplayPta (PIX *pixd, PIX *pixs, PTA *pta)
 
PIXpixDisplayPtaaPattern (PIX *pixd, PIX *pixs, PTAA *ptaa, PIX *pixp, l_int32 cx, l_int32 cy)
 
PIXpixDisplayPtaPattern (PIX *pixd, PIX *pixs, PTA *pta, PIX *pixp, l_int32 cx, l_int32 cy, l_uint32 color)
 
PTAptaReplicatePattern (PTA *ptas, PIX *pixp, PTA *ptap, l_int32 cx, l_int32 cy, l_int32 w, l_int32 h)
 
PIXpixDisplayPtaa (PIX *pixs, PTAA *ptaa)
 

Detailed Description


     --------------------------------------
     This file has these Pta utilities:
        - simple rearrangements
        - geometric analysis
        - min/max and filtering
        - least squares fitting
        - interconversions with Pix and Numa
        - display into a pix
     --------------------------------------

     Simple rearrangements
          PTA      *ptaSubsample()
          l_int32   ptaJoin()
          l_int32   ptaaJoin()
          PTA      *ptaReverse()
          PTA      *ptaTranspose()
          PTA      *ptaCyclicPerm()
          PTA      *ptaSelectRange()

     Geometric
          BOX      *ptaGetBoundingRegion()
          l_int32  *ptaGetRange()
          PTA      *ptaGetInsideBox()
          PTA      *pixFindCornerPixels()
          l_int32   ptaContainsPt()
          l_int32   ptaTestIntersection()
          PTA      *ptaTransform()
          l_int32   ptaPtInsidePolygon()
          l_float32 l_angleBetweenVectors()
          l_int32   ptaPolygonIsConvex()

     Min/max and filtering
          l_int32   ptaGetMinMax()
          PTA      *ptaSelectByValue()
          PTA      *ptaCropToMask()

     Least Squares Fit
          l_int32   ptaGetLinearLSF()
          l_int32   ptaGetQuadraticLSF()
          l_int32   ptaGetCubicLSF()
          l_int32   ptaGetQuarticLSF()
          l_int32   ptaNoisyLinearLSF()
          l_int32   ptaNoisyQuadraticLSF()
          l_int32   applyLinearFit()
          l_int32   applyQuadraticFit()
          l_int32   applyCubicFit()
          l_int32   applyQuarticFit()

     Interconversions with Pix
          l_int32   pixPlotAlongPta()
          PTA      *ptaGetPixelsFromPix()
          PIX      *pixGenerateFromPta()
          PTA      *ptaGetBoundaryPixels()
          PTAA     *ptaaGetBoundaryPixels()
          PTAA     *ptaaIndexLabeledPixels()
          PTA      *ptaGetNeighborPixLocs()

     Interconversion with Numa
          PTA      *numaConvertToPta1()
          PTA      *numaConvertToPta2()
          l_int32   ptaConvertToNuma()

     Display Pta and Ptaa
          PIX      *pixDisplayPta()
          PIX      *pixDisplayPtaaPattern()
          PIX      *pixDisplayPtaPattern()
          PTA      *ptaReplicatePattern()
          PIX      *pixDisplayPtaa()

Definition in file ptafunc1.c.

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 111 of file ptafunc1.c.

Function Documentation

◆ applyCubicFit()

l_ok applyCubicFit ( l_float32 a,
l_float32 b,
l_float32 c,
l_float32 d,
l_float32 x,
l_float32 * py )

applyCubicFit()

Parameters
[in]a,b,c,dcubic fit coefficients
[in]x
[out]pyy = a * x^3 + b * x^2 + c * x + d
Returns
0 if OK, 1 on error

Definition at line 1749 of file ptafunc1.c.

◆ applyLinearFit()

l_ok applyLinearFit ( l_float32 a,
l_float32 b,
l_float32 x,
l_float32 * py )

applyLinearFit()

Parameters
[in]a,blinear fit coefficients
[in]x
[out]pyy = a * x + b
Returns
0 if OK, 1 on error

Definition at line 1704 of file ptafunc1.c.

◆ applyQuadraticFit()

l_ok applyQuadraticFit ( l_float32 a,
l_float32 b,
l_float32 c,
l_float32 x,
l_float32 * py )

applyQuadraticFit()

Parameters
[in]a,b,cquadratic fit coefficients
[in]x
[out]pyy = a * x^2 + b * x + c
Returns
0 if OK, 1 on error

Definition at line 1726 of file ptafunc1.c.

◆ applyQuarticFit()

l_ok applyQuarticFit ( l_float32 a,
l_float32 b,
l_float32 c,
l_float32 d,
l_float32 e,
l_float32 x,
l_float32 * py )

applyQuarticFit()

Parameters
[in]a,b,c,d,equartic fit coefficients
[in]x
[out]pyy = a * x^4 + b * x^3 + c * x^2 + d * x + e
Returns
0 if OK, 1 on error

Definition at line 1773 of file ptafunc1.c.

◆ l_angleBetweenVectors()

l_float32 l_angleBetweenVectors ( l_float32 x1,
l_float32 y1,
l_float32 x2,
l_float32 y2 )

l_angleBetweenVectors()

Parameters
[in]x1,y1end point of first vector
[in]x2,y2end point of second vector
Returns
angle radians, or 0.0 on error
Notes:
     (1) This gives the angle between two vectors, going between
         vector1 (x1,y1) and vector2 (x2,y2).  The angle is swept
         out from 1 --> 2.  If this is clockwise, the angle is
         positive, but the result is folded into the interval [-pi, pi].

Definition at line 803 of file ptafunc1.c.

Referenced by ptaPtInsidePolygon().

◆ numaConvertToPta1()

PTA * numaConvertToPta1 ( NUMA * na)

numaConvertToPta1()

Parameters
[in]nanuma with implicit y(x)
Returns
pta if OK; null on error

Definition at line 2238 of file ptafunc1.c.

◆ numaConvertToPta2()

PTA * numaConvertToPta2 ( NUMA * nax,
NUMA * nay )

numaConvertToPta2()

Parameters
[in]nax
[in]nay
Returns
pta if OK; null on error

Definition at line 2266 of file ptafunc1.c.

◆ pixDisplayPta()

PIX * pixDisplayPta ( PIX * pixd,
PIX * pixs,
PTA * pta )

pixDisplayPta()

Parameters
[in]pixdcan be same as pixs or NULL; 32 bpp if in-place
[in]pixs1, 2, 4, 8, 16 or 32 bpp
[in]ptaof path to be plotted
Returns
pixd 32 bpp RGB version of pixs, with path in green.
Notes:
     (1) To write on an existing pixs, pixs must be 32 bpp and
         call with pixd == pixs:
            pixDisplayPta(pixs, pixs, pta);
         To write to a new pix, use pixd == NULL and call:
            pixd = pixDisplayPta(NULL, pixs, pta);
     (2) On error, returns pixd to avoid losing pixs if called as
            pixs = pixDisplayPta(pixs, pixs, pta);

Definition at line 2349 of file ptafunc1.c.

◆ pixDisplayPtaa()

PIX * pixDisplayPtaa ( PIX * pixs,
PTAA * ptaa )

pixDisplayPtaa()

Parameters
[in]pixs1, 2, 4, 8, 16 or 32 bpp
[in]ptaaarray of paths to be plotted
Returns
pixd 32 bpp RGB version of pixs, with paths plotted in different colors, or NULL on error

Definition at line 2587 of file ptafunc1.c.

References L_CLONE.

◆ pixDisplayPtaaPattern()

PIX * pixDisplayPtaaPattern ( PIX * pixd,
PIX * pixs,
PTAA * ptaa,
PIX * pixp,
l_int32 cx,
l_int32 cy )

pixDisplayPtaaPattern()

Parameters
[in]pixd32 bpp
[in]pixs1, 2, 4, 8, 16 or 32 bpp; 32 bpp if in place
[in]ptaagiving locations at which the pattern is displayed
[in]pixp1 bpp pattern to be placed such that its reference point co-locates with each point in pta
[in]cx,cyreference point in pattern
Returns
pixd 32 bpp RGB version of pixs.
Notes:
     (1) To write on an existing pixs, pixs must be 32 bpp and
         call with pixd == pixs:
            pixDisplayPtaPattern(pixs, pixs, pta, ...);
         To write to a new pix, use pixd == NULL and call:
            pixd = pixDisplayPtaPattern(NULL, pixs, pta, ...);
     (2) Puts a random color on each pattern associated with a pta.
     (3) On error, returns pixd to avoid losing pixs if called as
            pixs = pixDisplayPtaPattern(pixs, pixs, pta, ...);
     (4) A typical pattern to be used is a circle, generated with
            generatePtaFilledCircle()

Definition at line 2413 of file ptafunc1.c.

References L_CLONE, and pixDisplayPtaPattern().

◆ pixDisplayPtaPattern()

PIX * pixDisplayPtaPattern ( PIX * pixd,
PIX * pixs,
PTA * pta,
PIX * pixp,
l_int32 cx,
l_int32 cy,
l_uint32 color )

pixDisplayPtaPattern()

Parameters
[in]pixdcan be same as pixs or NULL; 32 bpp if in-place
[in]pixs1, 2, 4, 8, 16 or 32 bpp
[in]ptagiving locations at which the pattern is displayed
[in]pixp1 bpp pattern to be placed such that its reference point co-locates with each point in pta
[in]cx,cyreference point in pattern
[in]colorin 0xrrggbb00 format
Returns
pixd 32 bpp RGB version of pixs.
Notes:
     (1) To write on an existing pixs, pixs must be 32 bpp and
         call with pixd == pixs:
            pixDisplayPtaPattern(pixs, pixs, pta, ...);
         To write to a new pix, use pixd == NULL and call:
            pixd = pixDisplayPtaPattern(NULL, pixs, pta, ...);
     (2) On error, returns pixd to avoid losing pixs if called as
            pixs = pixDisplayPtaPattern(pixs, pixs, pta, ...);
     (3) A typical pattern to be used is a circle, generated with
            generatePtaFilledCircle()

Definition at line 2478 of file ptafunc1.c.

References ptaReplicatePattern().

Referenced by pixDisplayPtaaPattern().

◆ pixFindCornerPixels()

PTA * pixFindCornerPixels ( PIX * pixs)

pixFindCornerPixels()

Parameters
[in]pixs1 bpp
Returns
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.

Definition at line 559 of file ptafunc1.c.

References GET_DATA_BIT.

◆ pixGenerateFromPta()

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

pixGenerateFromPta()

Parameters
[in]pta
[in]w,hof pix
Returns
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.

Definition at line 1962 of file ptafunc1.c.

◆ pixPlotAlongPta()

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

pixPlotAlongPta()

Parameters
[in]pixsany depth
[in]ptaset of points on which to plot
[in]outformatGPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX
[in]title[optional] for plot; can be null
Returns
0 if OK, 1 on error
Notes:
     (1) This is a debugging function.
     (2) Removes existing colormaps and clips the pta to the input pixs.
     (3) If the image is RGB, three separate plots are generated.

Definition at line 1812 of file ptafunc1.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, GET_DATA_BYTE, and REMOVE_CMAP_BASED_ON_SRC.

◆ ptaaGetBoundaryPixels()

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

ptaaGetBoundaryPixels()

Parameters
[in]pixs1 bpp
[in]typeL_BOUNDARY_FG, L_BOUNDARY_BG
[in]connectivity4 or 8
[out]pboxa[optional] bounding boxes of the c.c.
[out]ppixa[optional] pixa of the c.c.
Returns
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.

Definition at line 2048 of file ptafunc1.c.

References L_CLONE, L_INSERT, ptaGetBoundaryPixels(), and ptaTransform().

◆ ptaaIndexLabeledPixels()

PTAA * ptaaIndexLabeledPixels ( PIX * pixs,
l_int32 * pncc )

ptaaIndexLabeledPixels()

Parameters
[in]pixs32 bpp, of indices of c.c.
[out]pncc[optional] number of connected components
Returns
ptaa, or NULL on error
Notes:
     (1) The pixel values in pixs are the index of the connected component
         to which the pixel belongs; pixs is typically generated from
         a 1 bpp pix by pixConnCompTransform().  Background pixels in
         the generating 1 bpp pix are represented in pixs by 0.
         We do not check that the pixel values are correctly labelled.
     (2) Each pta in the returned ptaa gives the pixel locations
         corresponding to a connected component, with the label of each
         given by the index of the pta into the ptaa.
     (3) Initialize with the first pta in ptaa being empty and
         representing the background value (index 0) in the pix.

Definition at line 2129 of file ptafunc1.c.

◆ ptaaJoin()

l_ok ptaaJoin ( PTAA * ptaad,
PTAA * ptaas,
l_int32 istart,
l_int32 iend )

ptaaJoin()

Parameters
[in]ptaaddest ptaa; add to this one
[in]ptaassource ptaa; add from this one
[in]istartstarting index in ptaas
[in]iendending index in ptaas; use -1 to cat all
Returns
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'
     (3) if ptas == NULL, this is a no-op

Definition at line 214 of file ptafunc1.c.

References L_CLONE, and L_INSERT.

◆ ptaContainsPt()

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

ptaContainsPt()

Parameters
[in]pta
[in]x,ypoint
Returns
1 if contained, 0 otherwise or on error

Definition at line 649 of file ptafunc1.c.

◆ ptaConvertToNuma()

l_ok ptaConvertToNuma ( PTA * pta,
NUMA ** pnax,
NUMA ** pnay )

ptaConvertToNuma()

Parameters
[in]pta
[out]pnaxaddr of nax
[out]pnayaddr of nay
Returns
0 if OK, 1 on error

Definition at line 2300 of file ptafunc1.c.

◆ ptaCropToMask()

PTA * ptaCropToMask ( PTA * ptas,
PIX * pixm )

ptaCropToMask()

Parameters
[in]ptasinput pta
[in]pixm1 bpp mask
Returns
ptad with only pts under the mask fg, or NULL on error

Definition at line 1004 of file ptafunc1.c.

◆ ptaCyclicPerm()

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

ptaCyclicPerm()

Parameters
[in]ptas
[in]xs,ysstart point; must be in ptas
Returns
ptad cyclic permutation, starting and ending at (xs, ys, or NULL on error
Notes:
     (1) Check to insure that (a) ptas is a closed path where
         the first and last points are identical, and (b) the
         resulting pta also starts and ends on the same point
         (which in this case is (xs, ys).

Definition at line 324 of file ptafunc1.c.

◆ ptaGetBoundaryPixels()

PTA * ptaGetBoundaryPixels ( PIX * pixs,
l_int32 type )

ptaGetBoundaryPixels()

Parameters
[in]pixs1 bpp
[in]typeL_BOUNDARY_FG, L_BOUNDARY_BG
Returns
pta, or NULL on error
Notes:
     (1) This generates a pta of either fg or bg boundary pixels.
     (2) See also pixGeneratePtaBoundary() for rendering of
         fg boundary pixels.

Definition at line 2001 of file ptafunc1.c.

References ptaGetPixelsFromPix().

Referenced by ptaaGetBoundaryPixels().

◆ ptaGetBoundingRegion()

BOX * ptaGetBoundingRegion ( PTA * pta)

ptaGetBoundingRegion()

Parameters
[in]pta
Returns
box, or NULL on error
Notes:
     (1) This is used when the pta represents a set of points in
         a two-dimensional image.  It returns the box of minimum
         size containing the pts in the pta.

Definition at line 431 of file ptafunc1.c.

◆ ptaGetCubicLSF()

l_ok ptaGetCubicLSF ( PTA * pta,
l_float32 * pa,
l_float32 * pb,
l_float32 * pc,
l_float32 * pd,
NUMA ** pnafit )

ptaGetCubicLSF()

Parameters
[in]pta
[out]pa[optional] coeff a of LSF: y = ax^3 + bx^2 + cx + d
[out]pb[optional] coeff b of LSF
[out]pc[optional] coeff c of LSF
[out]pd[optional] coeff d of LSF
[out]pnafit[optional] numa of least square fit
Returns
0 if OK, 1 on error
Notes:
     (1) This does a cubic least square fit to the set of points
         in pta.  That is, it finds coefficients a, b, c and d
         that minimize:

             sum (yi - a*xi*xi*xi -b*xi*xi -c*xi - d)^2
              i

         Differentiate this expression w/rt a, b, c and d, and solve
         the resulting four equations for these coefficients in
         terms of various sums over the input data (xi, yi).
         The four equations are in the form:
            f[0][0]a + f[0][1]b + f[0][2]c + f[0][3] = g[0]
            f[1][0]a + f[1][1]b + f[1][2]c + f[1][3] = g[1]
            f[2][0]a + f[2][1]b + f[2][2]c + f[2][3] = g[2]
            f[3][0]a + f[3][1]b + f[3][2]c + f[3][3] = g[3]
     (2) If &nafit 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.
         Get the nax array using ptaGetArrays(pta, &nax, NULL);

Definition at line 1279 of file ptafunc1.c.

References gaussjordan(), and Pta::y.

◆ ptaGetInsideBox()

PTA * ptaGetInsideBox ( PTA * ptas,
BOX * box )

ptaGetInsideBox()

Parameters
[in]ptasinput pts
[in]box
Returns
ptad of pts in ptas that are inside the box, or NULL on error

Definition at line 521 of file ptafunc1.c.

◆ ptaGetLinearLSF()

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

ptaGetLinearLSF()

Parameters
[in]pta
[out]pa[optional] slope a of least square fit: y = ax + b
[out]pb[optional] intercept b of least square fit
[out]pnafit[optional] numa of least square fit
Returns
0 if OK, 1 on error
Notes:
     (1) Either or both &a and &b must be input.  They determine the
         type of line that is fit.
     (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 &nafit 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.
         Get the nax array using ptaGetArrays(pta, &nax, NULL);

Definition at line 1069 of file ptafunc1.c.

References Pta::y.

Referenced by ptaNoisyLinearLSF().

◆ ptaGetMinMax()

l_ok ptaGetMinMax ( PTA * pta,
l_float32 * pxmin,
l_float32 * pymin,
l_float32 * pxmax,
l_float32 * pymax )

ptaGetMinMax()

Parameters
[in]pta
[out]pxmin[optional] min of x
[out]pymin[optional] min of y
[out]pxmax[optional] max of x
[out]pymax[optional] max of y
Returns
0 if OK, 1 on error. If pta is empty, requested values are returned as -1.0.

Definition at line 887 of file ptafunc1.c.

◆ ptaGetNeighborPixLocs()

PTA * ptaGetNeighborPixLocs ( PIX * pixs,
l_int32 x,
l_int32 y,
l_int32 conn )

ptaGetNeighborPixLocs()

Parameters
[in]pixsany depth
[in]x,ypixel from which we search for nearest neighbors
[in]conn4 or 8 connectivity
Returns
pta, or NULL on error
Notes:
     (1) Generates a pta of all valid neighbor pixel locations,
         or NULL on error.

Definition at line 2184 of file ptafunc1.c.

◆ ptaGetPixelsFromPix()

PTA * ptaGetPixelsFromPix ( PIX * pixs,
BOX * box )

ptaGetPixelsFromPix()

Parameters
[in]pixs1 bpp
[in]box[optional] can be null
Returns
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.

Definition at line 1911 of file ptafunc1.c.

References GET_DATA_BIT.

Referenced by ptaGetBoundaryPixels(), and ptaReplicatePattern().

◆ ptaGetQuadraticLSF()

l_ok ptaGetQuadraticLSF ( PTA * pta,
l_float32 * pa,
l_float32 * pb,
l_float32 * pc,
NUMA ** pnafit )

ptaGetQuadraticLSF()

Parameters
[in]pta
[out]pa[optional] coeff a of LSF: y = ax^2 + bx + c
[out]pb[optional] coeff b of LSF: y = ax^2 + bx + c
[out]pc[optional] coeff c of LSF: y = ax^2 + bx + c
[out]pnafit[optional] numa of least square fit
Returns
0 if OK, 1 on error
Notes:
     (1) This does a quadratic least square fit to the set of points
         in pta.  That is, it finds coefficients a, b and c that minimize:

             sum (yi - a*xi*xi -b*xi -c)^2
              i

         The method is simple: differentiate this expression w/rt
         a, b and c, and solve the resulting three equations for these
         coefficients in terms of various sums over the input data (xi, yi).
         The three equations are in the form:
            f[0][0]a + f[0][1]b + f[0][2]c = g[0]
            f[1][0]a + f[1][1]b + f[1][2]c = g[1]
            f[2][0]a + f[2][1]b + f[2][2]c = g[2]
     (2) If &nafit 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.
         Get the nax array using ptaGetArrays(pta, &nax, NULL);

Definition at line 1168 of file ptafunc1.c.

References gaussjordan(), and Pta::y.

Referenced by ptaNoisyQuadraticLSF().

◆ ptaGetQuarticLSF()

l_ok ptaGetQuarticLSF ( PTA * pta,
l_float32 * pa,
l_float32 * pb,
l_float32 * pc,
l_float32 * pd,
l_float32 * pe,
NUMA ** pnafit )

ptaGetQuarticLSF()

Parameters
[in]pta
[out]pa[optional] coeff a of LSF: y = ax^4 + bx^3 + cx^2 + dx + e
[out]pb[optional] coeff b of LSF
[out]pc[optional] coeff c of LSF
[out]pd[optional] coeff d of LSF
[out]pe[optional] coeff e of LSF
[out]pnafit[optional] numa of least square fit
Returns
0 if OK, 1 on error
Notes:
     (1) This does a quartic least square fit to the set of points
         in pta.  That is, it finds coefficients a, b, c, d and 3
         that minimize:

             sum (yi - a*xi*xi*xi*xi -b*xi*xi*xi -c*xi*xi - d*xi - e)^2
              i

         Differentiate this expression w/rt a, b, c, d and e, and solve
         the resulting five equations for these coefficients in
         terms of various sums over the input data (xi, yi).
         The five equations are in the form:
            f[0][0]a + f[0][1]b + f[0][2]c + f[0][3] + f[0][4] = g[0]
            f[1][0]a + f[1][1]b + f[1][2]c + f[1][3] + f[1][4] = g[1]
            f[2][0]a + f[2][1]b + f[2][2]c + f[2][3] + f[2][4] = g[2]
            f[3][0]a + f[3][1]b + f[3][2]c + f[3][3] + f[3][4] = g[3]
            f[4][0]a + f[4][1]b + f[4][2]c + f[4][3] + f[4][4] = g[4]
     (2) If &nafit 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.
         Get the nax array using ptaGetArrays(pta, &nax, NULL);

Definition at line 1407 of file ptafunc1.c.

References gaussjordan(), and Pta::y.

◆ ptaGetRange()

l_ok ptaGetRange ( PTA * pta,
l_float32 * pminx,
l_float32 * pmaxx,
l_float32 * pminy,
l_float32 * pmaxy )

ptaGetRange()

Parameters
[in]pta
[out]pminx[optional] min value of x
[out]pmaxx[optional] max value of x
[out]pminy[optional] min value of y
[out]pmaxy[optional] max value of y
Returns
0 if OK, 1 on error
Notes:
     (1) We can use pts to represent pairs of floating values, that
         are not necessarily tied to a two-dimension region.  For
         example, the pts can represent a general function y(x).

Definition at line 473 of file ptafunc1.c.

◆ ptaJoin()

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

ptaJoin()

Parameters
[in]ptaddest pta; add to this one
[in]ptassource pta; add from this one
[in]istartstarting index in ptas
[in]iendending index in ptas; use -1 to cat all
Returns
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'
     (3) if ptas == NULL, this is a no-op

Definition at line 166 of file ptafunc1.c.

◆ ptaNoisyLinearLSF()

l_ok ptaNoisyLinearLSF ( PTA * pta,
l_float32 factor,
PTA ** pptad,
l_float32 * pa,
l_float32 * pb,
l_float32 * pmederr,
NUMA ** pnafit )

ptaNoisyLinearLSF()

Parameters
[in]pta
[in]factorreject outliers with error greater than this number of medians; typically ~ 3
[out]pptad[optional] with outliers removed
[out]pa[optional] slope a of least square fit: y = ax + b
[out]pb[optional] intercept b of least square fit
[out]pmederr[optional] median error
[out]pnafit[optional] numa of least square fit to ptad
Returns
0 if OK, 1 on error
Notes:
     (1) This does a linear least square fit to the set of points
         in pta.  It then evaluates the errors and removes points
         whose error is >= factor * median_error.  It then re-runs
         the linear LSF on the resulting points.
     (2) Either or both &a and &b must be input.  They determine the
         type of line that is fit.
     (3) The median error can give an indication of how good the fit
         is likely to be.

Definition at line 1541 of file ptafunc1.c.

References ptaGetLinearLSF().

◆ ptaNoisyQuadraticLSF()

l_ok ptaNoisyQuadraticLSF ( PTA * pta,
l_float32 factor,
PTA ** pptad,
l_float32 * pa,
l_float32 * pb,
l_float32 * pc,
l_float32 * pmederr,
NUMA ** pnafit )

ptaNoisyQuadraticLSF()

Parameters
[in]pta
[in]factorreject outliers with error greater than this number of medians; typically ~ 3
[out]pptad[optional] with outliers removed
[out]pa[optional] coeff a of LSF: y = ax^2 + bx + c
[out]pb[optional] coeff b of LSF: y = ax^2 + bx + c
[out]pc[optional] coeff c of LSF: y = ax^2 + bx + c
[out]pmederr[optional] median error
[out]pnafit[optional] numa of least square fit to ptad
Returns
0 if OK, 1 on error
Notes:
     (1) This does a quadratic least square fit to the set of points
         in pta.  It then evaluates the errors and removes points
         whose error is >= factor * median_error.  It then re-runs
         a quadratic LSF on the resulting points.

Definition at line 1626 of file ptafunc1.c.

References ptaGetQuadraticLSF().

◆ ptaPolygonIsConvex()

l_int32 ptaPolygonIsConvex ( PTA * pta,
l_int32 * pisconvex )

ptaPolygonIsConvex()

Parameters
[in]ptacorners of polygon
[out]pisconvex1 if convex; 0 otherwise
Returns
0 if OK, 1 on error
Notes:
     (1) A Pta of size n describes a polygon with n sides, where
         the n-th side goes from point[n - 1] to point[0].
     (2) The pta must describe a CLOCKWISE traversal of the boundary
         of the polygon.
     (3) Algorithm: traversing the boundary in a cw direction, the
         polygon interior is always on the right.  If the polygon is
         convex, for each set of 3 points, the third point is either
         on the ray extending from the first point and going through
         the second point, or to the right of it.

Definition at line 838 of file ptafunc1.c.

◆ ptaPtInsidePolygon()

l_int32 ptaPtInsidePolygon ( PTA * pta,
l_float32 x,
l_float32 y,
l_int32 * pinside )

ptaPtInsidePolygon()

Parameters
[in]ptavertices of a polygon
[in]x,ypoint to be tested
[out]pinside1 if inside; 0 if outside or on boundary
Returns
1 if OK, 0 on error

The abs value of the sum of the angles subtended from a point by the sides of a polygon, when taken in order traversing the polygon, is 0 if the point is outside the polygon and 2*pi if inside. The sign will be positive if traversed cw and negative if ccw.

Definition at line 753 of file ptafunc1.c.

References l_angleBetweenVectors().

◆ ptaReplicatePattern()

PTA * ptaReplicatePattern ( PTA * ptas,
PIX * pixp,
PTA * ptap,
l_int32 cx,
l_int32 cy,
l_int32 w,
l_int32 h )

ptaReplicatePattern()

Parameters
[in]ptas"sparse" input pta
[in]pixp[optional] 1 bpp pattern, to be replicated in output pta
[in]ptap[optional] set of pts, to be replicated in output pta
[in]cx,cyreference point in pattern
[in]w,hclipping sizes for output pta
Returns
ptad with all points of replicated pattern, or NULL on error
Notes:
     (1) You can use either the image pixp or the set of pts ptap.
     (2) The pattern is placed with its reference point at each point
         in ptas, and all the fg pixels are colleced into ptad.
         For pixp, this is equivalent to blitting pixp at each point
         in ptas, and then converting the resulting pix to a pta.

Definition at line 2537 of file ptafunc1.c.

References ptaGetPixelsFromPix().

Referenced by pixDisplayPtaPattern().

◆ ptaReverse()

PTA * ptaReverse ( PTA * ptas,
l_int32 type )

ptaReverse()

Parameters
[in]ptas
[in]type0 for float values; 1 for integer values
Returns
ptad reversed pta, or NULL on error

Definition at line 252 of file ptafunc1.c.

◆ ptaSelectByValue()

PTA * ptaSelectByValue ( PTA * ptas,
l_float32 xth,
l_float32 yth,
l_int32 type,
l_int32 relation )

ptaSelectByValue()

Parameters
[in]ptas
[in]xth,yththreshold values
[in]typeL_SELECT_XVAL, L_SELECT_YVAL, L_SELECT_IF_EITHER, L_SELECT_IF_BOTH
[in]relationL_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE
Returns
ptad filtered set, or NULL on error

Definition at line 938 of file ptafunc1.c.

References L_SELECT_IF_BOTH, L_SELECT_IF_EITHER, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, L_SELECT_XVAL, and L_SELECT_YVAL.

◆ ptaSelectRange()

PTA * ptaSelectRange ( PTA * ptas,
l_int32 first,
l_int32 last )

ptaSelectRange()

Parameters
[in]ptas
[in]firstuse 0 to select from the beginning
[in]lastuse -1 to select to the end
Returns
ptad, or NULL on error

Definition at line 378 of file ptafunc1.c.

◆ ptaSubsample()

PTA * ptaSubsample ( PTA * ptas,
l_int32 subfactor )

ptaSubsample()

Parameters
[in]ptas
[in]subfactorsubsample factor, >= 1
Returns
ptad evenly sampled pt values from ptas, or NULL on error

Definition at line 125 of file ptafunc1.c.

◆ ptaTestIntersection()

l_int32 ptaTestIntersection ( PTA * pta1,
PTA * pta2 )

ptaTestIntersection()

Parameters
[in]pta1,pta2
Returns
bval which is 1 if they have any elements in common; 0 otherwise or on error.

Definition at line 676 of file ptafunc1.c.

◆ ptaTransform()

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

ptaTransform()

Parameters
[in]ptas
[in]shiftx,shifty
[in]scalex,scaley
Returns
pta, or NULL on error
Notes:
     (1) Shift first, then scale.

Definition at line 715 of file ptafunc1.c.

Referenced by ptaaGetBoundaryPixels().

◆ ptaTranspose()

PTA * ptaTranspose ( PTA * ptas)

ptaTranspose()

Parameters
[in]ptas
Returns
ptad with x and y values swapped, or NULL on error

Definition at line 286 of file ptafunc1.c.