Leptonica 1.68
C Image Processing Library

pix5.c File Reference

Property measurement of 1bbp images, rectangular region extraction, property measurement along lines, cropping to foreground. More...

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

Go to the source code of this file.

Defines

#define DEBUG_EDGES   0

Functions

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)
l_int32 pixFindOverlapFraction (PIX *pixs1, PIX *pixs2, l_int32 x2, l_int32 y2, l_int32 *tab, l_float32 *pratio, l_int32 *pnoverlap)
BOXApixFindRectangleComps (PIX *pixs, l_int32 dist, l_int32 minw, l_int32 minh)
l_int32 pixConformsToRectangle (PIX *pixs, BOX *box, l_int32 dist, l_int32 *pconforms)
PIXpixClipRectangle (PIX *pixs, BOX *box, BOX **pboxc)
PIXpixClipMasked (PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_uint32 outval)
PIXpixResizeToMatch (PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
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)
NUMApixExtractOnLine (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)
NUMApixAverageIntensityProfile (PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 factor1, l_int32 factor2)
NUMApixReversalProfile (PIX *pixs, l_float32 fract, l_int32 dir, l_int32 first, l_int32 last, l_int32 minreversal, l_int32 factor1, l_int32 factor2)
PIXpixRankRowTransform (PIX *pixs)
PIXpixRankColumnTransform (PIX *pixs)

Variables

static const l_uint32 rmask32 []

Detailed Description

Property measurement of 1bbp images, rectangular region extraction, property measurement along lines, cropping to foreground.

  This file has these operations:

    (1) Measurement of 1 bpp image properties
    (2) Extract rectangular region
    (3) Clip to foreground
    (4) Extract pixel averages and reversals along lines
    (5) Rank row and column transforms

  Measurement of properties
         l_int32     pixaFindDimensions()
         NUMA       *pixaFindAreaPerimRatio()
         l_int32     pixFindAreaPerimRatio()
         NUMA       *pixaFindPerimSizeRatio()
         l_int32     pixFindPerimSizeRatio()
         NUMA       *pixaFindAreaFraction()
         l_int32     pixFindAreaFraction()
         NUMA       *pixaFindWidthHeightRatio()
         NUMA       *pixaFindWidthHeightProduct()
         l_int32     pixFindOverlapFraction()
         BOXA       *pixFindRectangleComps()
         l_int32     pixConformsToRectangle()

  Extract rectangular region
         PIX        *pixClipRectangle()
         PIX        *pixClipMasked()
         PIX        *pixResizeToMatch()

  Clip to foreground
         PIX        *pixClipToForeground()
         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()

  Rank row and column transforms
         PIX        *pixRankRowTransform()
         PIX        *pixRankColumnTransform()

Definition in file pix5.c.


Define Documentation

#define DEBUG_EDGES   0

Definition at line 79 of file pix5.c.


Function Documentation

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

Definition at line 95 of file pix5.c.

References ERROR_INT, L_CLONE, NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixGetDimensions(), and PROCNAME.

Referenced by main().

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.

Definition at line 136 of file pix5.c.

References ERROR_PTR, FREE, L_CLONE, makePixelSumTab8(), NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixFindAreaPerimRatio(), and PROCNAME.

Referenced by main(), and pixaSelectByAreaPerimRatio().

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.

Definition at line 179 of file pix5.c.

References ERROR_INT, FREE, makePixelSumTab8(), NULL, pixCountPixels(), pixDestroy(), pixErodeBrick(), pixGetDepth(), pixXor(), and PROCNAME.

Referenced by pixaFindAreaPerimRatio().

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.

Definition at line 224 of file pix5.c.

References ERROR_PTR, FREE, L_CLONE, makePixelSumTab8(), NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixFindPerimSizeRatio(), and PROCNAME.

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.

Definition at line 267 of file pix5.c.

References ERROR_INT, FREE, makePixelSumTab8(), NULL, pixCountPixels(), pixDestroy(), pixErodeBrick(), pixGetDepth(), pixGetDimensions(), pixXor(), and PROCNAME.

Referenced by pixaFindPerimSizeRatio().

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.

Definition at line 312 of file pix5.c.

References ERROR_PTR, FREE, L_CLONE, makePixelSumTab8(), NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixFindAreaFraction(), and PROCNAME.

Referenced by main(), and pixaSelectByAreaFraction().

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.

Definition at line 353 of file pix5.c.

References ERROR_INT, FREE, makePixelSumTab8(), pixCountPixels(), pixGetDimensions(), and PROCNAME.

Referenced by pixaFindAreaFraction().

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.

Definition at line 394 of file pix5.c.

References ERROR_PTR, L_CLONE, NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixGetDimensions(), and PROCNAME.

