![]() |
Leptonica 1.85.0
Image processing and image analysis suite
|
#include <string.h>#include <math.h>#include "allheaders.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_EDGES 0 |
Functions | |
| l_ok | pixaFindDimensions (PIXA *pixa, NUMA **pnaw, NUMA **pnah) |
| l_ok | pixFindAreaPerimRatio (PIX *pixs, l_int32 *tab, l_float32 *pfract) |
| NUMA * | pixaFindPerimToAreaRatio (PIXA *pixa) |
| l_ok | pixFindPerimToAreaRatio (PIX *pixs, l_int32 *tab, l_float32 *pfract) |
| NUMA * | pixaFindPerimSizeRatio (PIXA *pixa) |
| l_ok | pixFindPerimSizeRatio (PIX *pixs, l_int32 *tab, l_float32 *pratio) |
| NUMA * | pixaFindAreaFraction (PIXA *pixa) |
| l_ok | pixFindAreaFraction (PIX *pixs, l_int32 *tab, l_float32 *pfract) |
| NUMA * | pixaFindAreaFractionMasked (PIXA *pixa, PIX *pixm, l_int32 debug) |
| l_ok | pixFindAreaFractionMasked (PIX *pixs, BOX *box, PIX *pixm, l_int32 *tab, l_float32 *pfract) |
| NUMA * | pixaFindWidthHeightRatio (PIXA *pixa) |
| NUMA * | pixaFindWidthHeightProduct (PIXA *pixa) |
| l_ok | pixFindOverlapFraction (PIX *pixs1, PIX *pixs2, l_int32 x2, l_int32 y2, l_int32 *tab, l_float32 *pratio, l_int32 *pnoverlap) |
| BOXA * | pixFindRectangleComps (PIX *pixs, l_int32 dist, l_int32 minw, l_int32 minh) |
| l_ok | pixConformsToRectangle (PIX *pixs, BOX *box, l_int32 dist, l_int32 *pconforms) |
| PIX * | pixExtractRectangularRegions (PIX *pixs, BOXA *boxa) |
| PIXA * | pixClipRectangles (PIX *pixs, BOXA *boxa) |
| PIX * | pixClipRectangle (PIX *pixs, BOX *box, BOX **pboxc) |
| PIX * | pixClipRectangleWithBorder (PIX *pixs, BOX *box, l_int32 maxbord, BOX **pboxn) |
| PIX * | pixClipMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_uint32 outval) |
| l_ok | pixCropToMatch (PIX *pixs1, PIX *pixs2, PIX **ppixd1, PIX **ppixd2) |
| PIX * | pixCropToSize (PIX *pixs, l_int32 w, l_int32 h) |
| PIX * | pixResizeToMatch (PIX *pixs, PIX *pixt, l_int32 w, l_int32 h) |
| PIX * | pixMakeSymmetricMask (l_int32 w, l_int32 h, l_float32 hf, l_float32 vf, l_int32 type) |
| PIX * | pixMakeFrameMask (l_int32 w, l_int32 h, l_float32 hf1, l_float32 hf2, l_float32 vf1, l_float32 vf2) |
| PIX * | pixMakeCoveringOfRectangles (PIX *pixs, l_int32 maxiters) |
| l_ok | pixFractionFgInMask (PIX *pix1, PIX *pix2, l_float32 *pfract) |
| l_ok | pixClipToForeground (PIX *pixs, PIX **ppixd, BOX **pbox) |
| l_ok | pixTestClipToForeground (PIX *pixs, l_int32 *pcanclip) |
| l_ok | pixClipBoxToForeground (PIX *pixs, BOX *boxs, PIX **ppixd, BOX **pboxd) |
| l_ok | pixScanForForeground (PIX *pixs, BOX *box, l_int32 scanflag, l_int32 *ploc) |
| l_ok | pixClipBoxToEdges (PIX *pixs, BOX *boxs, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, PIX **ppixd, BOX **pboxd) |
| l_ok | pixScanForEdge (PIX *pixs, BOX *box, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, l_int32 scanflag, l_int32 *ploc) |
| NUMA * | pixExtractOnLine (PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor) |
| l_float32 | pixAverageOnLine (PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 factor) |
| NUMA * | pixAverageIntensityProfile (PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 factor1, l_int32 factor2) |
| NUMA * | pixReversalProfile (PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 minreversal, l_int32 factor1, l_int32 factor2) |
| l_ok | pixWindowedVarianceOnLine (PIX *pixs, l_int32 dir, l_int32 loc, l_int32 c1, l_int32 c2, l_int32 size, NUMA **pnad) |
| l_ok | pixMinMaxNearLine (PIX *pixs, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 dist, l_int32 direction, NUMA **pnamin, NUMA **pnamax, l_float32 *pminave, l_float32 *pmaxave) |
| PIX * | pixRankRowTransform (PIX *pixs) |
| PIX * | pixRankColumnTransform (PIX *pixs) |
Variables | |
| static const l_uint32 | rmask32 [] |
This file has these operations:
(1) Measurement of 1 bpp image properties
(2) Extract rectangular regions
(3) Clip to foreground
(4) Extract pixel averages, reversals and variance along lines
(5) Rank row and column transforms
Measurement of properties
l_int32 pixaFindDimensions()
l_int32 pixFindAreaPerimRatio()
NUMA *pixaFindPerimToAreaRatio()
l_int32 pixFindPerimToAreaRatio()
NUMA *pixaFindPerimSizeRatio()
l_int32 pixFindPerimSizeRatio()
NUMA *pixaFindAreaFraction()
l_int32 pixFindAreaFraction()
NUMA *pixaFindAreaFractionMasked()
l_int32 pixFindAreaFractionMasked()
NUMA *pixaFindWidthHeightRatio()
NUMA *pixaFindWidthHeightProduct()
l_int32 pixFindOverlapFraction()
BOXA *pixFindRectangleComps()
l_int32 pixConformsToRectangle()
Extract rectangular regions
PIX *pixExtractRectangularRegions()
PIXA *pixClipRectangles()
PIX *pixClipRectangle()
PIX *pixClipRectangleWithBorder()
PIX *pixClipMasked()
l_int32 pixCropToMatch()
PIX *pixCropToSize()
PIX *pixResizeToMatch()
Select a connected component by size
PIX *pixSelectComponentBySize()
PIX *pixFilterComponentBySize()
Make special masks
PIX *pixMakeSymmetricMask()
PIX *pixMakeFrameMask()
Generate a covering of rectangles over connected components
PIX * pixMakeCoveringOfRectangles()
Fraction of Fg pixels under a mask
l_int32 pixFractionFgInMask()
Clip to foreground
PIX *pixClipToForeground()
l_int32 pixTestClipToForeground()
l_int32 pixClipBoxToForeground()
l_int32 pixScanForForeground()
l_int32 pixClipBoxToEdges()
l_int32 pixScanForEdge()
Extract pixel averages and reversals along lines
NUMA *pixExtractOnLine()
l_float32 pixAverageOnLine()
NUMA *pixAverageIntensityProfile()
NUMA *pixReversalProfile()
Extract windowed variance along a line
NUMA *pixWindowedVarianceOnLine()
Extract min/max of pixel values near lines
l_int32 pixMinMaxNearLine()
Rank row and column transforms
PIX *pixRankRowTransform()
PIX *pixRankColumnTransform()
Definition in file pix5.c.
| [in] | pixa | of 1 bpp pix |
Notes:
(1) This is typically used for a pixa consisting of
1 bpp connected components.
Definition at line 430 of file pix5.c.
References L_CLONE, and pixFindAreaFraction().
| [in] | pixa | of 1 bpp pix |
| [in] | pixm | mask image |
| [in] | debug | 1 for output, 0 to suppress |
Notes:
(1) This is typically used for a pixa consisting of
1 bpp connected components, which has an associated
boxa giving the location of the components relative
to the mask origin.
(2) The debug flag displays in green and red the masked and
unmasked parts of the image from which pixa was derived.
Definition at line 517 of file pix5.c.
References L_CLONE, L_SET_WHITE, PIX_MASK, and pixFindAreaFractionMasked().
| [in] | pixa | of 1 bpp pix |
Notes:
(1) This is typically used for a pixa consisting of
1 bpp connected components.
(2) This has a minimum value for a circle of pi/4; a value for
a rectangle component of approx. 1.0; and a value much larger
than 1.0 for a component with a highly irregular boundary.
Definition at line 338 of file pix5.c.
References L_CLONE, and pixFindPerimSizeRatio().
| [in] | pixa | of 1 bpp pix |
Notes:
(1) This is typically used for a pixa consisting of
1 bpp connected components.
Definition at line 238 of file pix5.c.
References L_CLONE, and pixFindPerimToAreaRatio().
| NUMA * pixAverageIntensityProfile | ( | PIX * | pixs, |
| l_float32 | fract, | ||
| l_int32 | dir, | ||
| l_int32 | first, | ||
| l_int32 | last, | ||
| l_int32 | factor1, | ||
| l_int32 | factor2 ) |
| [in] | pixs | any depth; colormap OK |
| [in] | fract | fraction of image width or height to be used |
| [in] | dir | averaging direction: L_HORIZONTAL_LINE or L_VERTICAL_LINE |
| [in] | first,last | span of rows or columns to measure |
| [in] | factor1 | sampling along fast scan direction; >= 1 |
| [in] | factor2 | sampling along slow scan direction; >= 1 |
Notes:
(1) If d != 1 bpp, colormaps are removed and the result
is converted to 8 bpp.
(2) If dir == L_HORIZONTAL_LINE, the intensity is averaged
along each horizontal raster line (sampled by factor1),
and the profile is the array of these averages in the
vertical direction between first and last raster lines,
and sampled by factor2.
(3) If dir == L_VERTICAL_LINE, the intensity is averaged
along each vertical line (sampled by factor1),
and the profile is the array of these averages in the
horizontal direction between first and last columns,
and sampled by factor2.
(4) The averages are measured over the central fract of the image.
Use fract == 1.0 to average across the entire width or height.
Definition at line 2637 of file pix5.c.
References L_HORIZONTAL_LINE, L_VERTICAL_LINE, pixAverageOnLine(), and REMOVE_CMAP_TO_GRAYSCALE.
| l_float32 pixAverageOnLine | ( | PIX * | pixs, |
| l_int32 | x1, | ||
| l_int32 | y1, | ||
| l_int32 | x2, | ||
| l_int32 | y2, | ||
| l_int32 | factor ) |
| [in] | pixs | 1 bpp or 8 bpp; no colormap |
| [in] | x1,y1 | starting pt for line |
| [in] | x2,y2 | end pt for line |
| [in] | factor | sampling; >= 1 |
Notes:
(1) The line must be either horizontal or vertical, so either
y1 == y2 (horizontal) or x1 == x2 (vertical).
(2) If horizontal, x1 must be <= x2.
If vertical, y1 must be <= y2.
characterize the intensity smoothness along a line.
(3) Input end points are clipped to the pix.
Definition at line 2540 of file pix5.c.
References GET_DATA_BIT, GET_DATA_BYTE, L_HORIZONTAL_LINE, and L_VERTICAL_LINE.
Referenced by pixAverageIntensityProfile().
| l_ok pixClipBoxToEdges | ( | PIX * | pixs, |
| BOX * | boxs, | ||
| l_int32 | lowthresh, | ||
| l_int32 | highthresh, | ||
| l_int32 | maxwidth, | ||
| l_int32 | factor, | ||
| PIX ** | ppixd, | ||
| BOX ** | pboxd ) |
| [in] | pixs | 1 bpp |
| [in] | boxs | [optional] ; use full image if null |
| [in] | lowthresh | threshold to choose clipping location |
| [in] | highthresh | threshold required to find an edge |
| [in] | maxwidth | max allowed width between low and high thresh locs |
| [in] | factor | sampling factor along pixel counting direction |
| [out] | ppixd | [optional] clipped pix returned |
| [out] | pboxd | [optional] bounding box |
Notes:
(1) At least one of {&pixd, &boxd} must be specified.
(2) If there are no fg pixels, the returned ptrs are null.
(3) This function attempts to locate rectangular "image" regions
of high-density fg pixels, that have well-defined edges
on the four sides.
(4) Edges are searched for on each side, iterating in order
from left, right, top and bottom. As each new edge is
found, the search box is resized to use that location.
Once an edge is found, it is held. If no more edges
are found in one iteration, the search fails.
(5) See pixScanForEdge() for usage of the thresholds and maxwidth.
(6) The thresholds must be at least 1, and the low threshold
cannot be larger than the high threshold.
(7) If the low and high thresholds are both 1, this is equivalent
to pixClipBoxToForeground().
Definition at line 2115 of file pix5.c.
References L_FROM_BOT, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, pixClipBoxToForeground(), pixClipRectangle(), and pixScanForEdge().
| [in] | pixs | 1 bpp |
| [in] | boxs | [optional] use full image if null |
| [out] | ppixd | [optional] clipped pix returned |
| [out] | pboxd | [optional] bounding box |
Notes:
(1) At least one of {&pixd, &boxd} must be specified.
(2) If there are no fg pixels, the returned ptrs are null.
(3) Do not use &pixs for the 3rd arg or &boxs for the 4th arg;
this will leak memory.
Definition at line 1937 of file pix5.c.
References L_FROM_BOT, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, pixClipRectangle(), pixClipToForeground(), and pixScanForForeground().
Referenced by pixClipBoxToEdges().
| [in] | pixs | 1, 2, 4, 8, 16, 32 bpp; colormap ok |
| [in] | pixm | clipping mask, 1 bpp |
| [in] | x,y | origin of clipping mask relative to pixs |
| [in] | outval | val to use for pixels that are outside the mask |
Notes:
(1) If pixs has a colormap, it is preserved in pixd.
(2) The depth of pixd is the same as that of pixs.
(3) If the depth of pixs is 1, use outval = 0 for white background
and 1 for black; otherwise, use the max value for white
and 0 for black. If pixs has a colormap, the max value for
outval is 0xffffffff; otherwise, it is 2^d - 1.
(4) When using 1 bpp pixs, this is a simple clip and
blend operation. For example, if both pix1 and pix2 are
black text on white background, and you want to OR the
fg on the two images, let pixm be the inverse of pix2.
Then the operation takes all of pix1 that's in the bg of
pix2, and for the remainder (which are the pixels
corresponding to the fg of the pix2), paint them black
(1) in pix1. The function call looks like
pixClipMasked(pix2, pixInvert(pix1, pix1), x, y, 1);
Definition at line 1167 of file pix5.c.
References pixClipRectangle().
| [in] | pixs | |
| [in] | box | requested clipping region; const |
| [out] | pboxc | [optional] actual box of clipped region |
Notes:
This should be simple, but there are choices to be made.
The box is defined relative to the pix coordinates. However,
if the box is not contained within the pix, we have two choices:
(1) clip the box to the pix
(2) make a new pix equal to the full box dimensions,
but let rasterop do the clipping and positioning
of the src with respect to the dest
Choice (2) immediately brings up the problem of what pixel values
to use that were not taken from the src. For example, on a grayscale
image, do you want the pixels not taken from the src to be black
or white or something else? To implement choice 2, one needs to
specify the color of these extra pixels.
So we adopt (1), and clip the box first, if necessary,
before making the dest pix and doing the rasterop. But there
is another issue to consider. If you want to paste the
clipped pix back into pixs, it must be properly aligned, and
it is necessary to use the clipped box for alignment.
Accordingly, this function has a third (optional) argument, which is
the input box clipped to the src pix.
Definition at line 1035 of file pix5.c.
References PIX_SRC.
Referenced by pixClipBoxToEdges(), pixClipBoxToForeground(), pixClipMasked(), pixClipRectangles(), pixClipRectangleWithBorder(), pixClipToForeground(), and pixConformsToRectangle().
| [in] | pixs | |
| [in] | boxa | requested clipping regions |
Notes:
(1) The boxa in the returned pixa has the regions clipped from
the input pixs.
Definition at line 971 of file pix5.c.
References L_CLONE, L_INSERT, and pixClipRectangle().
Referenced by pixExtractRectangularRegions().
| [in] | pixs | |
| [in] | box | requested clipping region; const |
| [in] | maxbord | maximum amount of border to include |
| [out] | pboxn | box in coordinates of returned pix |
Notes:
(1) This underclips by an amount determined by the minimum of
maxbord and the amount of border that can be included
equally on all 4 sides.
(2) If part of the rectangle lies outside the pix, no border
is included on any side.
Definition at line 1096 of file pix5.c.
References pixClipRectangle().
| [in] | pixs | 1 bpp |
| [out] | ppixd | [optional] clipped pix returned |
| [out] | pbox | [optional] bounding box |
Notes:
(1) At least one of {&pixd, &box} must be specified.
(2) If there are no fg pixels, the returned ptrs are null.
Definition at line 1769 of file pix5.c.
References GET_DATA_BIT, and pixClipRectangle().
Referenced by pixClipBoxToForeground().
| [in] | pixs | 1 bpp |
| [in] | box | [optional] if null, use the entire pixs |
| [in] | dist | max distance allowed between bounding box and nearest foreground pixel within it |
| [out] | pconforms | 0 (false) if not conforming; 1 (true) if conforming |
Notes:
(1) There are several ways to test if a connected component has
an essentially rectangular boundary, such as:
a. Fraction of fill into the bounding box
b. Max-min distance of fg pixel from periphery of bounding box
c. Max depth of bg intrusions into component within bounding box
The weakness of (a) is that it is highly sensitive to holes
within the c.c. The weakness of (b) is that it can have
arbitrarily large intrusions into the c.c. Method (c) tests
the integrity of the outer boundary of the c.c., with respect
to the enclosing bounding box, so we use it.
(2) This tests if the connected component within the box conforms
to the box at all points on the periphery within dist.
Inside, at a distance from the box boundary that is greater
than dist, we don't care about the pixels in the c.c.
(3) We can think of the conforming condition as follows:
No pixel inside a distance dist from the boundary
can connect to the boundary through a path through the bg.
To implement this, we need to do a flood fill. We can go
either from inside toward the boundary, or the other direction.
It's easiest to fill from the boundary, and then verify that
there are no filled pixels farther than dist from the boundary.
Definition at line 866 of file pix5.c.
References PIX_CLR, and pixClipRectangle().
Referenced by pixFindRectangleComps().
| [in] | pixs1 | any depth, colormap OK |
| [in] | pixs2 | any depth, colormap OK |
| [out] | ppixd1 | may be a clone |
| [out] | ppixd2 | may be a clone |
Notes:
(1) This resizes pixs1 and/or pixs2 by cropping at the right
and bottom, so that they're the same size.
(2) If a pix doesn't need to be cropped, a clone is returned.
(3) Note: the images are implicitly aligned to the UL corner.
Definition at line 1227 of file pix5.c.
References pixCropToSize().
| [in] | pixs | any depth, colormap OK |
| [in] | w,h | max dimensions of cropped image |
Notes:
(1) If either w or h is smaller than the corresponding dimension
of pixs, this returns a cropped image; otherwise it returns
a clone of pixs.
Definition at line 1268 of file pix5.c.
References PIX_SRC.
Referenced by pixCropToMatch().
| NUMA * pixExtractOnLine | ( | PIX * | pixs, |
| l_int32 | x1, | ||
| l_int32 | y1, | ||
| l_int32 | x2, | ||
| l_int32 | y2, | ||
| l_int32 | factor ) |
| [in] | pixs | 1 bpp or 8 bpp; no colormap |
| [in] | x1,y1 | one end point for line |
| [in] | x2,y2 | another end pt for line |
| [in] | factor | sampling; >= 1 |
Notes:
(1) Input end points are clipped to the pix.
(2) If the line is either horizontal, or closer to horizontal
than to vertical, the points will be extracted from left
to right in the pix. Likewise, if the line is vertical,
or closer to vertical than to horizontal, the points will
be extracted from top to bottom.
(3) Can be used with numaCountReverals(), for example, to
characterize the intensity smoothness along a line.
Definition at line 2422 of file pix5.c.
References L_HORIZONTAL_LINE, L_OBLIQUE_LINE, and L_VERTICAL_LINE.
Referenced by pixReversalProfile().
pixExtractRectangularRegions()
| [in] | pixs | |
| [in] | boxa | regions to extract |
Notes:
(1) The returned pix has the rectangular regions clipped from
the input pixs.
(2) We could equally well do this operation using a mask of 1's over
the regions determined by the boxa:
pix1 = pixCreateTemplate(pixs);
pixMaskBoxa(pix1, pix1, boxa, L_SET_PIXELS);
pixAnd(pix1, pix1, pixs);
Definition at line 936 of file pix5.c.
References pixClipRectangles().
| l_ok pixFindAreaFraction | ( | PIX * | pixs, |
| l_int32 * | tab, | ||
| l_float32 * | pfract ) |
| [in] | pixs | 1 bpp |
| [in] | tab | [optional] pixel sum table, can be NULL |
| [out] | pfract | fg area/size ratio |
Notes:
(1) This finds the ratio of the number of fg pixels to the
size of the pix (w * h). It is typically used for a
single connected component.
Definition at line 471 of file pix5.c.
Referenced by pixaFindAreaFraction().
| l_ok pixFindAreaFractionMasked | ( | PIX * | pixs, |
| BOX * | box, | ||
| PIX * | pixm, | ||
| l_int32 * | tab, | ||
| l_float32 * | pfract ) |
| [in] | pixs | 1 bpp, typically a single component |
| [in] | box | [optional] for pixs relative to pixm |
| [in] | pixm | 1 bpp mask, typically over the entire image from which the component pixs was extracted |
| [in] | tab | [optional] pixel sum table, can be NULL |
| [out] | pfract | fg area/size ratio |
Notes:
(1) This finds the ratio of the number of masked fg pixels
in pixs to the total number of fg pixels in pixs.
It is typically used for a single connected component.
If there are no fg pixels, this returns a ratio of 0.0.
(2) The box gives the location of the pix relative to that
of the UL corner of the mask. Therefore, the rasterop
is performed with the pix translated to its location
(x, y) in the mask before ANDing.
If box == NULL, the UL corners of pixs and pixm are aligned.
Definition at line 594 of file pix5.c.
References PIX_MASK.
Referenced by pixaFindAreaFractionMasked().
| l_ok pixFindAreaPerimRatio | ( | PIX * | pixs, |
| l_int32 * | tab, | ||
| l_float32 * | pfract ) |
| [in] | pixs | 1 bpp |
| [in] | tab | [optional] pixel sum table, can be NULL |
| [out] | pfract | area/perimeter ratio |
Notes:
(1) The area is the number of fg pixels that are not on the
boundary (i.e., are not 8-connected to a bg pixel), and the
perimeter is the number of fg boundary pixels. Returns
0.0 if there are no fg pixels.
(2) This function is retained because clients are using it.
| l_ok pixFindOverlapFraction | ( | PIX * | pixs1, |
| PIX * | pixs2, | ||
| l_int32 | x2, | ||
| l_int32 | y2, | ||
| l_int32 * | tab, | ||
| l_float32 * | pratio, | ||
| l_int32 * | pnoverlap ) |
| [in] | pixs1,pixs2 | 1 bpp |
| [in] | x2,y2 | location in pixs1 of UL corner of pixs2 |
| [in] | tab | [optional] pixel sum table, can be null |
| [out] | pratio | ratio fg intersection to fg union |
| [out] | pnoverlap | [optional] number of overlapping pixels |
Notes:
(1) The UL corner of pixs2 is placed at (x2, y2) in pixs1.
(2) This measure is similar to the correlation.
| l_ok pixFindPerimSizeRatio | ( | PIX * | pixs, |
| l_int32 * | tab, | ||
| l_float32 * | pratio ) |
| [in] | pixs | 1 bpp |
| [in] | tab | [optional] pixel sum table, can be NULL |
| [out] | pratio | perimeter/size ratio |
Notes:
(1) We take the 'size' as twice the sum of the width and
height of pixs, and the perimeter is the number of fg
boundary pixels. We use the fg pixels of the boundary
because the pix may be clipped to the boundary, so an
erosion is required to count all boundary pixels.
(2) This has a large value for dendritic, fractal-like components
with highly irregular boundaries.
(3) This is typically used for a single connected component.
It has a value of about 1.0 for rectangular components with
relatively smooth boundaries.
Definition at line 386 of file pix5.c.
Referenced by pixaFindPerimSizeRatio().
| l_ok pixFindPerimToAreaRatio | ( | PIX * | pixs, |
| l_int32 * | tab, | ||
| l_float32 * | pfract ) |
| [in] | pixs | 1 bpp |
| [in] | tab | [optional] pixel sum table, can be NULL |
| [out] | pfract | perimeter/area ratio |
Notes:
(1) The perimeter is the number of fg boundary pixels, and the
area is the number of fg pixels. This returns 0.0 if
there are no fg pixels.
(2) Unlike pixFindAreaPerimRatio(), this uses the full set of
fg pixels for the area, and the ratio is taken in the opposite
order.
(3) This is typically used for a single connected component.
This always has a value <= 1.0, and if the average distance
of a fg pixel from the nearest bg pixel is d, this has
a value ~1/d.
Definition at line 286 of file pix5.c.
Referenced by pixaFindPerimToAreaRatio().
| [in] | pixs | 1 bpp |
| [in] | dist | max distance allowed between bounding box and nearest foreground pixel within it |
| [in] | minw,minh | minimum size in each direction as a requirement for a conforming rectangle |
Notes:
(1) This applies the function pixConformsToRectangle() to
each 8-c.c. in pixs, and returns a boxa containing the
regions of all components that are conforming.
(2) Conforming components must satisfy both the size constraint
given by minsize and the slop in conforming to a rectangle
determined by dist.
Definition at line 788 of file pix5.c.
References L_CLONE, L_COPY, L_INSERT, and pixConformsToRectangle().
| [in] | pix1 | 1 bpp |
| [in] | pix2 | 1 bpp |
| [out] | pfract | fraction of fg pixels in 1 that are aligned with the fg of 2 |
Notes:
(1) This gives the fraction of fg pixels in pix1 that are in
the intersection (i.e., under the fg) of pix2:
|1 & 2|/|1|, where |...| means the number of fg pixels.
Note that this is different from the situation where
pix1 and pix2 are reversed.
(2) Both pix1 and pix2 are registered to the UL corners. A warning
is issued if pix1 and pix2 have different sizes.
(3) This can also be used to find the fraction of fg pixels in pix1
that are NOT under the fg of pix2: 1.0 - |1 & 2|/|1|
(4) If pix1 or pix2 are empty, this returns fract = 0.0.
(5) For example, pix2 could be a frame around the outside of the
image, made from pixMakeFrameMask().
| [in] | pixs | 1 bpp |
| [in] | maxiters | max iterations: use 0 to iterate to completion |
Notes:
(1) This iteratively finds the bounding boxes of the connected
components and generates a mask from them. Two iterations
should suffice for most situations.
(2) Returns an empty pix if pixs is empty.
(3) If there are many small components in proximity, it may
be useful to merge them with a morphological closing before
calling this one.
Definition at line 1644 of file pix5.c.
References L_SET_PIXELS.
| PIX * pixMakeFrameMask | ( | l_int32 | w, |
| l_int32 | h, | ||
| l_float32 | hf1, | ||
| l_float32 | hf2, | ||
| l_float32 | vf1, | ||
| l_float32 | vf2 ) |
| [in] | w,h | dimensions of output 1 bpp pix |
| [in] | hf1 | horizontal fraction of half-width at outer frame bdry |
| [in] | hf2 | horizontal fraction of half-width at inner frame bdry |
| [in] | vf1 | vertical fraction of half-width at outer frame bdry |
| [in] | vf2 | vertical fraction of half-width at inner frame bdry |
Notes:
(1) This makes an arbitrary 1-component mask with a centered fg
frame, which can have both an inner and an outer boundary.
All input fractional distances are measured from the image
border to the frame boundary, in units of the image half-width
for hf1 and hf2 and the image half-height for vf1 and vf2.
The distances to the outer frame boundary are given by hf1
and vf1; to the inner frame boundary, by hf2 and vf2.
Input fractions are thus in [0.0 ... 1.0], with hf1 <= hf2
and vf1 <= vf2. Horizontal and vertical frame widths are
thus independently specified.
(2) Special cases:
* full fg mask: hf1 = vf1 = 0.0, hf2 = vf2 = 1.0.
* empty fg (zero width) mask: set hf1 = hf2 and vf1 = vf2.
* fg rectangle with no hole: set hf2 = vf2 = 1.0.
* frame touching outer boundary: set hf1 = vf1 = 0.0.
(3) The vertical thickness of the horizontal mask parts
is 0.5 * (vf2 - vf1) * h. The horizontal thickness of the
vertical mask parts is 0.5 * (hf2 - hf1) * w.
Definition at line 1580 of file pix5.c.
References PIX_CLR, and PIX_SET.
Referenced by pixMakeSymmetricMask().
| PIX * pixMakeSymmetricMask | ( | l_int32 | w, |
| l_int32 | h, | ||
| l_float32 | hf, | ||
| l_float32 | vf, | ||
| l_int32 | type ) |
pixSelectComponentBySize()
| [in] | pixs | 1 bpp |
| [in] | rankorder | in decreasing size: 0 for largest. |
| [in] | type | L_SELECT_BY_WIDTH, L_SELECT_BY_HEIGHT, L_SELECT_BY_MAX_DIMENSION, L_SELECT_BY_AREA, L_SELECT_BY_PERIMETER |
| [in] | connectivity | 4 or 8 |
| [out] | pbox | [optional] location of returned component |
Notes:
(1) This selects the Nth largest connected component, based on
the selection type and connectivity.
(2) Note that rankorder is an integer. Use rankorder = 0 for
the largest component and rankorder = -1 for the smallest.
If rankorder >= number of components, select the smallest.
*/
PIX *
pixSelectComponentBySize(PIX *pixs,
l_int32 rankorder,
l_int32 type,
l_int32 connectivity,
BOX **pbox)
{
l_int32 n, empty, sorttype, index;
BOXA *boxa1;
NUMA *naindex;
PIX *pixd;
PIXA *pixa1, *pixa2;
if (pbox) *pbox = NULL;
if (!pixs || pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", __func__, NULL);
if (type == L_SELECT_BY_WIDTH)
sorttype = L_SORT_BY_WIDTH;
else if (type == L_SELECT_BY_HEIGHT)
sorttype = L_SORT_BY_HEIGHT;
else if (type == L_SELECT_BY_MAX_DIMENSION)
sorttype = L_SORT_BY_MAX_DIMENSION;
else if (type == L_SELECT_BY_AREA)
sorttype = L_SORT_BY_AREA;
else if (type == L_SELECT_BY_PERIMETER)
sorttype = L_SORT_BY_PERIMETER;
else
return (PIX *)ERROR_PTR("invalid selection type", __func__, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIX *)ERROR_PTR("connectivity not 4 or 8", __func__, NULL);
pixZero(pixs, &empty);
if (empty)
return (PIX *)ERROR_PTR("no foreground pixels", __func__, NULL);
boxa1 = pixConnComp(pixs, &pixa1, connectivity);
n = boxaGetCount(boxa1);
if (rankorder < 0 || rankorder >= n)
rankorder = n - 1; /* smallest */
pixa2 = pixaSort(pixa1, sorttype, L_SORT_DECREASING, &naindex, L_CLONE);
pixd = pixaGetPix(pixa2, rankorder, L_COPY);
if (pbox) {
numaGetIValue(naindex, rankorder, &index);
*pbox = boxaGetBox(boxa1, index, L_COPY);
}
numaDestroy(&naindex);
boxaDestroy(&boxa1);
pixaDestroy(&pixa1);
pixaDestroy(&pixa2);
return pixd;
}
/*!
pixFilterComponentBySize()
| [in] | pixs | 1 bpp |
| [in] | rankorder | in decreasing size: 0 for largest. |
| [in] | type | L_SELECT_BY_WIDTH, L_SELECT_BY_HEIGHT, L_SELECT_BY_MAX_DIMENSION, L_SELECT_BY_AREA, L_SELECT_BY_PERIMETER |
| [in] | connectivity | 4 or 8 |
| [out] | pbox | [optional] location of returned component |
Notes:
(1) See notes in pixSelectComponentBySize().
(2) This returns a copy of pixs, with all components removed
except for the selected one.
*/
PIX *
pixFilterComponentBySize(PIX *pixs,
l_int32 rankorder,
l_int32 type,
l_int32 connectivity,
BOX **pbox)
{
l_int32 x, y, w, h;
BOX *box;
PIX *pix1, *pix2;
if (!pixs || pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", __func__, NULL);
pix1 = pixSelectComponentBySize(pixs, rankorder, type, connectivity, &box);
if (!pix1) {
boxDestroy(&box);
return (PIX *)ERROR_PTR("pix1 not made", __func__, NULL);
}
/* Put the selected component in a new pix at the same
location as it had in pixs */
boxGetGeometry(box, &x, &y, &w, &h);
pix2 = pixCreateTemplate(pixs);
pixRasterop(pix2, x, y, w, h, PIX_SRC, pix1, 0, 0);
if (pbox)
*pbox = box;
else
boxDestroy(&box);
pixDestroy(&pix1);
return pix2;
}
/*---------------------------------------------------------------------*
Make special masks *
*---------------------------------------------------------------------*/
/*!
pixMakeSymmetricMask()
| [in] | w,h | dimensions of output 1 bpp pix |
| [in] | hf | horizontal fraction of half-width |
| [in] | vf | vertical fraction of half-height |
| [in] | type | L_USE_INNER, L_USE_OUTER |
pixd 1 bpp, or NULL on error.
Notes:
(1) This is a convenience function for generating masks with
horizontal and vertical reflection symmetry, over either
the inner or outer parts of an image.
(2) Using L_USE_INNER to generate a mask over the inner part
of the image, the mask is a solid rectangle, and the fractions
describe the distance between the boundary of the image and
the rectangle boundary. For example, with hf == vf == 0.0,
the mask covers the full image.
(3) Using L_USE_OUTER to generate a mask over an outer frame
of the image, the mask touches the boundary of the image,
and the fractions describe the location of the inner
boundary of the frame. For example, with hf == vf == 1.0,
the inner boundary is at the center of the image, so the
mask covers the full image.
(4) More examples:
* mask covering the inner 70%: hf = vf = 0.3, type = L_USE_INNER
* frame covering the outer 30%: hf = vf = 0.3, type = L_USE_OUTER
Definition at line 1525 of file pix5.c.
References L_USE_INNER, L_USE_OUTER, and pixMakeFrameMask().
| l_ok pixMinMaxNearLine | ( | PIX * | pixs, |
| l_int32 | x1, | ||
| l_int32 | y1, | ||
| l_int32 | x2, | ||
| l_int32 | y2, | ||
| l_int32 | dist, | ||
| l_int32 | direction, | ||
| NUMA ** | pnamin, | ||
| NUMA ** | pnamax, | ||
| l_float32 * | pminave, | ||
| l_float32 * | pmaxave ) |
| [in] | pixs | 8 bpp; no colormap |
| [in] | x1,y1 | starting pt for line |
| [in] | x2,y2 | end pt for line |
| [in] | dist | distance to search from line in each direction |
| [in] | direction | L_SCAN_NEGATIVE, L_SCAN_POSITIVE, L_SCAN_BOTH |
| [out] | pnamin | [optional] minimum values |
| [out] | pnamax | [optional] maximum values |
| [out] | pminave | [optional] average of minimum values |
| [out] | pmaxave | [optional] average of maximum values |
Notes:
(1) If the line is more horizontal than vertical, the values
are computed for [x1, x2], and the pixels are taken
below and/or above the local y-value. Otherwise, the
values are computed for [y1, y2] and the pixels are taken
to the left and/or right of the local x value.
(2) direction specifies which side (or both sides) of the
line are scanned for min and max values.
(3) There are two ways to tell if the returned values of min
and max averages are valid: the returned values cannot be
negative and the function must return 0.
(4) All accessed pixels are clipped to the pix.
Definition at line 2975 of file pix5.c.
References L_SCAN_BOTH, L_SCAN_NEGATIVE, and L_SCAN_POSITIVE.
| [in] | pixs | 8 bpp; no colormap |
Notes:
(1) The time is O(n) in the number of pixels and runs about
50 Mpixels/sec on a 3 GHz machine.
Definition at line 3147 of file pix5.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
| [in] | pixs | 8 bpp; no colormap |
Notes:
(1) The time is O(n) in the number of pixels and runs about
100 Mpixels/sec on a 3 GHz machine.
Definition at line 3096 of file pix5.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
| [in] | pixs | 1, 2, 4, 8, 16, 32 bpp; colormap ok |
| [in] | pixt | can be null; we use only the size |
| [in] | w,h | ignored if pixt is defined |
Notes:
(1) This resizes pixs to make pixd, without scaling, by either
cropping or extending separately in both width and height.
Extension is done by replicating the last row or column.
This is useful in a situation where, due to scaling
operations, two images that are expected to be the
same size can differ slightly in each dimension.
(2) You can use either an existing pixt or specify
both w and h. If pixt is defined, the values
in w and h are ignored.
(3) If pixt is larger than pixs (or if w and/or d is larger
than the dimension of pixs, replicate the outer row and
column of pixels in pixs into pixd.
Definition at line 1320 of file pix5.c.
References PIX_SRC.
| NUMA * pixReversalProfile | ( | PIX * | pixs, |
| l_float32 | fract, | ||
| l_int32 | dir, | ||
| l_int32 | first, | ||
| l_int32 | last, | ||
| l_int32 | minreversal, | ||
| l_int32 | factor1, | ||
| l_int32 | factor2 ) |
| [in] | pixs | any depth; colormap OK |
| [in] | fract | fraction of image width or height to be used |
| [in] | dir | profile direction: L_HORIZONTAL_LINE or L_VERTICAL_LINE |
| [in] | first,last | span of rows or columns to measure |
| [in] | minreversal | minimum change in intensity to trigger a reversal |
| [in] | factor1 | sampling along raster line (fast scan); >= 1 |
| [in] | factor2 | sampling of raster lines (slow scan); >= 1 |
Notes:
(1) If d != 1 bpp, colormaps are removed and the result
is converted to 8 bpp.
(2) If dir == L_HORIZONTAL_LINE, the the reversals are counted
along each horizontal raster line (sampled by factor1),
and the profile is the array of these sums in the
vertical direction between first and last raster lines,
and sampled by factor2.
(3) If dir == L_VERTICAL_LINE, the the reversals are counted
along each vertical column (sampled by factor1),
and the profile is the array of these sums in the
horizontal direction between first and last columns,
and sampled by factor2.
(4) For each row or column, the reversals are summed over the
central fract of the image. Use fract == 1.0 to sum
across the entire width (of row) or height (of column).
(5) minreversal is the relative change in intensity that is
required to resolve peaks and valleys. A typical number for
locating text in 8 bpp might be 50. For 1 bpp, minreversal
must be 1.
(6) The reversal profile is simply the number of reversals
in a row or column, vs the row or column index.
Definition at line 2750 of file pix5.c.
References L_HORIZONTAL_LINE, L_VERTICAL_LINE, pixExtractOnLine(), and REMOVE_CMAP_TO_GRAYSCALE.
| l_ok pixScanForEdge | ( | PIX * | pixs, |
| BOX * | box, | ||
| l_int32 | lowthresh, | ||
| l_int32 | highthresh, | ||
| l_int32 | maxwidth, | ||
| l_int32 | factor, | ||
| l_int32 | scanflag, | ||
| l_int32 * | ploc ) |
| [in] | pixs | 1 bpp |
| [in] | box | [optional] within which the search is conducted |
| [in] | lowthresh | threshold to choose clipping location |
| [in] | highthresh | threshold required to find an edge |
| [in] | maxwidth | max allowed width between low and high thresh locs |
| [in] | factor | sampling factor along pixel counting direction |
| [in] | scanflag | direction of scan; e.g., L_FROM_LEFT |
| [out] | ploc | location in scan direction of first black pixel |
Notes:
(1) If there are no fg pixels, the position is set to 0.
Caller must check the return value!
(2) Use box == NULL to scan from edge of pixs
(3) As the scan progresses, the location where the sum of
pixels equals or excees lowthresh is noted (loc). The
scan is stopped when the sum of pixels equals or exceeds
highthresh. If the scan distance between loc and that
point does not exceed maxwidth, an edge is found and
its position is taken to be loc. maxwidth implicitly
sets a minimum on the required gradient of the edge.
(4) The thresholds must be at least 1, and the low threshold
cannot be larger than the high threshold.
Definition at line 2243 of file pix5.c.
References GET_DATA_BIT, L_FROM_BOT, L_FROM_LEFT, L_FROM_RIGHT, and L_FROM_TOP.
Referenced by pixClipBoxToEdges().
| [in] | pixs | 1 bpp |
| [in] | box | [optional] within which the search is conducted |
| [in] | scanflag | direction of scan; e.g., L_FROM_LEFT |
| [out] | ploc | location in scan direction of first black pixel |
Notes:
(1) If there are no fg pixels, the position is set to 0.
Caller must check the return value!
(2) Use box == NULL to scan from edge of pixs
Definition at line 2001 of file pix5.c.
References GET_DATA_BIT, L_FROM_BOT, L_FROM_LEFT, L_FROM_RIGHT, and L_FROM_TOP.
Referenced by pixClipBoxToForeground().
| l_ok pixTestClipToForeground | ( | PIX * | pixs, |
| l_int32 * | pcanclip ) |
| [in] | pixs | 1 bpp |
| [out] | pcanclip | 1 if fg does not extend to all four edges |
Notes:
(1) This is a lightweight test to determine if a 1 bpp image
can be further cropped without loss of fg pixels.
If it cannot, canclip is set to 0.
(2) It does not test for the existence of any fg pixels.
If there are no fg pixels, it will return canclip = 1.
Check the output of the subsequent call to pixClipToForeground().
Definition at line 1867 of file pix5.c.
References GET_DATA_BIT.
| l_ok pixWindowedVarianceOnLine | ( | PIX * | pixs, |
| l_int32 | dir, | ||
| l_int32 | loc, | ||
| l_int32 | c1, | ||
| l_int32 | c2, | ||
| l_int32 | size, | ||
| NUMA ** | pnad ) |
| [in] | pixs | 8 bpp; no colormap |
| [in] | dir | L_HORIZONTAL_LINE or L_VERTICAL_LINE |
| [in] | loc | location of the constant coordinate for the line |
| [in] | c1,c2 | end point coordinates for the line |
| [in] | size | window size; must be > 1 |
| [out] | pnad | windowed square root of variance |
Notes:
(1) The returned variance array traverses the line starting
from the smallest coordinate, min(c1,c2).
(2) Line end points are clipped to pixs.
(3) The reference point for the variance calculation is the center of
the window. Therefore, the numa start parameter from
pixExtractOnLine() is incremented by size/2,
to align the variance values with the pixel coordinate.
(4) The square root of the variance is the RMS deviation from the mean.
Definition at line 2857 of file pix5.c.
References L_HORIZONTAL_LINE, L_NOCOPY, and L_VERTICAL_LINE.
|
static |