Файл src/pix4.c

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

Макросы

#define DEBUG_EDGES   0

Функции

NUMApixGetGrayHistogram (PIX *pixs, l_int32 factor)
NUMApixGetGrayHistogramMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor)
l_int32 pixGetColorHistogram (PIX *pixs, l_int32 factor, NUMA **pnar, NUMA **pnag, NUMA **pnab)
l_int32 pixGetColorHistogramMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, NUMA **pnar, NUMA **pnag, NUMA **pnab)
l_int32 pixGetRankValueMaskedRGB (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, l_float32 rank, l_float32 *prval, l_float32 *pgval, l_float32 *pbval)
l_int32 pixGetRankValueMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, l_float32 rank, l_float32 *pval, NUMA **pna)
l_int32 pixGetAverageMaskedRGB (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, l_int32 type, l_float32 *prval, l_float32 *pgval, l_float32 *pbval)
l_int32 pixGetAverageMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, l_int32 type, l_float32 *pval)
l_int32 pixGetAverageTiledRGB (PIX *pixs, l_int32 sx, l_int32 sy, l_int32 type, PIX **ppixr, PIX **ppixg, PIX **ppixb)
PIXpixGetAverageTiled (PIX *pixs, l_int32 sx, l_int32 sy, l_int32 type)
l_int32 pixGetExtremeValue (PIX *pixs, l_int32 factor, l_int32 type, l_int32 *prval, l_int32 *pgval, l_int32 *pbval, l_int32 *pgrayval)
l_int32 pixGetMaxValueInRect (PIX *pixs, BOX *box, l_uint32 *pmaxval, l_int32 *pxmax, l_int32 *pymax)
PIXpixaGetAlignedStats (PIXA *pixa, l_int32 type, l_int32 nbins, l_int32 thresh)
l_int32 pixaExtractColumnFromEachPix (PIXA *pixa, l_int32 col, PIX *pixd)
l_int32 pixGetRowStats (PIX *pixs, l_int32 type, l_int32 nbins, l_int32 thresh, l_float32 *colvect)
l_int32 pixGetColumnStats (PIX *pixs, l_int32 type, l_int32 nbins, l_int32 thresh, l_float32 *rowvect)
l_int32 pixSetPixelColumn (PIX *pix, l_int32 col, l_float32 *colvect)
l_int32 pixThresholdForFgBg (PIX *pixs, l_int32 factor, l_int32 thresh, l_int32 *pfgval, l_int32 *pbgval)
l_int32 pixSplitDistributionFgBg (PIX *pixs, l_float32 scorefract, l_int32 factor, l_int32 *pthresh, l_int32 *pfgval, l_int32 *pbgval, l_int32 debugflag)
l_int32 pixaFindDimensions (PIXA *pixa, NUMA **pnaw, NUMA **pnah)
NUMApixaFindAreaPerimRatio (PIXA *pixa)
l_int32 pixFindAreaPerimRatio (PIX *pixs, l_int32 *tab, l_float32 *pfract)
NUMApixaFindPerimSizeRatio (PIXA *pixa)
l_int32 pixFindPerimSizeRatio (PIX *pixs, l_int32 *tab, l_float32 *pratio)
NUMApixaFindAreaFraction (PIXA *pixa)
l_int32 pixFindAreaFraction (PIX *pixs, l_int32 *tab, l_float32 *pfract)
NUMApixaFindWidthHeightRatio (PIXA *pixa)
NUMApixaFindWidthHeightProduct (PIXA *pixa)
PIXpixClipRectangle (PIX *pixs, BOX *box, BOX **pboxc)
PIXpixClipMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_uint32 outval)
l_int32 pixClipToForeground (PIX *pixs, PIX **ppixd, BOX **pbox)
l_int32 pixClipBoxToForeground (PIX *pixs, BOX *boxs, PIX **ppixd, BOX **pboxd)
l_int32 pixScanForForeground (PIX *pixs, BOX *box, l_int32 scanflag, l_int32 *ploc)
l_int32 pixClipBoxToEdges (PIX *pixs, BOX *boxs, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, PIX **ppixd, BOX **pboxd)
l_int32 pixScanForEdge (PIX *pixs, BOX *box, l_int32 lowthresh, l_int32 highthresh, l_int32 maxwidth, l_int32 factor, l_int32 scanflag, l_int32 *ploc)

Переменные

static const l_uint32 rmask32 []

Макросы

#define DEBUG_EDGES   0


Функции

l_int32 pixaExtractColumnFromEachPix ( PIXA pixa,
l_int32  col,
PIX pixd 
)

pixaExtractColumnFromEachPix()

Input: pixa (of identically sized, 8 bpp; not cmapped) col (column index) pixd (pix into which each column is inserted) Return: 0 if OK, 1 on error

NUMA* pixaFindAreaFraction ( PIXA pixa  ) 

pixaFindAreaFraction()

Input: pixa (of 1 bpp pix) Return: na (of area fractions for each pix), or null on error

Notes: (1) This is typically used for a pixa consisting of 1 bpp connected components.

NUMA* pixaFindAreaPerimRatio ( PIXA pixa  ) 

pixaFindAreaPerimRatio()

Input: pixa (of 1 bpp pix) Return: na (of area/perimeter ratio for each pix), or null on error

Notes: (1) This is typically used for a pixa consisting of 1 bpp connected components.

l_int32 pixaFindDimensions ( PIXA pixa,
NUMA **  pnaw,
NUMA **  pnah 
)

pixaFindDimensions()

Input: pixa &naw (<optional return>=""> numa of pix widths) &nah (<optional return>=""> numa of pix heights) Return: 0 if OK, 1 on error

NUMA* pixaFindPerimSizeRatio ( PIXA pixa  ) 

pixaFindPerimSizeRatio()

Input: pixa (of 1 bpp pix) Return: na (of fg perimeter/(w*h) ratio for each pix), or null on error

Notes: (1) This is typically used for a pixa consisting of 1 bpp connected components.

NUMA* pixaFindWidthHeightProduct ( PIXA pixa  ) 

pixaFindWidthHeightProduct()

Input: pixa (of 1 bpp pix) Return: na (of width*height products for each pix), or null on error

Notes: (1) This is typically used for a pixa consisting of 1 bpp connected components.

NUMA* pixaFindWidthHeightRatio ( PIXA pixa  ) 

pixaFindWidthHeightRatio()

Input: pixa (of 1 bpp pix) Return: na (of width/height ratios for each pix), or null on error

Notes: (1) This is typically used for a pixa consisting of 1 bpp connected components.

PIX* pixaGetAlignedStats ( PIXA pixa,
l_int32  type,
l_int32  nbins,
l_int32  thresh 
)

pixaGetAlignedStats()

Input: pixa (of identically sized, 8 bpp pix; not cmapped) type (L_MEAN_ABSVAL, L_MEDIAN_VAL, L_MODE_VAL, L_MODE_COUNT) nbins (of histogram for median and mode; ignored for mean) thresh (on histogram for mode val; ignored for all other types) Return: pix (with pixelwise aligned stats), or null on error.

Notes: (1) Each pixel in the returned pix represents an average (or median, or mode) over the corresponding pixels in each pix in the pixa. (2) The parameter works with L_MODE_VAL only, and sets a minimum occupancy of the mode bin. If the occupancy of the mode bin is less than , the mode value is returned as 0. To always return the actual mode value, set = 0. See pixGetRowStats().

l_int32 pixClipBoxToEdges ( PIX pixs,
BOX boxs,
l_int32  lowthresh,
l_int32  highthresh,
l_int32  maxwidth,
l_int32  factor,
PIX **  ppixd,
BOX **  pboxd 
)

pixClipBoxToEdges()

Input: pixs (1 bpp) boxs (<optional> ; use full image if null) lowthresh (threshold to choose clipping location) highthresh (threshold required to find an edge) maxwidth (max allowed width between low and high thresh locs) factor (sampling factor along pixel counting direction) &pixd (<optional return>=""> clipped pix returned) &boxd (<optional return>=""> bounding box) Return: 0 if OK; 1 on error or if a fg edge is not found from all four sides.

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 . (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().

l_int32 pixClipBoxToForeground ( PIX pixs,
BOX boxs,
PIX **  ppixd,
BOX **  pboxd 
)

pixClipBoxToForeground()

Input: pixs (1 bpp) boxs (<optional> ; use full image if null) &pixd (<optional return>=""> clipped pix returned) &boxd (<optional return>=""> bounding box) Return: 0 if OK; 1 on error or if there are no fg pixels

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.

PIX* pixClipMasked ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_uint32  outval 
)

pixClipMasked()

Input: pixs (1, 2, 4, 8, 16, 32 bpp; colormap ok) pixm (clipping mask, 1 bpp) x, y (origin of clipping mask relative to pixs) outval (val to use for pixels that are outside the mask) Return: pixd, (clipped pix) or null on error or if pixm doesn't intersect pixs

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 = 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 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);

PIX* pixClipRectangle ( PIX pixs,
BOX box,
BOX **  pboxc 
)

pixClipRectangle()

Input: pixs box (requested clipping region; const) &boxc (<optional return>=""> actual box of clipped region) Return: clipped pix, or null on error or if rectangle doesn't intersect pixs

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.

l_int32 pixClipToForeground ( PIX pixs,
PIX **  ppixd,
BOX **  pbox 
)

pixClipToForeground()

Input: pixs (1 bpp) &pixd (<optional return>=""> clipped pix returned) &box (<optional return>=""> bounding box) Return: 0 if OK; 1 on error or if there are no fg pixels

Notes: (1) At least one of {&pixd, &box} must be specified. (2) If there are no fg pixels, the returned ptrs are null.

l_int32 pixFindAreaFraction ( PIX pixs,
l_int32 tab,
l_float32 pfract 
)

pixFindAreaFraction()

Input: pixs (1 bpp) tab (<optional> pixel sum table, can be NULL) &fract (<return> fg area/size ratio) Return: 0 if OK, 1 on error

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.

l_int32 pixFindAreaPerimRatio ( PIX pixs,
l_int32 tab,
l_float32 pfract 
)

pixFindAreaPerimRatio()

Input: pixs (1 bpp) tab (<optional> pixel sum table, can be NULL) &fract (<return> area/perimeter ratio) Return: 0 if OK, 1 on error

Notes: (1) The area is the number of fg pixels that are not on the boundary (i.e., not 8-connected to a bg pixel), and the perimeter is the number of boundary fg pixels. (2) This is typically used for a pixa consisting of 1 bpp connected components.

l_int32 pixFindPerimSizeRatio ( PIX pixs,
l_int32 tab,
l_float32 pratio 
)

pixFindPerimSizeRatio()

Input: pixs (1 bpp) tab (<optional> pixel sum table, can be NULL) &ratio (<return> perimeter/size ratio) Return: 0 if OK, 1 on error

Notes: (1) The size is the sum of the width and height of the pix, and the perimeter is the number of boundary fg 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.

l_int32 pixGetAverageMasked ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor,
l_int32  type,
l_float32 pval 
)

pixGetAverageMasked()

Input: pixs (8 or 16 bpp, or colormapped) pixm (<optional> 1 bpp mask over which average is to be taken; use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0) factor (subsampling factor; >= 1) type (L_MEAN_ABSVAL, L_ROOT_MEAN_SQUARE, L_STANDARD_DEVIATION, L_VARIANCE) &val (<return> measured value of given 'type') Return: 0 if OK, 1 on error

Notes: (1) Use L_MEAN_ABSVAL to get the average value of pixels in pixs that are under the fg of the optional mask. If the mask is null, it finds the average of the pixels in pixs. (2) Likewise, use L_ROOT_MEAN_SQUARE to get the rms value of pixels in pixs, either masked or not; L_STANDARD_DEVIATION to get the standard deviation from the mean of the pixels; L_VARIANCE to get the average squared difference from the expected value. The variance is the square of the stdev. For the standard deviation, we use sqrt(<(<x> - x)>^2) = sqrt(<x^2> - <x>^2) (3) Set the subsampling factor > 1 to reduce the amount of computation. (4) Clipping of pixm (if it exists) to pixs is done in the inner loop. (5) Input x,y are ignored unless pixm exists.

l_int32 pixGetAverageMaskedRGB ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor,
l_int32  type,
l_float32 prval,
l_float32 pgval,
l_float32 pbval 
)

pixGetAverageMaskedRGB()

Input: pixs (32 bpp, or colormapped) pixm (<optional> 1 bpp mask over which average is to be taken; use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0) factor (subsampling factor; >= 1) type (L_MEAN_ABSVAL, L_ROOT_MEAN_SQUARE, L_STANDARD_DEVIATION, L_VARIANCE) &rval (<return optional>=""> measured red value of given 'type') &gval (<return optional>=""> measured green value of given 'type') &bval (<return optional>=""> measured blue value of given 'type') Return: 0 if OK, 1 on error

Notes: (1) For usage, see pixGetAverageMasked(). (2) If there is a colormap, it is removed before the 8 bpp component images are extracted.

PIX* pixGetAverageTiled ( PIX pixs,
l_int32  sx,
l_int32  sy,
l_int32  type 
)

pixGetAverageTiled()

Input: pixs (8 bpp, or colormapped) sx, sy (tile size; must be at least 2 x 2) type (L_MEAN_ABSVAL, L_ROOT_MEAN_SQUARE, L_STANDARD_DEVIATION) Return: pixd (average values in each tile), or null on error

Notes: (1) Only computes for tiles that are entirely contained in pixs. (2) Use L_MEAN_ABSVAL to get the average abs value within the tile; L_ROOT_MEAN_SQUARE to get the rms value within each tile; L_STANDARD_DEVIATION to get the standard dev. from the average within each tile. (3) If colormapped, converts to 8 bpp gray.

l_int32 pixGetAverageTiledRGB ( PIX pixs,
l_int32  sx,
l_int32  sy,
l_int32  type,
PIX **  ppixr,
PIX **  ppixg,
PIX **  ppixb 
)

pixGetAverageTiledRGB()

Input: pixs (32 bpp, or colormapped) sx, sy (tile size; must be at least 2 x 2) type (L_MEAN_ABSVAL, L_ROOT_MEAN_SQUARE, L_STANDARD_DEVIATION) &pixr (<optional return>=""> tiled 'average' of red component) &pixg (<optional return>=""> tiled 'average' of green component) &pixb (<optional return>=""> tiled 'average' of blue component) Return: 0 if OK, 1 on error

Notes: (1) For usage, see pixGetAverageTiled(). (2) If there is a colormap, it is removed before the 8 bpp component images are extracted.

l_int32 pixGetColorHistogram ( PIX pixs,
l_int32  factor,
NUMA **  pnar,
NUMA **  pnag,
NUMA **  pnab 
)

pixGetColorHistogram()

Input: pixs (rgb or colormapped) factor (subsampling factor; integer >= 1) &nar (<return> red histogram) &nag (<return> green histogram) &nab (<return> blue histogram) Return: 0 if OK, 1 on error

Notes: (1) This generates a set of three 256 entry histograms, one for each color component (r,g,b). (2) Set the subsampling factor > 1 to reduce the amount of computation.

l_int32 pixGetColorHistogramMasked ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor,
NUMA **  pnar,
NUMA **  pnag,
NUMA **  pnab 
)

pixGetColorHistogramMasked()