Referenced by pixaSelectByWidthHeightRatio().

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.

Definition at line 428 of file pix5.c.

References ERROR_PTR, L_CLONE, NULL, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixGetDimensions(), and PROCNAME.

l_int32 pixFindOverlapFraction ( PIX pixs1,
PIX pixs2,
l_int32  x2,
l_int32  y2,
l_int32 tab,
l_float32 pratio,
l_int32 pnoverlap 
)

pixFindOverlapFraction()

Input: pixs1, pixs2 (1 bpp) x2, y2 (location in pixs1 of UL corner of pixs2) tab (<optional> pixel sum table, can be null) &ratio (<return> ratio fg intersection to fg union) &noverlap (<optional return>=""> number of overlapping pixels) Return: 0 if OK, 1 on error

Notes: (1) The UL corner of pixs2 is placed at (x2, y2) in pixs1. (2) This measure is similar to the correlation.

Definition at line 466 of file pix5.c.

References ERROR_INT, FREE, makePixelSumTab8(), NULL, PIX_MASK, PIX_PAINT, pixCopy(), pixCountPixels(), pixDestroy(), pixGetDepth(), pixGetDimensions(), pixRasterop(), and PROCNAME.

BOXA* pixFindRectangleComps ( PIX pixs,
l_int32  dist,
l_int32  minw,
l_int32  minh 
)

pixFindRectangleComps()

Input: pixs (1 bpp) dist (max distance allowed between bounding box and nearest foreground pixel within it) minw, minh (minimum size in each direction as a requirement for a conforming rectangle) Return: boxa (of components that conform), or null on error

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 and the slop in conforming to a rectangle determined by .

Definition at line 530 of file pix5.c.

References boxaAddBox(), boxaCreate(), boxaDestroy(), boxaGetBox(), ERROR_PTR, L_CLONE, L_COPY, L_INSERT, NULL, pixaDestroy(), pixaGetCount(), pixaGetPix(), pixConformsToRectangle(), pixConnComp(), pixDestroy(), pixGetDepth(), pixGetDimensions(), and PROCNAME.

l_int32 pixConformsToRectangle ( PIX pixs,
BOX box,
l_int32  dist,
l_int32 pconforms 
)

pixConformsToRectangle()

Input: pixs (1 bpp) box (<optional> if null, use the entire pixs) dist (max distance allowed between bounding box and nearest foreground pixel within it) &conforms (<return> 0 (false) if not conforming; 1 (true) if conforming) Return: 0 if OK, 1 on error

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 . Inside, at a distance from the box boundary that is greater than , 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 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 from the boundary.

Definition at line 609 of file pix5.c.

References ERROR_INT, L_WARNING, NULL, PIX_CLR, pixClipRectangle(), pixCopy(), pixDestroy(), pixExtractBorderConnComps(), pixGetDepth(), pixGetDimensions(), pixInvert(), pixSetOrClearBorder(), pixZero(), and PROCNAME.

Referenced by pixFindRectangleComps().

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.

Definition at line 698 of file pix5.c.

References boxClipToRectangle(), boxDestroy(), boxGetGeometry(), ERROR_PTR, L_WARNING, NULL, PIX_SRC, pixCopyColormap(), pixCopyResolution(), pixCreate(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by finalPositioningForAlignment(), GenerateSetOfMargePix(), identifyWatershedBasin(), main(), pixaClipToPix(), pixaCreateFromBoxa(), pixaGenerateFont(), pixaMorphSequenceByRegion(), pixBlend(), pixBlendGrayAdapt(), pixClipBoxToEdges(), pixClipBoxToForeground(), pixClipMasked(), pixClipToForeground(), pixConformsToRectangle(), pixConnCompPixa(), pixConvertToPdfDataSegmented(), pixDeskewBarcode(), pixGetLocalSkewAngles(), pixPaintSelfThroughMask(), pixTilingGetTile(), and pixWarpStereoscopic().

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

Definition at line 767 of file pix5.c.

References boxCreate(), boxDestroy(), composeRGBPixel(), ERROR_PTR, extractRGBValues(), NULL, pixClipRectangle(), pixcmapGetColor(), pixcmapGetNearestIndex(), pixDestroy(), pixGetColormap(), pixGetDepth(), pixGetDimensions(), pixInvert(), pixPaintThroughMask(), and PROCNAME.

Referenced by main().

PIX* pixResizeToMatch ( PIX pixs,
PIX pixt,
l_int32  w,
l_int32  h 
)

pixResizeToMatch()

Input: pixs (1, 2, 4, 8, 16, 32 bpp; colormap ok) pixt (can be null; we use only the size) w, h (ignored if pixt is defined) Return: pixd (resized to match) or null on error

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 and . If pixt is defined, the values in and 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 835 of file pix5.c.

References ERROR_PTR, NULL, PIX_SRC, pixCopy(), pixCopyColormap(), pixCopyInputFormat(), pixCopyResolution(), pixCopyText(), pixCreate(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by pixAffinePtaWithAlpha(), pixBilinearPtaWithAlpha(), pixProjectivePtaWithAlpha(), pixRotateWithAlpha(), and pixScaleWithAlpha().

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.

Definition at line 896 of file pix5.c.

References boxCreate(), boxDestroy(), ERROR_INT, GET_DATA_BIT, NULL, pixClipRectangle(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and rmask32.

Referenced by main(), pixaCreateFromPix(), pixClipBoxToForeground(), pixGenerateSelBoundary(), pixGenerateSelRandom(), and pixGenerateSelWithRuns().

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.

Definition at line 996 of file pix5.c.

References boxCreate(), boxDestroy(), boxGetGeometry(), ERROR_INT, L_FROM_BOTTOM, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_MIN, NULL, pixClipRectangle(), pixClipToForeground(), pixGetDepth(), pixGetDimensions(), pixScanForForeground(), and PROCNAME.

Referenced by pixClipBoxToEdges(), and pixSplitComponentIntoBoxa().

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

Definition at line 1060 of file pix5.c.

References boxClipToRectangle(), boxDestroy(), boxGetGeometry(), ERROR_INT, GET_DATA_BIT, L_FROM_BOTTOM, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by pixClipBoxToForeground().

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

Definition at line 1177 of file pix5.c.

References boxCreate(), boxDestroy(), boxGetGeometry(), boxRelocateOneSide(), ERROR_INT, L_FROM_BOTTOM, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_MIN, NULL, pixClipBoxToForeground(), pixClipRectangle(), pixGetDepth(), pixGetDimensions(), pixScanForEdge(), and PROCNAME.

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.

Definition at line 1305 of file pix5.c.

References boxClipToRectangle(), boxDestroy(), boxGetGeometry(), ERROR_INT, GET_DATA_BIT, L_FROM_BOTTOM, L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_MIN, NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by pixClipBoxToEdges().

NUMA* pixExtractOnLine ( PIX pixs,
l_int32  x1,
l_int32  y1,
l_int32  x2,
l_int32  y2,
l_int32  factor 
)

pixExtractOnLine()

Input: pixs (1 bpp or 8 bpp; no colormap) x1, y1 (one end point for line) x2, y2 (another end pt for line) factor (sampling; >= 1) Return: na (of pixel values along line), or null on error.

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 1483 of file pix5.c.

References ERROR_PTR, generatePtaLine(), GPLOT_X11, L_ABS, L_HORIZONTAL_LINE, L_MAX, L_MIN, L_OBLIQUE_LINE, L_VERTICAL_LINE, L_WARNING, NULL, numaAddNumber(), numaCreate(), numaSetXParameters(), pixGetColormap(), pixGetDimensions(), pixGetPixel(), pixPlotAlongPta(), PROCNAME, ptaDestroy(), ptaGetCount(), ptaGetPt(), x1, and y1.

Referenced by main(), and pixReversalProfile().

l_float32 pixAverageOnLine ( PIX pixs,
l_int32  x1,
l_int32  y1,
l_int32  x2,
l_int32  y2,
l_int32  factor 
)

pixAverageOnLine()

Input: pixs (1 bpp or 8 bpp; no colormap) x1, y1 (starting pt for line) x2, y2 (end pt for line) factor (sampling; >= 1) Return: average of pixel values along line, or null on error.

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 1604 of file pix5.c.

References ERROR_INT, GET_DATA_BIT, GET_DATA_BYTE, L_HORIZONTAL_LINE, L_MAX, L_MIN, L_VERTICAL_LINE, L_WARNING, pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, x2, and y2.

Referenced by pixAverageIntensityProfile().

PIX* pixRankRowTransform ( PIX pixs)

pixRankRowTransform()

Input: pixs (8 bpp; no colormap) Return: pixd (with pixels sorted in each row, from min to max value)

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 1908 of file pix5.c.

References ERROR_PTR, GET_DATA_BYTE, NULL, pixCreateTemplateNoInit(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

PIX* pixRankColumnTransform ( PIX pixs)

pixRankColumnTransform()

Input: pixs (8 bpp; no colormap) Return: pixd (with pixels sorted in each column, from min to max value)

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 1959 of file pix5.c.

References ERROR_PTR, FREE, GET_DATA_BYTE, NULL, pixCreateTemplateNoInit(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetLinePtrs(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.


Variable Documentation

const l_uint32 rmask32[] [static]
Initial value:
 {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}

Definition at line 68 of file pix5.c.

Referenced by pixClipToForeground().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines