![]() |
Leptonica
1.73
Image processing and image analysis suite
|
#include <math.h>#include "allheaders.h"Go to the source code of this file.
Functions | |
| static l_int32 | boxaTestEvenOddHeight (BOXA *boxa1, BOXA *boxa2, l_int32 start, l_float32 *pdel1, l_float32 *pdel2) |
| static l_int32 | boxaFillAll (BOXA *boxa) |
| BOXA * | boxaSelectRange (BOXA *boxas, l_int32 first, l_int32 last, l_int32 copyflag) |
| BOXAA * | boxaaSelectRange (BOXAA *baas, l_int32 first, l_int32 last, l_int32 copyflag) |
| BOXA * | boxaSelectBySize (BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged) |
| NUMA * | boxaMakeSizeIndicator (BOXA *boxa, l_int32 width, l_int32 height, l_int32 type, l_int32 relation) |
| BOXA * | boxaSelectByArea (BOXA *boxas, l_int32 area, l_int32 relation, l_int32 *pchanged) |
| NUMA * | boxaMakeAreaIndicator (BOXA *boxa, l_int32 area, l_int32 relation) |
| BOXA * | boxaSelectByWHRatio (BOXA *boxas, l_float32 ratio, l_int32 relation, l_int32 *pchanged) |
| NUMA * | boxaMakeWHRatioIndicator (BOXA *boxa, l_float32 ratio, l_int32 relation) |
| BOXA * | boxaSelectWithIndicator (BOXA *boxas, NUMA *na, l_int32 *pchanged) |
| BOXA * | boxaPermutePseudorandom (BOXA *boxas) |
| BOXA * | boxaPermuteRandom (BOXA *boxad, BOXA *boxas) |
| l_int32 | boxaSwapBoxes (BOXA *boxa, l_int32 i, l_int32 j) |
| PTA * | boxaConvertToPta (BOXA *boxa, l_int32 ncorners) |
| BOXA * | ptaConvertToBoxa (PTA *pta, l_int32 ncorners) |
| PTA * | boxConvertToPta (BOX *box, l_int32 ncorners) |
| BOX * | ptaConvertToBox (PTA *pta) |
| BOXA * | boxaSmoothSequenceLS (BOXA *boxas, l_float32 factor, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels, l_int32 debug) |
| BOXA * | boxaSmoothSequenceMedian (BOXA *boxas, l_int32 halfwin, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels, l_int32 debug) |
| BOXA * | boxaLinearFit (BOXA *boxas, l_float32 factor, l_int32 debug) |
| BOXA * | boxaWindowedMedian (BOXA *boxas, l_int32 halfwin, l_int32 debug) |
| BOXA * | boxaModifyWithBoxa (BOXA *boxas, BOXA *boxam, l_int32 subflag, l_int32 maxdiff, l_int32 extrapixels) |
| BOXA * | boxaConstrainSize (BOXA *boxas, l_int32 width, l_int32 widthflag, l_int32 height, l_int32 heightflag) |
| BOXA * | boxaReconcileEvenOddHeight (BOXA *boxas, l_int32 sides, l_int32 delh, l_int32 op, l_float32 factor, l_int32 start) |
| BOXA * | boxaReconcilePairWidth (BOXA *boxas, l_int32 delw, l_int32 op, l_float32 factor, NUMA *na) |
| l_int32 | boxaPlotSides (BOXA *boxa, const char *plotname, NUMA **pnal, NUMA **pnat, NUMA **pnar, NUMA **pnab, PIX **ppixd) |
| l_int32 | boxaPlotSizes (BOXA *boxa, const char *plotname, NUMA **pnaw, NUMA **pnah, PIX **ppixd) |
| BOXA * | boxaFillSequence (BOXA *boxas, l_int32 useflag, l_int32 debug) |
| l_int32 | boxaGetExtent (BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox) |
| l_int32 | boxaGetCoverage (BOXA *boxa, l_int32 wc, l_int32 hc, l_int32 exactflag, l_float32 *pfract) |
| l_int32 | boxaaSizeRange (BOXAA *baa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh) |
| l_int32 | boxaSizeRange (BOXA *boxa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh) |
| l_int32 | boxaLocationRange (BOXA *boxa, l_int32 *pminx, l_int32 *pminy, l_int32 *pmaxx, l_int32 *pmaxy) |
| l_int32 | boxaGetSizes (BOXA *boxa, NUMA **pnaw, NUMA **pnah) |
| l_int32 | boxaGetArea (BOXA *boxa, l_int32 *parea) |
| PIX * | boxaDisplayTiled (BOXA *boxas, PIXA *pixa, l_int32 maxwidth, l_int32 linewidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border) |
Boxa and Boxaa range selection
BOXA *boxaSelectRange()
BOXAA *boxaaSelectRange()
Boxa size selection
BOXA *boxaSelectBySize()
NUMA *boxaMakeSizeIndicator()
BOXA *boxaSelectByArea()
NUMA *boxaMakeAreaIndicator()
BOXA *boxaSelectByWHRatio()
NUMA *boxaMakeWHRatioIndicator()
BOXA *boxaSelectWithIndicator()
Boxa permutation
BOXA *boxaPermutePseudorandom()
BOXA *boxaPermuteRandom()
l_int32 boxaSwapBoxes()
Boxa and box conversions
PTA *boxaConvertToPta()
BOXA *ptaConvertToBoxa()
PTA *boxConvertToPta()
BOX *ptaConvertToBox()
Boxa sequence fitting
BOXA *boxaSmoothSequenceLS()
BOXA *boxaSmoothSequenceMedian()
BOXA *boxaLinearFit()
BOXA *boxaWindowedMedian()
BOXA *boxaModifyWithBoxa()
BOXA *boxaConstrainSize()
BOXA *boxaReconcileEvenOddHeight()
static l_int32 boxaTestEvenOddHeight()
BOXA *boxaReconcilePairWidth()
l_int32 boxaPlotSides() [for debugging]
l_int32 boxaPlotSizes() [for debugging]
BOXA *boxaFillSequence()
static l_int32 boxaFillAll() Miscellaneous boxa functions
l_int32 boxaGetExtent()
l_int32 boxaGetCoverage()
l_int32 boxaaSizeRange()
l_int32 boxaSizeRange()
l_int32 boxaLocationRange()
NUMA *boxaGetSizes()
l_int32 boxaGetArea()
PIX *boxaDisplayTiled()
Definition in file boxfunc4.c.
| [in] | baas | |
| [in] | first | use 0 to select from the beginning |
| [in] | last | use 0 to select to the end |
| [in] | copyflag | L_COPY, L_CLONE |
Notes:
(1) The copyflag specifies what we do with each boxa from baas.
Specifically, L_CLONE inserts a clone into baad of each
selected boxa from baas.
Definition at line 163 of file boxfunc4.c.
References boxaaAddBoxa(), boxaaCreate(), boxaaGetBoxa(), boxaaGetCount(), L_CLONE, L_COPY, and L_INSERT.
| l_int32 boxaaSizeRange | ( | BOXAA * | baa, |
| l_int32 * | pminw, | ||
| l_int32 * | pminh, | ||
| l_int32 * | pmaxw, | ||
| l_int32 * | pmaxh | ||
| ) |
| [in] | baa | |
| [out] | pminw,pminh,pmaxw,pmaxh | [optional] range of dimensions of all boxes |
Definition at line 2446 of file boxfunc4.c.
References boxaaGetBoxa(), boxaaGetCount(), boxaDestroy(), boxaSizeRange(), and L_CLONE.
| BOXA* boxaConstrainSize | ( | BOXA * | boxas, |
| l_int32 | width, | ||
| l_int32 | widthflag, | ||
| l_int32 | height, | ||
| l_int32 | heightflag | ||
| ) |
| [in] | boxas | |
| [in] | width | force width of all boxes to this size; input 0 to use the median width |
| [in] | widthflag | L_ADJUST_SKIP, L_ADJUST_LEFT, L_ADJUST_RIGHT, or L_ADJUST_LEFT_AND_RIGHT |
| [in] | height | force height of all boxes to this size; input 0 to use the median height |
| [in] | heightflag | L_ADJUST_SKIP, L_ADJUST_TOP, L_ADJUST_BOT, or L_ADJUST_TOP_AND_BOT |
Notes:
(1) Forces either width or height (or both) of every box in
the boxa to a specified size, by moving the indicated sides.
(2) Not all input boxes need to be valid. Median values will be
used with invalid boxes.
(3) Typical input might be the output of boxaLinearFit(),
where each side has been fit.
(4) Unlike boxaAdjustWidthToTarget() and boxaAdjustHeightToTarget(),
this is not dependent on a difference threshold to change the size.
(5) On error, a message is issued and a copy of the input boxa
is returned.
Definition at line 1584 of file boxfunc4.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxAdjustSides(), boxaGetCount(), boxaGetMedianVals(), boxaGetValidBox(), boxaGetValidCount(), boxCopy(), boxCreate(), boxDestroy(), boxGetGeometry(), L_ADJUST_BOT, L_ADJUST_LEFT, L_ADJUST_RIGHT, L_ADJUST_TOP, L_COPY, and L_INSERT.
| [in] | boxa | |
| [in] | ncorners | 2 or 4 for the representation of each box |
Notes:
(1) If ncorners == 2, we select the UL and LR corners.
Otherwise we save all 4 corners in this order: UL, UR, LL, LR.
Definition at line 762 of file boxfunc4.c.
References boxaGetBox(), boxaGetCount(), boxConvertToPta(), boxDestroy(), L_COPY, ptaCreate(), ptaDestroy(), and ptaJoin().
Referenced by boxaAffineTransform(), boxaRotate(), boxaScale(), and boxaTranslate().
| PIX* boxaDisplayTiled | ( | BOXA * | boxas, |
| PIXA * | pixa, | ||
| l_int32 | maxwidth, | ||
| l_int32 | linewidth, | ||
| l_float32 | scalefactor, | ||
| l_int32 | background, | ||
| l_int32 | spacing, | ||
| l_int32 | border | ||
| ) |
| [in] | boxas | |
| [in] | pixa | [optional] background for each box |
| [in] | maxwidth | of output image |
| [in] | linewidth | width of box outlines, before scaling |
| [in] | scalefactor | applied to every box; use 1.0 for no scaling |
| [in] | background | 0 for white, 1 for black; this is the color of the spacing between the images |
| [in] | spacing | between images, and on outside |
| [in] | border | width of black border added to each image; use 0 for no border |
Notes:
(1) Displays each box separately in a tiled 32 bpp image.
(2) If pixa is defined, it must have the same count as the boxa,
and it will be a background over with each box is rendered.
If pixa is not defined, the boxes will be rendered over
blank images of identical size.
(3) See pixaDisplayTiledInRows() for other parameters.
Definition at line 2696 of file boxfunc4.c.
References bmfCreate(), bmfDestroy(), boxaDestroy(), boxaGetBox(), boxaGetCount(), boxaGetExtent(), boxaSaveValid(), boxDestroy(), L_ADD_BELOW, L_CLONE, L_COPY, L_INSERT, pixaAddPix(), pixaCreate(), pixAddSingleTextblock(), pixaDestroy(), pixaDisplayTiledInRows(), pixaGetCount(), pixaGetPix(), pixCreate(), pixDestroy(), pixRenderBoxArb(), pixSetAll(), and pixSetBorderVal().
|
static |
| [in] | boxa |
Notes:
(1) This static function replaces every invalid box with the
nearest valid box. If there are no valid boxes, it
issues a warning.
Definition at line 2238 of file boxfunc4.c.
References boxaGetBox(), boxaGetCount(), boxaGetValidBox(), boxaGetValidCount(), boxaReplaceBox(), boxDestroy(), L_CLONE, and L_COPY.
Referenced by boxaFillSequence().
| [in] | boxas | with at least 3 boxes |
| [in] | useflag | L_USE_ALL_BOXES, L_USE_SAME_PARITY_BOXES |
| [in] | debug | 1 for debug output |
Notes:
(1) This simple function replaces invalid boxes with a copy of
the nearest valid box, selected from either the entire
sequence (L_USE_ALL_BOXES) or from the boxes with the
same parity (L_USE_SAME_PARITY_BOXES). It returns a new boxa.
(2) This is useful if you expect boxes in the sequence to
vary slowly with index.
Definition at line 2179 of file boxfunc4.c.
References boxaCopy(), boxaDestroy(), boxaFillAll(), boxaGetCount(), boxaGetValidCount(), boxaMergeEvenOdd(), boxaSplitEvenOdd(), L_COPY, L_USE_ALL_BOXES, and L_USE_SAME_PARITY_BOXES.
Referenced by boxaPlotSides(), boxaPlotSizes(), and boxaWindowedMedian().
| l_int32 boxaGetArea | ( | BOXA * | boxa, |
| l_int32 * | parea | ||
| ) |
| [in] | boxa | |
| [out] | parea | total area of all boxes |
Notes:
(1) Measures the total area of the boxes, without regard to overlaps.
Definition at line 2648 of file boxfunc4.c.
References boxaGetBoxGeometry(), and boxaGetCount().
Referenced by boxaCombineOverlapsInPair(), and boxaCompareRegions().
| l_int32 boxaGetCoverage | ( | BOXA * | boxa, |
| l_int32 | wc, | ||
| l_int32 | hc, | ||
| l_int32 | exactflag, | ||
| l_float32 * | pfract | ||
| ) |
| [in] | boxa | |
| [in] | wc,hc | dimensions of overall clipping rectangle with UL corner at (0, 0 that is covered by the boxes. |
| [in] | exactflag | 1 for guaranteeing an exact result; 0 for getting an exact result only if the boxes do not overlap |
| [out] | pfract | sum of box area as fraction of w * h |
Notes:
(1) The boxes in boxa are clipped to the input rectangle.
(2) * When exactflag == 1, we generate a 1 bpp pix of size
wc x hc, paint all the boxes black, and count the fg pixels.
This can take 1 msec on a large page with many boxes.
* When exactflag == 0, we clip each box to the wc x hc region
and sum the resulting areas. This is faster.
* The results are the same when none of the boxes overlap
within the wc x hc region.
Definition at line 2387 of file boxfunc4.c.
References boxaGetBox(), boxaGetCount(), boxClipToRectangle(), boxDestroy(), boxGetGeometry(), L_CLONE, PIX_SET, pixCountPixels(), pixCreate(), pixDestroy(), and pixRasterop().
| [in] | boxa | |
| [out] | pw | [optional] width |
| [out] | ph | [optional] height |
| [out] | pbox | [optional] minimum box containing all boxes in boxa |
Notes:
(1) The returned w and h are the minimum size image
that would contain all boxes untranslated.
(2) If there are no valid boxes, returned w and h are 0 and
all parameters in the returned box are 0. This
is not an error, because an empty boxa is valid and
boxaGetExtent() is required for serialization.
Definition at line 2321 of file boxfunc4.c.
References boxaGetBoxGeometry(), boxaGetCount(), and boxCreate().
Referenced by boxaaAlignBox(), boxaaGetExtent(), boxaaWriteStream(), boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaCompareRegions(), boxaDisplayTiled(), pixaaDisplay(), pixaCreateFromBoxa(), pixaDisplay(), pixaDisplayOnColor(), pixaDisplayRandomCmap(), and showExtractNumbers().
| [in] | boxa | |
| [out] | pnaw,pnah | [optional] widths and heights of valid boxes |
Definition at line 2602 of file boxfunc4.c.
References boxaGetValidBox(), boxaGetValidCount(), boxDestroy(), boxGetGeometry(), L_COPY, numaAddNumber(), and numaCreate().
| [in] | boxas | source boxa |
| [in] | factor | reject outliers with widths and heights deviating from the median by more than factor times the median deviation from the median; typically ~3 |
| [in] | debug | 1 for debug output |
Notes:
(1) This finds a set of boxes (boxad) where each edge of each box is
a linear least square fit (LSF) to the edges of the
input set of boxes (boxas). Before fitting, outliers in
the boxes in boxas are removed (see below).
(2) This is useful when each of the box edges in boxas are expected
to vary linearly with box index in the set. These could
be, for example, noisy measurements of similar regions
on successive scanned pages.
(3) Method: there are 2 steps:
(a) Find and remove outliers, separately based on the deviation
from the median of the width and height of the box.
Use factor to specify tolerance to outliers; use a very
large value of factor to avoid rejecting any box sides
in the linear LSF.
(b) On the remaining boxes, do a linear LSF independently
for each of the four sides.
(4) Invalid input boxes are not used in computation of the LSF.
(5) The returned boxad can then be used in boxaModifyWithBoxa()
to selectively change the boxes in boxas.
Definition at line 1178 of file boxfunc4.c.
References boxaAddBox(), boxaCreate(), boxaDestroy(), boxaExtractAsNuma(), boxaExtractAsPta(), boxaGetCount(), boxaGetValidBox(), boxaPlotSides(), boxaPlotSizes(), boxaWrite(), boxCreate(), boxDestroy(), boxGetGeometry(), L_CLONE, L_COPY, L_INSERT, lept_mkdir(), numaDestroy(), numaGetMedianVariation(), ptaDestroy(), ptaGetLinearLSF(), and ptaWrite().
Referenced by boxaSmoothSequenceLS().
| l_int32 boxaLocationRange | ( | BOXA * | boxa, |
| l_int32 * | pminx, | ||
| l_int32 * | pminy, | ||
| l_int32 * | pmaxx, | ||
| l_int32 * | pmaxy | ||
| ) |
| [in] | boxa | |
| [out] | pminx,pminy,pmaxx,pmaxy | [optional] range of UL corner positions |
Definition at line 2551 of file boxfunc4.c.
References boxaGetBoxGeometry(), and boxaGetCount().
| [in] | boxa | |
| [in] | area | threshold value of width * height |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
Notes:
(1) To keep small components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep large components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 426 of file boxfunc4.c.
References boxaGetBoxGeometry(), boxaGetCount(), L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, numaAddNumber(), and numaCreate().
Referenced by boxaSelectByArea().
| NUMA* boxaMakeSizeIndicator | ( | BOXA * | boxa, |
| l_int32 | width, | ||
| l_int32 | height, | ||
| l_int32 | type, | ||
| l_int32 | relation | ||
| ) |
| [in] | boxa | |
| [in] | width,height | threshold dimensions |
| [in] | type | L_SELECT_WIDTH, L_SELECT_HEIGHT, L_SELECT_IF_EITHER, L_SELECT_IF_BOTH |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
Notes:
(1) The args specify constraints on the size of the
components that are kept.
(2) If the selection type is L_SELECT_WIDTH, the input
height is ignored, and v.v.
(3) To keep small components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep large components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 289 of file boxfunc4.c.
References boxaGetBoxGeometry(), boxaGetCount(), L_SELECT_HEIGHT, 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_WIDTH, numaAddNumber(), and numaCreate().
Referenced by boxaSelectBySize().
| [in] | boxa | |
| [in] | ratio | width/height threshold value |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
Notes:
(1) To keep narrow components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep wide components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 530 of file boxfunc4.c.
References boxaGetBoxGeometry(), boxaGetCount(), L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, numaAddNumber(), and numaCreate().
Referenced by boxaSelectByWHRatio().
| BOXA* boxaModifyWithBoxa | ( | BOXA * | boxas, |
| BOXA * | boxam, | ||
| l_int32 | subflag, | ||
| l_int32 | maxdiff, | ||
| l_int32 | extrapixels | ||
| ) |
| [in] | boxas | |
| [in] | boxam | boxa with boxes used to modify those in boxas |
| [in] | subflag | L_USE_MINSIZE, L_USE_MAXSIZE, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | maxdiff | parameter used with L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | extrapixels | pixels added on all sides (or subtracted if extrapixels < 0) when using L_SUB_ON_LOC_DIFF and L_SUB_ON_SIZE_DIFF |
Notes:
(1) This takes two input boxa (boxas, boxam) and constructs boxad,
where each box in boxad is generated from the corresponding
boxes in boxas and boxam. The rule for constructing each
output box depends on subflag and maxdiff. Let boxs be
a box from boxas and boxm be a box from boxam.
* If subflag == L_USE_MINSIZE: the output box is the intersection
of the two input boxes.
* If subflag == L_USE_MAXSIZE: the output box is the union of the
two input boxes; i.e., the minimum bounding rectangle for the
two input boxes.
* If subflag == L_SUB_ON_LOC_DIFF: each side of the output box
is found separately from the corresponding side of boxs and boxm.
Use the boxm side, expanded by extrapixels, if greater than
maxdiff pixels from the boxs side.
* If subflag == L_SUB_ON_SIZE_DIFF: the sides of the output box
are determined in pairs from the width and height of boxs
and boxm. If the boxm width differs by more than maxdiff
pixels from boxs, use the boxm left and right sides,
expanded by extrapixels. Ditto for the height difference.
For the last two flags, each side of the output box is found
separately from the corresponding side of boxs and boxm,
according to these rules, where "smaller"("bigger") mean in a
direction that decreases(increases) the size of the output box:
* If subflag == L_USE_CAPPED_MIN: use the Min of boxm
with the Max of (boxs, boxm +- maxdiff), where the sign
is adjusted to make the box smaller (e.g., use "+" on left side).
* If subflag == L_USE_CAPPED_MAX: use the Max of boxm
with the Min of (boxs, boxm +- maxdiff), where the sign
is adjusted to make the box bigger (e.g., use "-" on left side).
Use of the last 2 flags is further explained in (3) and (4).
(2) boxas and boxam must be the same size. If boxam == NULL,
this returns a copy of boxas with a warning.
(3) If subflag == L_SUB_ON_LOC_DIFF, use boxm for each side
where the corresponding sides differ by more than maxdiff.
Two extreme cases:
(a) set maxdiff == 0 to use only values from boxam in boxad.
(b) set maxdiff == 10000 to ignore all values from boxam;
then boxad will be the same as boxas.
(4) If subflag == L_USE_CAPPED_MAX: use boxm if boxs is smaller;
use boxs if boxs is bigger than boxm by an amount up to maxdiff;
and use boxm +- maxdiff (the 'capped' value) if boxs is
bigger than boxm by an amount larger than maxdiff.
Similarly, with interchange of Min/Max and sign of maxdiff,
for subflag == L_USE_CAPPED_MIN.
(5) If either of corresponding boxes in boxas and boxam is invalid,
an invalid box is copied to the result.
(6) Typical input for boxam may be the output of boxaLinearFit().
where outliers have been removed and each side is LS fit to a line.
(7) Unlike boxaAdjustWidthToTarget() and boxaAdjustHeightToTarget(),
this uses two boxes and does not specify target dimensions.
Additional constraints on the size of each box can be enforced
by following this operation with boxaConstrainSize(), taking
boxad as input.
Definition at line 1468 of file boxfunc4.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaGetCount(), boxaGetValidBox(), boxCreate(), boxDestroy(), boxGetGeometry(), L_CLONE, L_COPY, L_INSERT, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MAX, L_USE_CAPPED_MIN, L_USE_MAXSIZE, and L_USE_MINSIZE.
Referenced by boxaSmoothSequenceLS(), and boxaSmoothSequenceMedian().
| [in] | boxas | input boxa |
Notes:
(1) This does a pseudorandom in-place permutation of the boxes.
(2) The result is guaranteed not to have any boxes in their
original position, but it is not very random. If you
need randomness, use boxaPermuteRandom().
Definition at line 640 of file boxfunc4.c.
References boxaGetCount(), boxaSortByIndex(), numaDestroy(), and numaPseudorandomSequence().
| [in] | boxad | [optional] can be null or equal to boxas |
| [in] | boxas | input boxa |
Notes:
(1) If boxad is null, make a copy of boxas and permute the copy.
Otherwise, boxad must be equal to boxas, and the operation
is done in-place.
(2) If boxas is empty, return an empty boxad.
(3) This does a random in-place permutation of the boxes,
by swapping each box in turn with a random box. The
result is almost guaranteed not to have any boxes in their
original position.
(4) MSVC rand() has MAX_RAND = 2^15 - 1, so it will not do
a proper permutation is the number of boxes exceeds this.
Definition at line 681 of file boxfunc4.c.
References boxaCopy(), boxaGetCount(), boxaSwapBoxes(), and L_COPY.
| l_int32 boxaPlotSides | ( | BOXA * | boxa, |
| const char * | plotname, | ||
| NUMA ** | pnal, | ||
| NUMA ** | pnat, | ||
| NUMA ** | pnar, | ||
| NUMA ** | pnab, | ||
| PIX ** | ppixd | ||
| ) |
| [in] | boxa | source boxa |
| [in] | plotname | [optional], can be NULL |
| [out] | pnal | [optional] na of left sides |
| [out] | pnat | [optional] na of top sides |
| [out] | pnar | [optional] na of right sides |
| [out] | pnab | [optional] na of bottom sides |
| [out] | ppixd | [optional] pix of the output plot |
Notes:
(1) This debugging function shows the progression of the four
sides in the boxa. There must be at least 2 boxes.
(2) If there are invalid boxes (e.g., if only even or odd
indices have valid boxes), this will fill them with the
nearest valid box before plotting.
(3) The plotfiles are put in /tmp/lept/plots/, and are named
either with plotname or, if NULL, a default name.
Definition at line 1979 of file boxfunc4.c.
References boxaDestroy(), boxaFillSequence(), boxaGetBoxGeometry(), boxaGetCount(), gplotCreate(), L_USE_ALL_BOXES, lept_mkdir(), numaAddNumber(), and numaCreate().
Referenced by boxaLinearFit(), boxaSmoothSequenceMedian(), and boxaWindowedMedian().
| l_int32 boxaPlotSizes | ( | BOXA * | boxa, |
| const char * | plotname, | ||
| NUMA ** | pnaw, | ||
| NUMA ** | pnah, | ||
| PIX ** | ppixd | ||
| ) |
| [in] | boxa | source boxa |
| [in] | plotname | [optional], can be NULL |
| [out] | pnaw | [optional] na of widths |
| [out] | pnah | [optional] na of heights |
| [out] | ppixd | [optional] pix of the output plot |
Notes:
(1) This debugging function shows the progression of box width
and height in the boxa. There must be at least 2 boxes.
(2) If there are invalid boxes (e.g., if only even or odd
indices have valid boxes), this will fill them with the
nearest valid box before plotting.
(3) The plotfiles are put in /tmp/lept/plots/, and are named
either with plotname or, if NULL, a default name. Make sure
that plotname is a string with no whitespace characters.
Definition at line 2091 of file boxfunc4.c.
References boxaDestroy(), boxaFillSequence(), boxaGetBoxGeometry(), boxaGetCount(), gplotCreate(), L_USE_ALL_BOXES, lept_mkdir(), numaAddNumber(), and numaCreate().
Referenced by boxaLinearFit(), boxaSmoothSequenceMedian(), and boxaWindowedMedian().
| BOXA* boxaReconcileEvenOddHeight | ( | BOXA * | boxas, |
| l_int32 | sides, | ||
| l_int32 | delh, | ||
| l_int32 | op, | ||
| l_float32 | factor, | ||
| l_int32 | start | ||
| ) |
| [in] | boxas | containing at least 3 valid boxes in even and odd |
| [in] | sides | L_ADJUST_TOP, L_ADJUST_BOT, L_ADJUST_TOP_AND_BOT |
| [in] | delh | threshold on median height difference |
| [in] | op | L_ADJUST_CHOOSE_MIN, L_ADJUST_CHOOSE_MAX |
| [in] | factor | > 0.0, typically near 1.0 |
| [in] | start | 0 if pairing (0,1), etc; 1 if pairing (1,2), etc |
Notes:
(1) The basic idea is to reconcile differences in box height
in the even and odd boxes, by moving the top and/or bottom
edges in the even and odd boxes. Choose the edge or edges
to be moved, whether to adjust the boxes with the min
or the max of the medians, and the threshold on the median
difference between even and odd box heights for the operations
to take place. The same threshold is also used to
determine if each individual box edge is to be adjusted.
(2) Boxes are conditionally reset with either the same top (y)
value or the same bottom value, or both. The value is
determined by the greater or lesser of the medians of the
even and odd boxes, with the choice depending on the value
of op, which selects for either min or max median height.
If the median difference between even and odd boxes is
greater than dely, then any individual box edge that differs
from the selected median by more than dely is set to
the selected median times a factor typically near 1.0.
(3) Note that if selecting for minimum height, you will choose
the largest y-value for the top and the smallest y-value for
the bottom of the box.
(4) Typical input might be the output of boxaSmoothSequence(),
where even and odd boxa have been independently regulated.
(5) Require at least 3 valid even boxes and 3 valid odd boxes.
Median values will be used for invalid boxes.
(6) If the median height is not representative of the boxes
in boxas, this can make things much worse. In that case,
ignore the value of op, and force pairwise equality of the
heights, with pairwise maximal vertical extension.
Definition at line 1693 of file boxfunc4.c.
References boxaAdjustHeightToTarget(), boxaCopy(), boxaDestroy(), boxaGetMedianVals(), boxaGetValidCount(), boxaMergeEvenOdd(), boxaSplitEvenOdd(), boxaTestEvenOddHeight(), L_ADJUST_BOT, L_ADJUST_CHOOSE_MIN, L_ADJUST_TOP, L_ADJUST_TOP_AND_BOT, L_CLONE, and L_COPY.
| BOXA* boxaReconcilePairWidth | ( | BOXA * | boxas, |
| l_int32 | delw, | ||
| l_int32 | op, | ||
| l_float32 | factor, | ||
| NUMA * | na | ||
| ) |
| [in] | boxas | |
| [in] | delw | threshold on adjacent width difference |
| [in] | op | L_ADJUST_CHOOSE_MIN, L_ADJUST_CHOOSE_MAX |
| [in] | factor | > 0.0, typically near 1.0 |
| [in] | na | [optional] indicator array allowing change |
Notes:
(1) This reconciles differences in the width of adjacent boxes,
by moving one side of one of the boxes in each pair.
If the widths in the pair differ by more than some
threshold, move either the left side for even boxes or
the right side for odd boxes, depending on if we're choosing
the min or max. If choosing min, the width of the max is
set to factor * (width of min). If choosing max, the width
of the min is set to factor * (width of max).
(2) If na exists, it is an indicator array corresponding to the
boxes in boxas. If na != NULL, only boxes with an
indicator value of 1 are allowed to adjust; otherwise,
all boxes can adjust.
(3) Typical input might be the output of boxaSmoothSequence(),
where even and odd boxa have been independently regulated.
Definition at line 1874 of file boxfunc4.c.
References boxaDestroy(), boxaGetBox(), boxaGetCount(), boxaMergeEvenOdd(), boxaSplitEvenOdd(), boxDestroy(), boxGetGeometry(), boxSetGeometry(), L_ADJUST_CHOOSE_MIN, L_CLONE, and numaGetIValue().
| [in] | boxas | |
| [in] | area | threshold value of width * height |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
| [out] | pchanged | [optional] 1 if changed; 0 if clone returned |
Notes:
(1) Uses box copies in the new boxa.
(2) To keep small components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep large components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 376 of file boxfunc4.c.
References boxaCopy(), boxaGetCount(), boxaMakeAreaIndicator(), boxaSelectWithIndicator(), L_COPY, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, and numaDestroy().
Referenced by boxaCompareRegions().
| BOXA* boxaSelectBySize | ( | BOXA * | boxas, |
| l_int32 | width, | ||
| l_int32 | height, | ||
| l_int32 | type, | ||
| l_int32 | relation, | ||
| l_int32 * | pchanged | ||
| ) |
| [in] | boxas | |
| [in] | width,height | threshold dimensions |
| [in] | type | L_SELECT_WIDTH, L_SELECT_HEIGHT, L_SELECT_IF_EITHER, L_SELECT_IF_BOTH |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
| [out] | pchanged | [optional] 1 if changed; 0 if clone returned |
Notes:
(1) The args specify constraints on the size of the
components that are kept.
(2) Uses box copies in the new boxa.
(3) If the selection type is L_SELECT_WIDTH, the input
height is ignored, and v.v.
(4) To keep small components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep large components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 226 of file boxfunc4.c.
References boxaCopy(), boxaGetCount(), boxaMakeSizeIndicator(), boxaSelectWithIndicator(), L_COPY, L_SELECT_HEIGHT, 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_WIDTH, and numaDestroy().
| [in] | boxas | |
| [in] | ratio | width/height threshold value |
| [in] | relation | L_SELECT_IF_LT, L_SELECT_IF_GT, L_SELECT_IF_LTE, L_SELECT_IF_GTE |
| [out] | pchanged | [optional] 1 if changed; 0 if clone returned |
Notes:
(1) Uses box copies in the new boxa.
(2) To keep narrow components, use relation = L_SELECT_IF_LT or
L_SELECT_IF_LTE.
To keep wide components, use relation = L_SELECT_IF_GT or
L_SELECT_IF_GTE.
Definition at line 480 of file boxfunc4.c.
References boxaCopy(), boxaGetCount(), boxaMakeWHRatioIndicator(), boxaSelectWithIndicator(), L_COPY, L_SELECT_IF_GT, L_SELECT_IF_GTE, L_SELECT_IF_LT, L_SELECT_IF_LTE, and numaDestroy().
| [in] | boxas | |
| [in] | first | use 0 to select from the beginning |
| [in] | last | use 0 to select to the end |
| [in] | copyflag | L_COPY, L_CLONE |
Notes:
(1) The copyflag specifies what we do with each box from boxas.
Specifically, L_CLONE inserts a clone into boxad of each
selected box from boxas.
Definition at line 110 of file boxfunc4.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaGetBox(), boxaGetCount(), L_CLONE, L_COPY, and L_INSERT.
| [in] | boxas | |
| [in] | na | indicator numa |
| [out] | pchanged | [optional] 1 if changed; 0 if clone returned |
Notes:
(1) Returns a copy of the boxa if no components are removed.
(2) Uses box copies in the new boxa.
(3) The indicator numa has values 0 (ignore) and 1 (accept).
Definition at line 582 of file boxfunc4.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaGetBox(), L_COPY, L_INSERT, numaGetCount(), and numaGetIValue().
Referenced by boxaSelectByArea(), boxaSelectBySize(), and boxaSelectByWHRatio().
| l_int32 boxaSizeRange | ( | BOXA * | boxa, |
| l_int32 * | pminw, | ||
| l_int32 * | pminh, | ||
| l_int32 * | pmaxw, | ||
| l_int32 * | pmaxh | ||
| ) |
| [in] | boxa | |
| [out] | pminw,pminh,pmaxw,pmaxh | [optional] range of dimensions of box in the array |
Definition at line 2500 of file boxfunc4.c.
References boxaGetBoxGeometry(), and boxaGetCount().
Referenced by boxaaSizeRange().
| BOXA* boxaSmoothSequenceLS | ( | BOXA * | boxas, |
| l_float32 | factor, | ||
| l_int32 | subflag, | ||
| l_int32 | maxdiff, | ||
| l_int32 | extrapixels, | ||
| l_int32 | debug | ||
| ) |
| [in] | boxas | source boxa |
| [in] | factor | reject outliers with widths and heights deviating from the median by more than factor times the median variation from the median; typically ~3 |
| [in] | subflag | L_USE_MINSIZE, L_USE_MAXSIZE, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | maxdiff | parameter used with L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | extrapixels | pixels added on all sides (or subtracted if extrapixels < 0) when using L_SUB_ON_LOC_DIFF and L_SUB_ON_SIZE_DIFF |
| [in] | debug | 1 for debug output |
Notes:
(1) This returns a modified version of boxas by constructing
for each input box a box that has been linear least square fit
(LSF) to the entire set. The linear fitting is done to each of
the box sides independently, after outliers are rejected,
and it is computed separately for sequences of even and
odd boxes. Once the linear LSF box is found, the output box
(in boxad) is constructed from the input box and the LSF
box, depending on subflag. See boxaModifyWithBoxa() for
details on the use of subflag and maxdiff.
(2) This is useful if, in both the even and odd sets, the box
edges vary roughly linearly with its index in the set.
Definition at line 966 of file boxfunc4.c.
References boxaCopy(), boxaDestroy(), boxaGetCount(), boxaLinearFit(), boxaMergeEvenOdd(), boxaModifyWithBoxa(), boxaSplitEvenOdd(), boxaWrite(), L_COPY, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MAX, L_USE_CAPPED_MIN, L_USE_MAXSIZE, L_USE_MINSIZE, and lept_mkdir().
| BOXA* boxaSmoothSequenceMedian | ( | BOXA * | boxas, |
| l_int32 | halfwin, | ||
| l_int32 | subflag, | ||
| l_int32 | maxdiff, | ||
| l_int32 | extrapixels, | ||
| l_int32 | debug | ||
| ) |
| [in] | boxas | source boxa |
| [in] | halfwin | half-width of sliding window; used to find median |
| [in] | subflag | L_USE_MINSIZE, L_USE_MAXSIZE, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | maxdiff | parameter used with L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MIN, L_USE_CAPPED_MAX |
| [in] | extrapixels | pixels added on all sides (or subtracted if extrapixels < 0) when using L_SUB_ON_LOC_DIFF and L_SUB_ON_SIZE_DIFF |
| [in] | debug | 1 for debug output |
Notes:
(1) The target width of the sliding window is 2 * halfwin + 1.
If necessary, this will be reduced by boxaWindowedMedian().
(2) This returns a modified version of boxas by constructing
for each input box a box that has been smoothed with windowed
median filtering. The filtering is done to each of the
box sides independently, and it is computed separately for
sequences of even and odd boxes. The output boxad is
constructed from the input boxa and the filtered boxa,
depending on subflag. See boxaModifyWithBoxa() for
details on the use of subflag, maxdiff and extrapixels.
(3) This is useful for removing noise separately in the even
and odd sets, where the box edge locations can have
discontinuities but otherwise vary roughly linearly within
intervals of size halfwin or larger.
(4) If you don't need to handle even and odd sets separately,
just do this:
boxam = boxaWindowedMedian(boxas, halfwin, debug);
boxad = boxaModifyWithBoxa(boxas, boxam, subflag, maxdiff,
extrapixels);
boxaDestroy(&boxam);
Definition at line 1072 of file boxfunc4.c.
References boxaCopy(), boxaDestroy(), boxaGetCount(), boxaMergeEvenOdd(), boxaModifyWithBoxa(), boxaPlotSides(), boxaPlotSizes(), boxaSplitEvenOdd(), boxaWindowedMedian(), boxaWrite(), L_COPY, L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, L_USE_CAPPED_MAX, L_USE_CAPPED_MIN, L_USE_MAXSIZE, L_USE_MINSIZE, and lept_mkdir().
| l_int32 boxaSwapBoxes | ( | BOXA * | boxa, |
| l_int32 | i, | ||
| l_int32 | j | ||
| ) |
| [in] | boxa | |
| [in] | i,j | two indices of boxes, that are to be swapped |
Definition at line 718 of file boxfunc4.c.
References Boxa::box, and boxaGetCount().
Referenced by boxaPermuteRandom().
|
static |
| [in] | boxa1,boxa2 | |
| [in] | start | 0 if pairing (0,1), etc; 1 if pairing (1,2), etc |
| [out] | pdel1 | root mean of (dely^2 + delh^2 for boxa1 |
| [out] | pdel2 | root mean of (dely^2 + delh^2 for boxa2 |
Notes:
(1) This compares differences in the y location and height of
adjacent boxes, in each of the input boxa.
Definition at line 1802 of file boxfunc4.c.
References boxaGetBoxGeometry(), and boxaGetCount().
Referenced by boxaReconcileEvenOddHeight().
| [in] | boxas | source boxa |
| [in] | halfwin | half width of window over which the median is found |
| [in] | debug | 1 for debug output |
Notes:
(1) This finds a set of boxes (boxad) where each edge of each box is
a windowed median smoothed value to the edges of the
input set of boxes (boxas).
(2) Invalid input boxes are filled from nearby ones.
(3) The returned boxad can then be used in boxaModifyWithBoxa()
to selectively change the boxes in the source boxa.
Definition at line 1330 of file boxfunc4.c.
References boxaAddBox(), boxaCopy(), boxaCreate(), boxaDestroy(), boxaExtractAsNuma(), boxaFillSequence(), boxaGetCount(), boxaPlotSides(), boxaPlotSizes(), boxCreate(), L_COPY, L_INSERT, L_USE_ALL_BOXES, numaDestroy(), numaGetIValue(), and numaWindowedMedian().
Referenced by boxaSmoothSequenceMedian().
| [in] | box | |
| [in] | ncorners | 2 or 4 for the representation of the box |
Notes:
(1) If ncorners == 2, we select the UL and LR corners.
Otherwise we save all 4 corners in this order: UL, UR, LL, LR.
Definition at line 862 of file boxfunc4.c.
References boxGetGeometry(), ptaAddPt(), and ptaCreate().
Referenced by boxaConvertToPta().
| [in] | pta |
Notes:
(1) For 2 corners, the order of the 2 points is UL, LR.
For 4 corners, the order of points is UL, UR, LL, LR.
Definition at line 904 of file boxfunc4.c.
References boxCreate(), ptaGetCount(), and ptaGetIPt().
| [in] | pta | |
| [in] | ncorners | 2 or 4 for the representation of each box |
Notes:
(1) For 2 corners, the order of the 2 points is UL, LR.
For 4 corners, the order of points is UL, UR, LL, LR.
(2) Each derived box is the minimum size containing all corners.
Definition at line 807 of file boxfunc4.c.
References boxaAddBox(), boxaCreate(), boxCreate(), L_INSERT, ptaGetCount(), and ptaGetIPt().
Referenced by boxaAffineTransform(), boxaRotate(), boxaScale(), and boxaTranslate().
1.8.14