Input: pixs (32 bpp rgb, or colormapped) pixm (<optional> 1 bpp mask over which histogram is to be computed; use use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0; these values are ignored if pixm is null) factor (subsampling factor; integer >= 1) &nar (<return> red histogram) &nag (<return> green histogram) &nab (<return> blue histogram) Return: 0 if OK, 1 on error

Notes: (1) This generates a set of three 256 entry histograms, (2) Set the subsampling factor > 1 to reduce the amount of computation. (3) Clipping of pixm (if it exists) to pixs is done in the inner loop. (4) Input x,y are ignored unless pixm exists.

l_int32 pixGetColumnStats ( PIX pixs,
l_int32  type,
l_int32  nbins,
l_int32  thresh,
l_float32 rowvect 
)

pixGetColumnStats()

Input: pixs (8 bpp; not cmapped) type (L_MEAN_ABSVAL, L_MEDIAN_VAL, L_MODE_VAL, L_MODE_COUNT) nbins (of histogram for median and mode; ignored for mean) thresh (on histogram for mode val; ignored for all other types) rowvect (vector of results gathered down the columns of pixs) Return: 0 if OK, 1 on error

Notes: (1) This computes a row vector of statistics using each column of a Pix. The result is put in . (2) The parameter works with L_MODE_VAL only, and sets a minimum occupancy of the mode bin. If the occupancy of the mode bin is less than , the mode value is returned as 0. To always return the actual mode value, set = 0. (3) What is the meaning of this parameter? For each column, the total count in the histogram is h, the image height. So , relative to h, gives a measure of the ratio of the bin width to the width of the distribution. The larger , the narrower the distribution must be for the mode value to be returned (instead of returning 0).

l_int32 pixGetExtremeValue ( PIX pixs,
l_int32  factor,
l_int32  type,
l_int32 prval,
l_int32 pgval,
l_int32 pbval,
l_int32 pgrayval 
)

pixGetExtremeValue()

Input: pixs (8 bpp grayscale, 32 bpp rgb, or colormapped) factor (subsampling factor; >= 1; ignored if colormapped) type (L_CHOOSE_MIN or L_CHOOSE_MAX) &rval (<optional return>=""> red component) &gval (<optional return>=""> green component) &bval (<optional return>=""> blue component) &grayval (<optional return>=""> min gray value) Return: 0 if OK, 1 on error

Notes: (1) If pixs is grayscale, the result is returned in &grayval. Otherwise, if there is a colormap or d == 32, each requested color component is returned. At least one color component (address) must be input.

NUMA* pixGetGrayHistogram ( PIX pixs,
l_int32  factor 
)

pixGetGrayHistogram()

Input: pixs (1, 2, 4, 8, 16 bpp; can be colormapped) factor (subsampling factor; integer >= 1) Return: na (histogram), or null on error

Notes: (1) This generates a histogram of gray or cmapped pixels. The image must not be rgb. (2) If pixs does not have a colormap, the output histogram is of size 2^d, where d is the depth of pixs. (3) If pixs has has a colormap with color entries, the histogram generated is of the colormap indices, and is of size 2^d. (4) If pixs has a gray (r=g=b) colormap, a temporary 8 bpp image without the colormap is used to construct a histogram of size 256. (5) Set the subsampling factor > 1 to reduce the amount of computation.

NUMA* pixGetGrayHistogramMasked ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor 
)

pixGetGrayHistogramMasked()

Input: pixs (8 bpp, or colormapped) pixm (<optional> 1 bpp mask over which histogram is to be computed; use use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0; these values are ignored if pixm is null) factor (subsampling factor; integer >= 1) Return: na (histogram), or null on error

Notes: (1) If pixs is cmapped, it is converted to 8 bpp gray. (2) This always returns a 256-value histogram of pixel values. (3) Set the subsampling factor > 1 to reduce the amount of computation. (4) Clipping of pixm (if it exists) to pixs is done in the inner loop. (5) Input x,y are ignored unless pixm exists.

l_int32 pixGetMaxValueInRect ( PIX pixs,
BOX box,
l_uint32 pmaxval,
l_int32 pxmax,
l_int32 pymax 
)

pixGetMaxValueInRect()

Input: pixs (8 bpp or 32 bpp grayscale; no color space components) box (<optional> region; set box = NULL to use entire pixs) &maxval (<optional return>=""> max value in region) &xmax (<optional return>=""> x location of max value) &ymax (<optional return>=""> y location of max value) Return: 0 if OK, 1 on error

Notes: (1) This can be used to find the maximum and its location in a 2-dimensional histogram, where the x and y directions represent two color components (e.g., saturation and hue). (2) Note that here a 32 bpp pixs has pixel values that are simply numbers. They are not 8 bpp components in a colorspace.

l_int32 pixGetRankValueMasked ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor,
l_float32  rank,
l_float32 pval,
NUMA **  pna 
)

pixGetRankValueMasked()

Input: pixs (8 bpp, or colormapped) pixm (<optional> 1 bpp mask over which rank val is to be taken; use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0; these values are ignored if pixm is null) factor (subsampling factor; integer >= 1) rank (between 0.0 and 1.0; 1.0 is brightest, 0.0 is darkest) &val (<return> pixel value corresponding to input rank) &na (<optional return>=""> of histogram) Return: 0 if OK, 1 on error

Notes: (1) Computes the rank value of pixels in pixs that are under the fg of the optional mask. If the mask is null, it computes the average of the pixels in pixs. (2) Set the subsampling factor > 1 to reduce the amount of computation. (3) Clipping of pixm (if it exists) to pixs is done in the inner loop. (4) Input x,y are ignored unless pixm exists. (5) The rank must be in [0.0 ... 1.0], where the brightest pixel has rank 1.0. For the median pixel value, use 0.5. (6) The histogram can optionally be returned, so that other rank values can be extracted without recomputing the histogram. In that case, just use numaHistogramGetValFromRank(na, rank, &val); on the returned Numa for additional rank values.

l_int32 pixGetRankValueMaskedRGB ( PIX pixs,
PIX pixm,
l_int32  x,
l_int32  y,
l_int32  factor,
l_float32  rank,
l_float32 prval,
l_float32 pgval,
l_float32 pbval 
)

pixGetRankValueMaskedRGB()

Input: pixs (32 bpp) pixm (<optional> 1 bpp mask over which rank val is to be taken; use all pixels if null) x, y (UL corner of pixm relative to the UL corner of pixs; can be < 0; these values are ignored if pixm is null) factor (subsampling factor; integer >= 1) rank (between 0.0 and 1.0; 1.0 is brightest, 0.0 is darkest) &rval (<optional return>=""> red component val for to input rank) &gval (<optional return>=""> green component val for to input rank) &bval (<optional return>=""> blue component val for to input rank) Return: 0 if OK, 1 on error

Notes: (1) Computes the rank component values of pixels in pixs that are under the fg of the optional mask. If the mask is null, it computes the average of the pixels in pixs. (2) Set the subsampling factor > 1 to reduce the amount of computation. (4) Input x,y are ignored unless pixm exists. (5) The rank must be in [0.0 ... 1.0], where the brightest pixel has rank 1.0. For the median pixel value, use 0.5.

l_int32 pixGetRowStats ( PIX pixs,
l_int32  type,
l_int32  nbins,
l_int32  thresh,
l_float32 colvect 
)

pixGetRowStats()

Input: pixs (8 bpp; not cmapped) type (L_MEAN_ABSVAL, L_MEDIAN_VAL, L_MODE_VAL, L_MODE_COUNT) nbins (of histogram for median and mode; ignored for mean) thresh (on histogram for mode; ignored for mean and median) colvect (vector of results gathered across the rows of pixs) Return: 0 if OK, 1 on error

Notes: (1) This computes a column vector of statistics using each row of a Pix. The result is put in . (2) The parameter works with L_MODE_VAL only, and sets a minimum occupancy of the mode bin. If the occupancy of the mode bin is less than , the mode value is returned as 0. To always return the actual mode value, set = 0. (3) What is the meaning of this parameter? For each row, the total count in the histogram is w, the image width. So , relative to w, gives a measure of the ratio of the bin width to the width of the distribution. The larger , the narrower the distribution must be for the mode value to be returned (instead of returning 0). (4) If the Pix consists of a set of corresponding columns, one for each Pix in a Pixa, the width of the Pix is the number of Pix in the Pixa and the column vector can be stored as a column in a Pix of the same size as each Pix in the Pixa.

l_int32 pixScanForEdge ( PIX pixs,
BOX box,
l_int32  lowthresh,
l_int32  highthresh,
l_int32  maxwidth,
l_int32  factor,
l_int32  scanflag,
l_int32 ploc 
)

pixScanForEdge()

Input: pixs (1 bpp) box (<optional> within which the search is conducted) lowthresh (threshold to choose clipping location) highthresh (threshold required to find an edge) maxwidth (max allowed width between low and high thresh locs) factor (sampling factor along pixel counting direction) scanflag (direction of scan; e.g., L_FROM_LEFT) &loc (location in scan direction of first black pixel) Return: 0 if OK; 1 on error or if the edge is not found

Notes: (1) If there are no fg pixels, the position is set to 0. Caller must check the return value! (2) Use == NULL to scan from edge of pixs (3) As the scan progresses, the location where the sum of pixels equals or excees is noted (loc). The scan is stopped when the sum of pixels equals or exceeds . If the scan distance between loc and that point does not exceed , an edge is found and its position is taken to be loc. 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.

l_int32 pixScanForForeground ( PIX pixs,
BOX box,
l_int32  scanflag,
l_int32 ploc 
)

pixScanForForeground()

Input: pixs (1 bpp) box (<optional> within which the search is conducted) scanflag (direction of scan; e.g., L_FROM_LEFT) &loc (location in scan direction of first black pixel) Return: 0 if OK; 1 on error or if no fg pixels are found

Notes: (1) If there are no fg pixels, the position is set to 0. Caller must check the return value! (2) Use == NULL to scan from edge of pixs

l_int32 pixSetPixelColumn ( PIX pix,
l_int32  col,
l_float32 colvect 
)

pixSetPixelColumn()

Input: pix (8 bpp; not cmapped) col (column index) colvect (vector of floats) Return: 0 if OK, 1 on error

l_int32 pixSplitDistributionFgBg ( PIX pixs,
l_float32  scorefract,
l_int32  factor,
l_int32 pthresh,
l_int32 pfgval,
l_int32 pbgval,
l_int32  debugflag 
)

pixSplitDistributionFgBg()

Input: pixs (any depth; cmapped ok) scorefract (fraction of the max score, used to determine the range over which the histogram min is searched) factor (subsampling factor; integer >= 1) &thresh (<optional return>=""> best threshold for separating) &fgval (<optional return>=""> average foreground value) &bgval (<optional return>=""> average background value) debugflag (1 for plotting of distribution and split point) Return: 0 if OK, 1 on error

Notes: (1) See numaSplitDistribution() for details on the underlying method of choosing a threshold.

l_int32 pixThresholdForFgBg ( PIX pixs,
l_int32  factor,
l_int32  thresh,
l_int32 pfgval,
l_int32 pbgval 
)

pixThresholdForFgBg()

Input: pixs (any depth; cmapped ok) factor (subsampling factor; integer >= 1) thresh (threshold for generating foreground mask) &fgval (<optional return>=""> average foreground value) &bgval (<optional return>=""> average background value) Return: 0 if OK, 1 on error


Переменные

const l_uint32 rmask32[] [static]

Инициализатор

 {0x0,
    0x00000001, 0x00000003, 0x00000007, 0x0000000f,
    0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
    0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
    0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
    0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
    0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
    0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
    0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff}


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9