Leptonica 1.68
C Image Processing Library

numafunc1.c File Reference

Arithmetic, data extraction, interpolation, sorting on numas. More...

#include <stdlib.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

NUMAnumaArithOp (NUMA *nad, NUMA *na1, NUMA *na2, l_int32 op)
NUMAnumaLogicalOp (NUMA *nad, NUMA *na1, NUMA *na2, l_int32 op)
NUMAnumaInvert (NUMA *nad, NUMA *nas)
l_int32 numaGetMin (NUMA *na, l_float32 *pminval, l_int32 *piminloc)
l_int32 numaGetMax (NUMA *na, l_float32 *pmaxval, l_int32 *pimaxloc)
l_int32 numaGetSum (NUMA *na, l_float32 *psum)
NUMAnumaGetPartialSums (NUMA *na)
l_int32 numaGetSumOnInterval (NUMA *na, l_int32 first, l_int32 last, l_float32 *psum)
l_int32 numaHasOnlyIntegers (NUMA *na, l_int32 maxsamples, l_int32 *pallints)
NUMAnumaSubsample (NUMA *nas, l_int32 subfactor)
NUMAnumaMakeDelta (NUMA *nas)
NUMAnumaMakeSequence (l_float32 startval, l_float32 increment, l_int32 size)
NUMAnumaMakeConstant (l_float32 val, l_int32 size)
NUMAnumaAddBorder (NUMA *nas, l_int32 left, l_int32 right, l_float32 val)
NUMAnumaAddSpecifiedBorder (NUMA *nas, l_int32 left, l_int32 right, l_int32 type)
NUMAnumaRemoveBorder (NUMA *nas, l_int32 left, l_int32 right)
l_int32 numaGetNonzeroRange (NUMA *na, l_float32 eps, l_int32 *pfirst, l_int32 *plast)
l_int32 numaGetCountRelativeToZero (NUMA *na, l_int32 type, l_int32 *pcount)
NUMAnumaClipToInterval (NUMA *nas, l_int32 first, l_int32 last)
NUMAnumaMakeThresholdIndicator (NUMA *nas, l_float32 thresh, l_int32 type)
NUMAnumaUniformSampling (NUMA *nas, l_int32 nsamp)
NUMAnumaLowPassIntervals (NUMA *nas, l_float32 thresh, l_float32 maxn)
NUMAnumaThresholdEdges (NUMA *nas, l_float32 thresh1, l_float32 thresh2, l_float32 maxn)
l_int32 numaGetSpanValues (NUMA *na, l_int32 span, l_int32 *pstart, l_int32 *pend)
l_int32 numaGetEdgeValues (NUMA *na, l_int32 edge, l_int32 *pstart, l_int32 *pend, l_int32 *psign)
l_int32 numaInterpolateEqxVal (l_float32 startx, l_float32 deltax, NUMA *nay, l_int32 type, l_float32 xval, l_float32 *pyval)
l_int32 numaInterpolateArbxVal (NUMA *nax, NUMA *nay, l_int32 type, l_float32 xval, l_float32 *pyval)
l_int32 numaInterpolateEqxInterval (l_float32 startx, l_float32 deltax, NUMA *nasy, l_int32 type, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnax, NUMA **pnay)
l_int32 numaInterpolateArbxInterval (NUMA *nax, NUMA *nay, l_int32 type, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnadx, NUMA **pnady)
l_int32 numaFitMax (NUMA *na, l_float32 *pmaxval, NUMA *naloc, l_float32 *pmaxloc)
l_int32 numaDifferentiateInterval (NUMA *nax, NUMA *nay, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnadx, NUMA **pnady)
l_int32 numaIntegrateInterval (NUMA *nax, NUMA *nay, l_float32 x0, l_float32 x1, l_int32 npts, l_float32 *psum)
NUMAnumaSort (NUMA *naout, NUMA *nain, l_int32 sortorder)
NUMAnumaGetSortIndex (NUMA *na, l_int32 sortorder)
NUMAnumaSortByIndex (NUMA *nas, NUMA *naindex)
l_int32 numaIsSorted (NUMA *nas, l_int32 sortorder, l_int32 *psorted)
l_int32 numaSortPair (NUMA *nax, NUMA *nay, l_int32 sortorder, NUMA **pnasx, NUMA **pnasy)
NUMAnumaPseudorandomSequence (l_int32 size, l_int32 seed)
NUMAnumaRandomPermutation (NUMA *nas, l_int32 seed)
l_int32 numaGetRankValue (NUMA *na, l_float32 fract, l_float32 *pval)
l_int32 numaGetMedian (NUMA *na, l_float32 *pval)
l_int32 numaGetMode (NUMA *na, l_float32 *pval, l_int32 *pcount)
l_int32 numaJoin (NUMA *nad, NUMA *nas, l_int32 istart, l_int32 iend)
NUMAnumaaFlattenToNuma (NUMAA *naa)

Detailed Description

Arithmetic, data extraction, interpolation, sorting on numas.

    Arithmetic and logic
        NUMA        *numaArithOp()
        NUMA        *numaLogicalOp()
        NUMA        *numaInvert()

    Simple extractions
        l_int32      numaGetMin()
        l_int32      numaGetMax()
        l_int32      numaGetSum()
        NUMA        *numaGetPartialSums()
        l_int32      numaGetSumOnInterval()
        l_int32      numaHasOnlyIntegers()
        NUMA        *numaSubsample()
        NUMA        *numaMakeDelta()
        NUMA        *numaMakeSequence()
        NUMA        *numaMakeConstant()
        NUMA        *numaAddBorder()
        NUMA        *numaAddSpecifiedBorder()
        NUMA        *numaRemoveBorder()
        l_int32      numaGetNonzeroRange()
        l_int32      numaGetCountRelativeToZero()
        NUMA        *numaClipToInterval()
        NUMA        *numaMakeThresholdIndicator()
        NUMA        *numaUniformSampling()

    Signal feature extraction
        NUMA        *numaLowPassIntervals()
        NUMA        *numaThresholdEdges()
        NUMA        *numaGetSpanValues()
        NUMA        *numaGetEdgeValues()

    Interpolation
        l_int32      numaInterpolateEqxVal()
        l_int32      numaInterpolateEqxInterval()
        l_int32      numaInterpolateArbxVal()
        l_int32      numaInterpolateArbxInterval()

    Functions requiring interpolation
        l_int32      numaFitMax()
        l_int32      numaDifferentiateInterval()
        l_int32      numaIntegrateInterval()

    Sorting
        NUMA        *numaSort()
        NUMA        *numaGetSortIndex()
        NUMA        *numaSortByIndex()
        l_int32      numaIsSorted()
        l_int32      numaSortPair()

    Random permutation
        NUMA        *numaPseudorandomSequence()
        NUMA        *numaRandomPermutation()

    Functions requiring sorting
        l_int32      numaGetRankValue()
        l_int32      numaGetMedian()
        l_int32      numaGetMode()

    Numa combination
        l_int32      numaJoin()
        NUMA        *numaaFlattenToNuma()


  Things to remember when using the Numa:

  (1) The numa is a struct, not an array.  Always use accessors
      (see numabasic.c), never the fields directly.

  (2) The number array holds l_float32 values.  It can also
      be used to store l_int32 values.  See numabasic.c for
      details on using the accessors.

  (3) If you use numaCreate(), no numbers are stored and the size is 0.
      You have to add numbers to increase the size.
      If you want to start with a numa of a fixed size, with each
      entry initialized to the same value, use numaMakeConstant().

  (4) Occasionally, in the comments we denote the i-th element of a
      numa by na[i].  This is conceptual only -- the numa is not an array!

Definition in file numafunc1.c.


Function Documentation

NUMA* numaArithOp ( NUMA nad,
NUMA na1,
NUMA na2,
l_int32  op 
)

numaArithOp()

Input: nad (<optional> can be null or equal to na1 (in-place) na1 na2 op (L_ARITH_ADD, L_ARITH_SUBTRACT, L_ARITH_MULTIPLY, L_ARITH_DIVIDE) Return: nad (always: operation applied to na1 and na2)

Notes: (1) The sizes of na1 and na2 must be equal. (2) nad can only null or equal to na1. (3) To add a constant to a numa, or to multipy a numa by a constant, use numaTransform().

Definition at line 125 of file numafunc1.c.

References ERROR_PTR, L_ARITH_ADD, L_ARITH_DIVIDE, L_ARITH_MULTIPLY, L_ARITH_SUBTRACT, numaCopy(), numaGetCount(), numaGetFValue(), numaSetValue(), and PROCNAME.

Referenced by GenerateSplitPlot().

NUMA* numaLogicalOp ( NUMA nad,
NUMA na1,
NUMA na2,
l_int32  op 
)

numaLogicalOp()

Input: nad (<optional> can be null or equal to na1 (in-place) na1 na2 op (L_UNION, L_INTERSECTION, L_SUBTRACTION, L_EXCLUSIVE_OR) Return: nad (always: operation applied to na1 and na2)

Notes: (1) The sizes of na1 and na2 must be equal. (2) nad can only null or equal to na1. (3) This is intended for use with indicator arrays (0s and 1s). Input data is extracted as integers (0 == false, anything else == true); output results are 0 and 1. (4) L_SUBTRACTION is subtraction of val2 from val1. For bit logical arithmetic this is (val1 & ~val2), but because these values are integers, we use (val1 && !val2).

Definition at line 203 of file numafunc1.c.

References ERROR_PTR, L_EXCLUSIVE_OR, L_INTERSECTION, L_SUBTRACTION, L_UNION, numaCopy(), numaGetCount(), numaGetIValue(), numaSetValue(), and PROCNAME.

Referenced by main().

NUMA* numaInvert ( NUMA nad,
NUMA nas 
)

numaInvert()

Input: nad (<optional> can be null or equal to nas (in-place) nas Return: nad (always: 'inverts' nas)

Notes: (1) This is intended for use with indicator arrays (0s and 1s). It gives a boolean-type output, taking the input as an integer and inverting it: 0 --> 1 anything else --> 0

Definition at line 272 of file numafunc1.c.

References ERROR_PTR, numaCopy(), numaGetCount(), numaGetIValue(), numaSetValue(), and PROCNAME.

Referenced by main().

l_int32 numaGetMin ( NUMA na,
l_float32 pminval,
l_int32 piminloc 
)

numaGetMin()

Input: na &minval (<optional return>=""> min value) &iminloc (<optional return>=""> index of min location) Return: 0 if OK; 1 on error

Definition at line 312 of file numafunc1.c.

References ERROR_INT, numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by numaDifferentiateInterval(), numaGetCrossingDistances(), numaGetStatsUsingHistogram(), numaIntegrateInterval(), numaInterpolateArbxInterval(), numaMakeHistogram(), numaMakeHistogramAuto(), and pixFindSkewSweepAndSearchScorePivot().

l_int32 numaGetSum ( NUMA na,
l_float32 psum 
)
NUMA* numaGetPartialSums ( NUMA na)

numaGetPartialSums()

Input: na Return: nasum, or null on error

Notes: (1) nasum[i] is the sum for all j <= i of na[j]. So nasum[0] = na[0]. (2) If you want to generate a rank function, where rank[0] - 0.0, insert a 0.0 at the beginning of the nasum array.

Definition at line 432 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by main(), and numaEqualizeTRC().

l_int32 numaGetSumOnInterval ( NUMA na,
l_int32  first,
l_int32  last,
l_float32 psum 
)

numaGetSumOnInterval()

Input: na first (beginning index) last (final index) &sum (<return> sum of values in the index interval range) Return: 0 if OK, 1 on error

Definition at line 465 of file numafunc1.c.

References ERROR_INT, L_MIN, numaGetCount(), numaGetFValue(), and PROCNAME.

l_int32 numaHasOnlyIntegers ( NUMA na,
l_int32  maxsamples,
l_int32 pallints 
)

numaHasOnlyIntegers()

Input: na maxsamples (maximum number of samples to check) &allints (<return> 1 if all sampled values are ints; else 0) Return: 0 if OK, 1 on error

Notes: (1) Set == 0 to check every integer in na. Otherwise, this samples no more than .

Definition at line 509 of file numafunc1.c.

References ERROR_INT, FALSE, numaGetCount(), numaGetFValue(), PROCNAME, and TRUE.

Referenced by numaMakeHistogramAuto().

NUMA* numaSubsample ( NUMA nas,
l_int32  subfactor 
)

numaSubsample()

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

Definition at line 550 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), and PROCNAME.

NUMA* numaMakeDelta ( NUMA nas)

numaMakeDelta()

Input: nas (input numa) Return: numa (of difference values val[i+1] - val[i]), or null on error

Definition at line 584 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetIValue(), and PROCNAME.

Referenced by ptraConcatenatePdfToData().

NUMA* numaMakeSequence ( l_float32  startval,
l_float32  increment,
l_int32  size 
)

numaMakeSequence()

Input: startval increment size (of sequence) Return: numa of sequence of evenly spaced values, or null on error

Definition at line 614 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), PROCNAME, and size.

Referenced by main(), numaContrastTRC(), numaMakeConstant(), pixWordMaskByDilation(), ptraConcatenatePdfToData(), and wshedApply().

NUMA* numaMakeConstant ( l_float32  val,
l_int32  size 
)
NUMA* numaAddBorder ( NUMA nas,
l_int32  left,
l_int32  right,
l_float32  val 
)

numaAddBorder()

Input: nas left, right (number of elements to add on each side) val (initialize border elements) Return: nad (with added elements at left and right), or null on error

Definition at line 661 of file numafunc1.c.

References ERROR_PTR, L_NOCOPY, NULL, numaCopy(), numaGetCount(), numaGetFArray(), numaGetXParameters(), numaMakeConstant(), numaSetXParameters(), and PROCNAME.

Referenced by numaAddSpecifiedBorder(), and numaClose().

NUMA* numaAddSpecifiedBorder ( NUMA nas,
l_int32  left,
l_int32  right,
l_int32  type 
)

numaAddSpecifiedBorder()

Input: nas left, right (number of elements to add on each side) type (L_EXTENDED_BORDER, L_MIRRORED_BORDER) Return: nad (with added elements at left and right), or null on error

Definition at line 703 of file numafunc1.c.

References ERROR_PTR, L_EXTENDED_BORDER, L_MIRRORED_BORDER, L_NOCOPY, NULL, numaAddBorder(), numaCopy(), numaGetCount(), numaGetFArray(), and PROCNAME.

Referenced by numaWindowedMean(), and numaWindowedMeanSquare().

NUMA* numaRemoveBorder ( NUMA nas,
l_int32  left,
l_int32  right 
)

numaRemoveBorder()

Input: nas left, right (number of elements to remove from each side) Return: nad (with removed elements at left and right), or null on error

Definition at line 754 of file numafunc1.c.

References ERROR_PTR, L_NOCOPY, NULL, numaCopy(), numaGetCount(), numaGetFArray(), numaGetXParameters(), numaMakeConstant(), numaSetXParameters(), and PROCNAME.

Referenced by numaClose().

l_int32 numaGetNonzeroRange ( NUMA na,
l_float32  eps,
l_int32 pfirst,
l_int32 plast 
)

numaGetNonzeroRange()

Input: numa eps (largest value considered to be zero) &first, &last (<return> interval of array indices where values are nonzero) Return: 0 if OK, 1 on error or if no nonzero range is found.

Definition at line 797 of file numafunc1.c.

References ERROR_INT, FALSE, numaGetCount(), numaGetFValue(), PROCNAME, and TRUE.

Referenced by main(), pixCompareGray(), pixCompareRGB(), and pixGetDifferenceStats().

l_int32 numaGetCountRelativeToZero ( NUMA na,
l_int32  type,
l_int32 pcount 
)

numaGetCountRelativeToZero()

Input: numa type (L_LESS_THAN_ZERO, L_EQUAL_TO_ZERO, L_GREATER_THAN_ZERO) &count (<return> count of values of given type) Return: 0 if OK, 1 on error

Definition at line 846 of file numafunc1.c.

References ERROR_INT, L_EQUAL_TO_ZERO, L_GREATER_THAN_ZERO, L_LESS_THAN_ZERO, numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by pixConvertGrayToColormap8().

NUMA* numaClipToInterval ( NUMA nas,
l_int32  first,
l_int32  last 
)

numaClipToInterval()

Input: numa first, last (clipping interval) Return: numa with the same values as the input, but clipped to the specified interval

Note: If you want the indices of the array values to be unchanged, use first = 0. Usage: This is useful to clip a histogram that has a few nonzero values to its nonzero range.

Definition at line 890 of file numafunc1.c.

References ERROR_PTR, L_MIN, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by main(), pixCompareGray(), pixCompareRGB(), and pixGetDifferenceStats().

NUMA* numaMakeThresholdIndicator ( NUMA nas,
l_float32  thresh,
l_int32  type 
)

numaMakeThresholdIndicator()

Input: nas (input numa) thresh (threshold value) type (L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE) Output: nad (indicator array: values are 0 and 1)

Notes: (1) For each element in nas, if the constraint given by 'type' correctly specifies its relation to thresh, a value of 1 is recorded in nad.

Definition at line 935 of file numafunc1.c.

References ERROR_PTR, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by main(), pixaSelectByAreaFraction(), pixaSelectByAreaPerimRatio(), and pixaSelectByWidthHeightRatio().

NUMA* numaUniformSampling ( NUMA nas,
l_int32  nsamp 
)

numaUniformSampling()

Input: nas (input numa) nsamp (number of samples) Output: nad (resampled array), or null on error

Notes: (1) This resamples the values in the array, using equal divisions.

Definition at line 989 of file numafunc1.c.

References ERROR_PTR, L_MIN, L_NOCOPY, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFArray(), numaGetXParameters(), numaSetXParameters(), and PROCNAME.

NUMA* numaLowPassIntervals ( NUMA nas,
l_float32  thresh,
l_float32  maxn 
)

numaLowPassIntervals()

Input: nas (input numa) thresh (threshold fraction of max; in [0.0 ... 1.0]) maxn (for normalizing; set maxn = 0.0 to use the max in nas) Output: nad (interval abscissa pairs), or null on error

Notes: (1) For each interval where the value is less than a specified fraction of the maximum, this records the left and right "x" value.

Definition at line 1057 of file numafunc1.c.

References ERROR_PTR, FALSE, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), numaGetMax(), numaGetXParameters(), PROCNAME, TRUE, x0, and x1.

NUMA* numaThresholdEdges ( NUMA nas,
l_float32  thresh1,
l_float32  thresh2,
l_float32  maxn 
)

numaThresholdEdges()

Input: nas (input numa) thresh1 (low threshold as fraction of max; in [0.0 ... 1.0]) thresh2 (high threshold as fraction of max; in [0.0 ... 1.0]) maxn (for normalizing; set maxn = 0.0 to use the max in nas) Output: nad (edge interval triplets), or null on error

Notes: (1) For each edge interval, where where the value is less than on one side, greater than on the other, and between these thresholds throughout the interval, this records a triplet of values: the 'left' and 'right' edges, and either +1 or -1, depending on whether the edge is rising or falling. (2) No assumption is made about the value outside the array, so if the value at the array edge is between the threshold values, it is not considered part of an edge. We start looking for edge intervals only after leaving the thresholded band.

Definition at line 1132 of file numafunc1.c.

References ERROR_PTR, FALSE, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), numaGetMax(), numaGetXParameters(), PROCNAME, TRUE, x0, and x1.

l_int32 numaGetSpanValues ( NUMA na,
l_int32  span,
l_int32 pstart,
l_int32 pend 
)

numaGetSpanValues()

Input: na (numa that is output of numaLowPassIntervals()) span (span number, zero-based) &start (<optional return>=""> location of start of transition) &end (<optional return>=""> location of end of transition) Output: 0 if OK, 1 on error

Definition at line 1258 of file numafunc1.c.

References ERROR_INT, numaGetCount(), numaGetIValue(), and PROCNAME.

l_int32 numaGetEdgeValues ( NUMA na,
l_int32  edge,
l_int32 pstart,
l_int32 pend,
l_int32 psign 
)

numaGetEdgeValues()

Input: na (numa that is output of numaThresholdEdges()) edge (edge number, zero-based) &start (<optional return>=""> location of start of transition) &end (<optional return>=""> location of end of transition) &sign (<optional return>=""> transition sign: +1 is rising, -1 is falling) Output: 0 if OK, 1 on error

Definition at line 1294 of file numafunc1.c.

References ERROR_INT, numaGetCount(), numaGetIValue(), and PROCNAME.

l_int32 numaInterpolateEqxVal ( l_float32  startx,
l_float32  deltax,
NUMA nay,
l_int32  type,
l_float32  xval,
l_float32 pyval 
)

numaInterpolateEqxVal()

Input: startx (xval corresponding to first element in array) deltax (x increment between array elements) nay (numa of ordinate values, assumed equally spaced) type (L_LINEAR_INTERP, L_QUADRATIC_INTERP) xval &yval (<return> interpolated value) Return: 0 if OK, 1 on error (e.g., if xval is outside range)

Notes: (1) Considering nay as a function of x, the x values are equally spaced (2) Caller should check for valid return.

For linear Lagrangian interpolation (through 2 data pts): y(x) = y1(x-x2)/(x1-x2) + y2(x-x1)/(x2-x1)

For quadratic Lagrangian interpolation (through 3 data pts): y(x) = y1(x-x2)(x-x3)/((x1-x2)(x1-x3)) + y2(x-x1)(x-x3)/((x2-x1)(x2-x3)) + y3(x-x1)(x-x2)/((x3-x1)(x3-x2))

Definition at line 1349 of file numafunc1.c.

References ERROR_INT, L_LINEAR_INTERP, L_NOCOPY, L_QUADRATIC_INTERP, L_WARNING, numaGetCount(), numaGetFArray(), PROCNAME, x1, x2, and x3.

Referenced by numaInterpolateEqxInterval().

l_int32 numaInterpolateArbxVal ( NUMA nax,
NUMA nay,
l_int32  type,
l_float32  xval,
l_float32 pyval 
)

numaInterpolateArbxVal()

Input: nax (numa of abscissa values) nay (numa of ordinate values, corresponding to nax) type (L_LINEAR_INTERP, L_QUADRATIC_INTERP) xval &yval (<return> interpolated value) Return: 0 if OK, 1 on error (e.g., if xval is outside range)

Notes: (1) The values in nax must be sorted in increasing order. If, additionally, they are equally spaced, you can use numaInterpolateEqxVal(). (2) Caller should check for valid return. (3) Uses lagrangian interpolation. See numaInterpolateEqxVal() for formulas.

Definition at line 1441 of file numafunc1.c.

References ERROR_INT, L_LINEAR_INTERP, L_NOCOPY, L_QUADRATIC_INTERP, L_WARNING, numaGetCount(), numaGetFArray(), numaGetFValue(), nx, ny, and PROCNAME.

Referenced by main().

l_int32 numaInterpolateEqxInterval ( l_float32  startx,
l_float32  deltax,
NUMA nasy,
l_int32  type,
l_float32  x0,
l_float32  x1,
l_int32  npts,
NUMA **  pnax,
NUMA **  pnay 
)

numaInterpolateEqxInterval()

Input: startx (xval corresponding to first element in nas) deltax (x increment between array elements in nas) nasy (numa of ordinate values, assumed equally spaced) type (L_LINEAR_INTERP, L_QUADRATIC_INTERP) x0 (start value of interval) x1 (end value of interval) npts (number of points to evaluate function in interval) &nax (<optional return>=""> array of x values in interval) &nay (<return> array of y values in interval) Return: 0 if OK, 1 on error

Notes: (1) Considering nasy as a function of x, the x values are equally spaced. (2) This creates nay (and optionally nax) of interpolated values over the specified interval (x0, x1). (3) If the interval (x0, x1) lies partially outside the array nasy (as interpreted by startx and deltax), it is an error and returns 1. (4) Note that deltax is the intrinsic x-increment for the input array nasy, whereas delx is the intrinsic x-increment for the output interpolated array nay.

Definition at line 1555 of file numafunc1.c.

References ERROR_INT, L_LINEAR_INTERP, L_QUADRATIC_INTERP, L_WARNING, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaInterpolateEqxVal(), numaSetXParameters(), PROCNAME, and x0.

Referenced by main(), numaMakeRankFromHistogram(), and pixExtractBarcodeCrossings().

l_int32 numaInterpolateArbxInterval ( NUMA nax,
NUMA nay,
l_int32  type,
l_float32  x0,
l_float32  x1,
l_int32  npts,
NUMA **  pnadx,
NUMA **  pnady 
)

numaInterpolateArbxInterval()

Input: nax (numa of abscissa values) nay (numa of ordinate values, corresponding to nax) type (L_LINEAR_INTERP, L_QUADRATIC_INTERP) x0 (start value of interval) x1 (end value of interval) npts (number of points to evaluate function in interval) &nadx (<optional return>=""> array of x values in interval) &nady (<return> array of y values in interval) Return: 0 if OK, 1 on error (e.g., if x0 or x1 is outside range)

Notes: (1) The values in nax must be sorted in increasing order. If they are not sorted, we do it here, and complain. (2) If the values in nax are equally spaced, you can use numaInterpolateEqxInterval(). (3) Caller should check for valid return. (4) We don't call numaInterpolateArbxVal() for each output point, because that requires an O(n) search for each point. Instead, we do a single O(n) pass through nax, saving the indices to be used for each output yval. (5) Uses lagrangian interpolation. See numaInterpolateEqxVal() for formulas.

Definition at line 1641 of file numafunc1.c.

References CALLOC, ERROR_INT, FREE, L_LINEAR_INTERP, L_MAX, L_MIN, L_NOCOPY, L_QUADRATIC_INTERP, L_SORT_INCREASING, L_WARNING, NULL, numaAddNumber(), numaClone(), numaCreate(), numaDestroy(), numaGetCount(), numaGetFArray(), numaGetMax(), numaGetMin(), numaIsSorted(), numaSortPair(), nx, ny, PROCNAME, and x0.

Referenced by main(), numaDifferentiateInterval(), and numaIntegrateInterval().

l_int32 numaFitMax ( NUMA na,
l_float32 pmaxval,
NUMA naloc,
l_float32 pmaxloc 
)

numaFitMax()

Input: na (numa of ordinate values, to fit a max to) &maxval (<return> max value) naloc (<optional> associated numa of abscissa values) &maxloc (<return> abscissa value that gives max value in na; if naloc == null, this is given as an interpolated index value) Return: 0 if OK; 1 on error

Note: if naloc is given, there is no requirement that the data points are evenly spaced. Lagrangian interpolation handles that. The only requirement is that the data points are ordered so that the values in naloc are either increasing or decreasing. We test to make sure that the sizes of na and naloc are equal, and it is assumed that the correspondences na[i] as a function of naloc[i] are properly arranged for all i.

The formula for Lagrangian interpolation through 3 data pts is: y(x) = y1(x-x2)(x-x3)/((x1-x2)(x1-x3)) + y2(x-x1)(x-x3)/((x2-x1)(x2-x3)) + y3(x-x1)(x-x2)/((x3-x1)(x3-x2))

Then the derivative, using the constants (c1,c2,c3) defined below, is set to 0: y'(x) = 2x(c1+c2+c3) - c1(x2+x3) - c2(x1+x3) - c3(x1+x2) = 0

Definition at line 1798 of file numafunc1.c.

References ERROR_INT, numaGetCount(), numaGetFValue(), numaGetMax(), PROCNAME, x1, x2, x3, y1, y2, and y3.

Referenced by main(), and pixFindSkewSweep().

l_int32 numaDifferentiateInterval ( NUMA nax,
NUMA nay,
l_float32  x0,
l_float32  x1,
l_int32  npts,
NUMA **  pnadx,
NUMA **  pnady 
)

numaDifferentiateInterval()

Input: nax (numa of abscissa values) nay (numa of ordinate values, corresponding to nax) x0 (start value of interval) x1 (end value of interval) npts (number of points to evaluate function in interval) &nadx (<optional return>=""> array of x values in interval) &nady (<return> array of derivatives in interval) Return: 0 if OK, 1 on error (e.g., if x0 or x1 is outside range)

Notes: (1) The values in nax must be sorted in increasing order. If they are not sorted, it is done in the interpolation step, and a warning is issued. (2) Caller should check for valid return.

Definition at line 1903 of file numafunc1.c.

References ERROR_INT, L_LINEAR_INTERP, L_NOCOPY, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetCount(), numaGetFArray(), numaGetMax(), numaGetMin(), numaInterpolateArbxInterval(), nx, ny, PROCNAME, and x0.

Referenced by main().

l_int32 numaIntegrateInterval ( NUMA nax,
NUMA nay,
l_float32  x0,
l_float32  x1,
l_int32  npts,
l_float32 psum 
)

numaIntegrateInterval()

Input: nax (numa of abscissa values) nay (numa of ordinate values, corresponding to nax) x0 (start value of interval) x1 (end value of interval) npts (number of points to evaluate function in interval) &sum (<return> integral of function over interval) Return: 0 if OK, 1 on error (e.g., if x0 or x1 is outside range)

Notes: (1) The values in nax must be sorted in increasing order. If they are not sorted, it is done in the interpolation step, and a warning is issued. (2) Caller should check for valid return.

Definition at line 1984 of file numafunc1.c.

References ERROR_INT, L_LINEAR_INTERP, L_NOCOPY, NULL, numaDestroy(), numaGetCount(), numaGetFArray(), numaGetMax(), numaGetMin(), numaInterpolateArbxInterval(), nx, ny, PROCNAME, and x0.

Referenced by main().

NUMA* numaSort ( NUMA naout,
NUMA nain,
l_int32  sortorder 
)

numaSort()

Input: naout (output numa; can be NULL or equal to nain) nain (input numa) sortorder (L_SORT_INCREASING or L_SORT_DECREASING) Return: naout (output sorted numa), or null on error

Notes: (1) Set naout = nain for in-place; otherwise, set naout = NULL. (2) Source: Shell sort, modified from K&R, 2nd edition, p.62. Slow but simple O(n logn) sort.

Definition at line 2056 of file numafunc1.c.

References Numa::array, ERROR_PTR, L_SORT_DECREASING, L_SORT_INCREASING, NULL, numaCopy(), numaGetCount(), and PROCNAME.

Referenced by numaGetMode(), numaGetRankValue(), and pixThresholdGrayArb().

NUMA* numaGetSortIndex ( NUMA na,
l_int32  sortorder 
)

numaGetSortIndex()

Input: na sortorder (L_SORT_INCREASING or L_SORT_DECREASING) Return: na giving an array of indices that would sort the input array, or null on error

Definition at line 2107 of file numafunc1.c.

References CALLOC, ERROR_PTR, FREE, L_COPY, L_SORT_DECREASING, L_SORT_INCREASING, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFArray(), and PROCNAME.

Referenced by boxaSort(), dewarpBuildModel(), numaSortPair(), pixaSort(), pixcmapGetRankIntensity(), pixColorSegmentClean(), pixColorSegmentRemoveColors(), pixSplitComponentIntoBoxa(), ptaaRemoveShortLines(), and ptaSort().

NUMA* numaSortByIndex ( NUMA nas,
NUMA naindex 
)

numaSortByIndex()

Input: nas naindex (na that maps from the new numa to the input numa) Return: nad (sorted), or null on error

Definition at line 2169 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), numaGetCount(), numaGetFValue(), numaGetIValue(), and PROCNAME.

Referenced by boxaSort2d(), dewarpBuildModel(), and numaSortPair().

l_int32 numaIsSorted ( NUMA nas,
l_int32  sortorder,
l_int32 psorted 
)

numaIsSorted()

Input: nas sortorder (L_SORT_INCREASING or L_SORT_DECREASING) &sorted (<return> 1 if sorted; 0 if not) Return: 1 if OK; 0 on error

Notes: (1) This is a quick O(n) test if nas is sorted. It is useful in situations where the array is likely to be already sorted, and a sort operation can be avoided.

Definition at line 2209 of file numafunc1.c.

References ERROR_INT, FALSE, L_SORT_DECREASING, L_SORT_INCREASING, numaGetCount(), numaGetFValue(), PROCNAME, and TRUE.

Referenced by numaInterpolateArbxInterval(), and numaSortPair().

l_int32 numaSortPair ( NUMA nax,
NUMA nay,
l_int32  sortorder,
NUMA **  pnasx,
NUMA **  pnasy 
)

numaSortPair()

Input: nax, nay (input arrays) sortorder (L_SORT_INCREASING or L_SORT_DECREASING) &nasx (<return> sorted) &naxy (<return> sorted exactly in order of nasx) Return: 0 if OK, 1 on error

Notes: (1) This function sorts the two input arrays, nax and nay, together, using nax as the key for sorting.

Definition at line 2254 of file numafunc1.c.

References ERROR_INT, L_SORT_DECREASING, L_SORT_INCREASING, NULL, numaCopy(), numaDestroy(), numaGetSortIndex(), numaIsSorted(), numaSortByIndex(), PROCNAME, and TRUE.

Referenced by numaInterpolateArbxInterval().

NUMA* numaPseudorandomSequence ( l_int32  size,
l_int32  seed 
)

numaPseudorandomSequence()

Input: size (of sequence) seed (for random number generation) Return: na (pseudorandom on {0,...,size - 1}), or null on error

Notes: (1) This uses the Durstenfeld shuffle. See: http://en.wikipedia.org/wiki/Fisher–Yates_shuffle. Result is a pseudorandom permutation of the sequence of integers from 0 to size - 1.

Definition at line 2310 of file numafunc1.c.

References CALLOC, ERROR_PTR, FREE, L_MIN, NULL, numaCreateFromIArray(), PROCNAME, and size.

Referenced by boxaPermutePseudorandom(), numaRandomPermutation(), and pixDisplayPtaa().

NUMA* numaRandomPermutation ( NUMA nas,
l_int32  seed 
)

numaRandomPermutation()

Input: nas (input array) seed (for random number generation) Return: nas (randomly shuggled array), or null on error

Definition at line 2349 of file numafunc1.c.

References ERROR_PTR, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetCount(), numaGetFValue(), numaGetIValue(), numaPseudorandomSequence(), PROCNAME, and size.

l_int32 numaGetRankValue ( NUMA na,
l_float32  fract,
l_float32 pval 
)

numaGetRankValue()

Input: na fract (use 0.0 for smallest, 1.0 for largest) &val (<return> rank val) Return: 0 if OK; 1 on error

Notes: (1) Computes the rank value of the numbers in the numa, by sorting and finding the value a fraction from the small end.

Definition at line 2392 of file numafunc1.c.

References ERROR_INT, L_SORT_INCREASING, NULL, numaDestroy(), numaGetCount(), numaGetFValue(), numaSort(), and PROCNAME.

Referenced by boxaGetRankSize(), and numaGetMedian().

l_int32 numaGetMedian ( NUMA na,
l_float32 pval 
)

numaGetMedian()

Input: na &val (<return> median val) Return: 0 if OK; 1 on error

Notes: (1) Computes the median value of the numbers in the numa, by sorting and finding the middle value in the sorted array.

Definition at line 2434 of file numafunc1.c.

References ERROR_INT, numaGetRankValue(), and PROCNAME.

l_int32 numaGetMode ( NUMA na,
l_float32 pval,
l_int32 pcount 
)

numaGetMode()

Input: na &val (<return> mode val) &count (<optional return>=""> mode count) Return: 0 if OK; 1 on error

Notes: (1) Computes the mode value of the numbers in the numa, by sorting and finding the value of the number with the largest count. (2) Optionally, also returns that count.

Definition at line 2464 of file numafunc1.c.

References ERROR_INT, L_NOCOPY, L_SORT_DECREASING, NULL, numaDestroy(), numaGetCount(), numaGetFArray(), numaSort(), and PROCNAME.

Referenced by numaSelectCrossingThreshold().

l_int32 numaJoin ( NUMA nad,
NUMA nas,
l_int32  istart,
l_int32  iend 
)

numaJoin()

Input: nad (dest numa; add to this one) nas (<optional> source numa; add from this one) istart (starting index in nas) iend (ending index in nas; 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' (3) if nas == NULL, this is a no-op

Definition at line 2543 of file numafunc1.c.

References ERROR_INT, numaAddNumber(), numaGetCount(), numaGetFValue(), and PROCNAME.

Referenced by BoxaSortTest(), jbWordsInTextlines(), kernelCreateFromFile(), mergeLookup(), numaaFlattenToNuma(), and numaGetBinSortIndex().

NUMA* numaaFlattenToNuma ( NUMAA naa)

numaaFlattenToNuma()

Input: numaa Return: numa, or null on error

Notes: (1) This 'flattens' the Numaa to a Numa, by joining successively each Numa in the Numaa. (2) It doesn't make any assumptions about the location of the Numas in the Numaa array, unlike most Numaa functions. (3) It leaves the input Numaa unchanged.

Definition at line 2592 of file numafunc1.c.

References ERROR_PTR, Numaa::nalloc, NULL, numaaGetPtrArray(), numaCreate(), numaJoin(), and PROCNAME.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines