Leptonica 1.68
C Image Processing Library
|
Manipulation/calculations using arrays of points. More...
Go to the source code of this file.
Manipulation/calculations using arrays of points.
Pta and Ptaa rearrangements PTA *ptaSubsample() l_int32 ptaJoin() PTA *ptaReverse() PTA *ptaCyclicPerm() PTA *ptaSort() PTA *ptaRemoveDuplicates() PTAA *ptaaSortByIndex() Geometric BOX *ptaGetBoundingRegion() l_int32 *ptaGetRange() PTA *ptaGetInsideBox() PTA *pixFindCornerPixels() l_int32 ptaContainsPt() l_int32 ptaTestIntersection() PTA *ptaTransform() Least Squares Fit l_int32 ptaGetLinearLSF() l_int32 ptaGetQuadraticLSF() l_int32 ptaGetCubicLSF() l_int32 ptaGetQuarticLSF() 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() Display Pta and Ptaa PIX *pixDisplayPta() PIX *pixDisplayPtaa()
Definition in file ptafunc1.c.
Input: ptas subfactor (subsample factor, >= 1) Return: ptad (evenly sampled pt values from ptas, or null on error
Definition at line 78 of file ptafunc1.c.
References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().
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'
Definition at line 118 of file ptafunc1.c.
References ERROR_INT, PROCNAME, ptaAddPt(), ptaGetCount(), and ptaGetIPt().
Referenced by ccbaGenerateSinglePath(), generatePtaBox(), generatePtaBoxa(), generatePtaHashBox(), generatePtaPolyline(), generatePtaWideLine(), jbClassifyCorrelation(), jbClassifyRankHaus(), main(), selaAddCrossJunctions(), and selaAddTJunctions().
Input: ptas type (0 for float values; 1 for integer values) Return: ptad (reversed pta), or null on error
Definition at line 160 of file ptafunc1.c.
References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), ptaGetIPt(), and ptaGetPt().
Referenced by ccbaGenerateSinglePath().
Input: ptas xs, ys (start point; must be in ptas) Return: 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 205 of file ptafunc1.c.
References ERROR_PTR, L_FOUND, L_NOT_FOUND, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), ptaGetIPt(), x1, x2, y1, and y2.
Referenced by ccbaGenerateSinglePath().
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
Definition at line 263 of file ptafunc1.c.
References ERROR_PTR, L_SORT_BY_X, L_SORT_BY_Y, L_SORT_DECREASING, L_SORT_INCREASING, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetIValue(), numaGetSortIndex(), PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().
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
Definition at line 325 of file ptafunc1.c.
References CALLOC, DEFAULT_SPREADING_FACTOR, ERROR_PTR, FREE, NULL, numaDestroy(), numaGetCount(), numaGetIValue(), numaHashAdd(), numaHashCreate(), numaHashDestroy(), numaHashGetNuma(), PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetIPt().
Referenced by generatePtaBoxa(), and generatePtaPolyline().
Input: ptaas naindex (na that maps from the new ptaa to the input ptaa) Return: ptaad (sorted), or null on error
Definition at line 401 of file ptafunc1.c.
References ERROR_PTR, L_COPY, L_INSERT, NULL, numaGetCount(), numaGetIValue(), PROCNAME, ptaaAddPta(), ptaaCreate(), ptaaGetCount(), and ptaaGetPta().
Referenced by dewarpBuildModel().
Input: pta Return: 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 445 of file ptafunc1.c.
References boxCreate(), ERROR_PTR, NULL, PROCNAME, ptaGetCount(), and ptaGetIPt().
Referenced by selCreateFromPta().
l_int32 ptaGetRange | ( | PTA * | pta, |
l_float32 * | pminx, | ||
l_float32 * | pmaxx, | ||
l_float32 * | pminy, | ||
l_float32 * | pmaxy | ||
) |
Input: pta &minx (<optional return>=""> min value of x) &maxx (<optional return>=""> max value of x) &miny (<optional return>=""> min value of y) &maxy (<optional return>=""> max value of y) Return: 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 487 of file ptafunc1.c.
References ERROR_INT, PROCNAME, ptaGetCount(), and ptaGetPt().
Referenced by dewarpBuildModel(), and ptaaRemoveShortLines().
Input: ptas (input pts) box Return: ptad (of pts in ptas that are inside the box), or null on error
Definition at line 537 of file ptafunc1.c.
References boxContainsPt(), ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().
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.
Definition at line 575 of file ptafunc1.c.
References ERROR_PTR, FALSE, GET_DATA_BIT, L_MIN, NULL, pixGetData(), pixGetDepth(), pixGetHeight(), pixGetWidth(), pixGetWpl(), PROCNAME, ptaAddPt(), ptaCreate(), and TRUE.
Referenced by main().
Input: pta x, y (point) Return: 1 if contained, 0 otherwise or on error
Definition at line 667 of file ptafunc1.c.
References ERROR_INT, PROCNAME, ptaGetCount(), and ptaGetIPt().
Referenced by getCutPathForHole().
Input: pta1, pta2 Return: bval which is 1 if they have any elements in common; 0 otherwise or on error.
Definition at line 696 of file ptafunc1.c.
References ERROR_INT, PROCNAME, ptaGetCount(), ptaGetIPt(), x1, x2, y1, and y2.
PTA* ptaTransform | ( | PTA * | ptas, |
l_int32 | shiftx, | ||
l_int32 | shifty, | ||
l_float32 | scalex, | ||
l_float32 | scaley | ||
) |
Input: pta shiftx, shifty scalex, scaley Return: pta, or null on error
Notes: (1) Shift first, then scale.
Definition at line 735 of file ptafunc1.c.
References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetIPt().
Referenced by pixAffinePtaWithAlpha(), pixBilinearPtaWithAlpha(), pixGetOuterBorderPta(), pixProjectivePtaWithAlpha(), ptaaGetBoundaryPixels(), and selDisplayInPix().
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.
Definition at line 795 of file ptafunc1.c.
References ERROR_INT, NULL, numaAddNumber(), numaCreate(), PROCNAME, ptaGetCount(), Pta::x, and Pta::y.
Referenced by pixGetLocalSkewAngles().
l_int32 ptaGetQuadraticLSF | ( | PTA * | pta, |
l_float32 * | pa, | ||
l_float32 * | pb, | ||
l_float32 * | pc, | ||
NUMA ** | pnafit | ||
) |
Input: pta &a (<optional return>=""> coeff a of LSF: y = ax^2 + bx + c) &b (<optional return>=""> coeff b of LSF: y = ax^2 + bx + c) &c (<optional return>=""> coeff c of LSF: y = ax^2 + bx + c) &nafit (<optional return>=""> numa of least square fit) Return: 0 if OK, 1 on error
Notes: (1) This does a quadratic least square fit to the set of points in . 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 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.
Definition at line 892 of file ptafunc1.c.
References CALLOC, ERROR_INT, FREE, gaussjordan(), NULL, numaAddNumber(), numaCreate(), PROCNAME, ptaGetCount(), Pta::x, and Pta::y.
Referenced by dewarpBuildModel(), and main().
l_int32 ptaGetCubicLSF | ( | PTA * | pta, |
l_float32 * | pa, | ||
l_float32 * | pb, | ||
l_float32 * | pc, | ||
l_float32 * | pd, | ||
NUMA ** | pnafit | ||
) |
Input: pta &a (<optional return>=""> coeff a of LSF: y = ax^3 + bx^2 + cx + d) &b (<optional return>=""> coeff b of LSF) &c (<optional return>=""> coeff c of LSF) &d (<optional return>=""> coeff d of LSF) &nafit (<optional return>=""> numa of least square fit) Return: 0 if OK, 1 on error
Notes: (1) This does a cubic least square fit to the set of points in . 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 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.
Definition at line 1006 of file ptafunc1.c.
References CALLOC, ERROR_INT, FREE, gaussjordan(), NULL, numaAddNumber(), numaCreate(), PROCNAME, ptaGetCount(), Pta::x, and Pta::y.
Referenced by main().
l_int32 ptaGetQuarticLSF | ( | PTA * | pta, |
l_float32 * | pa, | ||
l_float32 * | pb, | ||
l_float32 * | pc, | ||
l_float32 * | pd, | ||
l_float32 * | pe, | ||
NUMA ** | pnafit | ||
) |
Input: pta &a (<optional return>=""> coeff a of LSF: y = ax^4 + bx^3 + cx^2 + dx + e) &b (<optional return>=""> coeff b of LSF) &c (<optional return>=""> coeff c of LSF) &d (<optional return>=""> coeff d of LSF) &e (<optional return>=""> coeff e of LSF) &nafit (<optional return>=""> numa of least square fit) Return: 0 if OK, 1 on error
Notes: (1) This does a quartic least square fit to the set of points in . 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 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.
Definition at line 1137 of file ptafunc1.c.
References CALLOC, ERROR_INT, FREE, gaussjordan(), NULL, numaAddNumber(), numaCreate(), PROCNAME, ptaGetCount(), Pta::x, and Pta::y.
Referenced by main().
Input: a, b (linear fit coefficients) x &y (<return> y = a * x + b) Return: 0 if OK, 1 on error
Definition at line 1260 of file ptafunc1.c.
Input: a, b, c (quadratic fit coefficients) x &y (<return> y = a * x^2 + b * x + c) Return: 0 if OK, 1 on error
Definition at line 1284 of file ptafunc1.c.
References ERROR_INT, and PROCNAME.
Referenced by dewarpBuildModel().
l_int32 applyCubicFit | ( | l_float32 | a, |
l_float32 | b, | ||
l_float32 | c, | ||
l_float32 | d, | ||
l_float32 | x, | ||
l_float32 * | py | ||
) |
Input: a, b, c, d (cubic fit coefficients) x &y (<return> y = a * x^3 + b * x^2 + c * x + d) Return: 0 if OK, 1 on error
Definition at line 1309 of file ptafunc1.c.
l_int32 applyQuarticFit | ( | l_float32 | a, |
l_float32 | b, | ||
l_float32 | c, | ||
l_float32 | d, | ||
l_float32 | e, | ||
l_float32 | x, | ||
l_float32 * | py | ||
) |
Input: a, b, c, d, e (quartic fit coefficients) x &y (<return> y = a * x^4 + b * x^3 + c * x^2 + d * x + e) Return: 0 if OK, 1 on error
Definition at line 1335 of file ptafunc1.c.
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.
Definition at line 1376 of file ptafunc1.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_INT, FREE, GET_DATA_BYTE, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNG, GPLOT_PS, GPLOT_X11, gplotSimple1(), L_WARNING, numaAddNumber(), numaCreate(), numaDestroy(), pixDestroy(), pixGetDepth(), pixGetHeight(), pixGetPixel(), pixGetWidth(), pixRemoveColormap(), PROCNAME, ptaGetCount(), ptaGetIPt(), REMOVE_CMAP_BASED_ON_SRC, and stringJoin().
Referenced by pixExtractOnLine().
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.
Definition at line 1475 of file ptafunc1.c.
References boxGetGeometry(), ERROR_PTR, GET_DATA_BIT, NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, ptaAddPt(), and ptaCreate().
Referenced by pixSubsampleBoundaryPixels(), and ptaGetBoundaryPixels().
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.
Definition at line 1526 of file ptafunc1.c.
References ERROR_PTR, NULL, pixCreate(), pixSetPixel(), PROCNAME, ptaGetCount(), and ptaGetIPt().
Referenced by main(), selDisplayInPix(), and wshedApply().
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.
Definition at line 1563 of file ptafunc1.c.
References ERROR_PTR, L_BOUNDARY_BG, L_BOUNDARY_FG, NULL, pixDestroy(), pixGetDepth(), pixMorphSequence(), pixXor(), PROCNAME, and ptaGetPixelsFromPix().
Referenced by ptaaGetBoundaryPixels().
PTAA* ptaaGetBoundaryPixels | ( | PIX * | pixs, |
l_int32 | type, | ||
l_int32 | connectivity, | ||
BOXA ** | pboxa, | ||
PIXA ** | ppixa | ||
) |
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.
Definition at line 1610 of file ptafunc1.c.
References boxaDestroy(), boxaGetBoxGeometry(), boxaGetCount(), ERROR_PTR, L_BOUNDARY_BG, L_BOUNDARY_FG, L_CLONE, L_INSERT, NULL, pixAddBorderGeneral(), pixaDestroy(), pixaGetPix(), pixClone(), pixConnComp(), pixDestroy(), pixGetDepth(), pixGetDimensions(), PROCNAME, ptaaAddPta(), ptaaCreate(), ptaDestroy(), ptaGetBoundaryPixels(), and ptaTransform().
Referenced by main().
Input: pixd (can be same as pixs or null; 32 bpp if in-place) pixs (1, 2, 4, 8, 16 or 32 bpp) pta (of path to be plotted) Return: pixd (32 bpp RGB version of pixs, with path in green), or null on error
Notes: (1) To write on an existing pixs, pixs must be 32 bpp and call with pixd == pixs: pixDisplayPta(pixs, pixs, pta); To write on a new pix, set pixd == NULL and call: pixd = pixDisplayPta(NULL, pixs, pta);
Definition at line 1691 of file ptafunc1.c.
References composeRGBPixel(), ERROR_PTR, NULL, pixConvertTo32(), pixGetDepth(), pixSetPixel(), PROCNAME, ptaGetCount(), and ptaGetIPt().
Referenced by main().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) ptaa (array of paths to be plotted) Return: pixd (32 bpp RGB version of pixs, with paths plotted in different colors), or null on error
Definition at line 1737 of file ptafunc1.c.
References CALLOC, composeRGBPixel(), ERROR_PTR, FREE, L_CLONE, NULL, numaDestroy(), numaGetIValue(), numaPseudorandomSequence(), pixConvertTo32(), pixSetPixel(), PROCNAME, ptaaGetCount(), ptaaGetPta(), ptaDestroy(), ptaGetCount(), and ptaGetIPt().
Referenced by dewarpBuildModel(), main(), pixGetTextlineCenters(), and ptaaRemoveShortLines().
const l_int32 DEFAULT_SPREADING_FACTOR = 7500 [static] |
Definition at line 64 of file ptafunc1.c.
Referenced by ptaRemoveDuplicates().