Leptonica
1.54
|
Функции | |
PIX * | pixConnCompTransform (PIX *pixs, l_int32 connect, l_int32 depth) |
PIX * | pixConnCompAreaTransform (PIX *pixs, l_int32 connect) |
l_int32 | pixConnCompIncrInit (PIX *pixs, l_int32 conn, PIX **ppixd, PTAA **pptaa, l_int32 *pncc) |
l_int32 | pixConnCompIncrAdd (PIX *pixs, PTAA *ptaa, l_int32 *pncc, l_float32 x, l_float32 y, l_int32 debug) |
l_int32 | pixGetSortedNeighborValues (PIX *pixs, l_int32 x, l_int32 y, l_int32 conn, l_int32 **pneigh, l_int32 *pnvals) |
PIX * | pixLocToColorTransform (PIX *pixs) |
PIX* pixConnCompAreaTransform | ( | PIX * | pixs, |
l_int32 | connect | ||
) |
Input: pixs (1 bpp) connect (connectivity: 4 or 8) Return: pixd (32 bpp, 1 spp), or null on error
Notes: (1) The pixel values in pixd label the area of the fg component to which the pixel belongs. Pixels in the bg are labelled 0. (2) For purposes of visualization, the output can be converted to 8 bpp, using pixConvert32To8() or pixMaxDynamicRange().
l_int32 pixConnCompIncrAdd | ( | PIX * | pixs, |
PTAA * | ptaa, | ||
l_int32 * | pncc, | ||
l_float32 | x, | ||
l_float32 | y, | ||
l_int32 | debug | ||
) |
Input: pixs (32 bpp, with pixels labelled by c.c.) ptaa (with each pta of pixel locations indexed by c.c.) &ncc (number of c.c) x,y (location of added pixel) debug (0 for no output; otherwise output whenever debug <= nvals, up to debug == 3) Return: -1 if nothing happens; 0 if a pixel is added; 1 on error
Notes: (1) This adds a pixel and updates the labelled connected components. Before calling this function, initialize the process using pixConnCompIncrInit(). (2) As a result of adding a pixel, one of the following can happen, depending on the number of neighbors with non-zero value: (a) nothing: the pixel is already a member of a c.c. (b) no neighbors: a new component is added, increasing the number of c.c. (c) one neighbor: the pixel is added to an existing c.c. (d) more than one neighbor: the added pixel causes joining of two or more c.c., reducing the number of c.c. A maximum of 4 c.c. can be joined. (3) When two c.c. are joined, the pixels in the larger index are relabelled to those of the smaller in pixs, and their locations are transferred to the pta with the smaller index in the ptaa. The pta corresponding to the larger index is then deleted. (4) This is an efficient implementation of a "union-find" operation, which supports the generation and merging of disjoint sets of pixels. This function can be called about 1.3 million times per second.
l_int32 pixConnCompIncrInit | ( | PIX * | pixs, |
l_int32 | conn, | ||
PIX ** | ppixd, | ||
PTAA ** | pptaa, | ||
l_int32 * | pncc | ||
) |
Input: pixs (1 bpp) conn (connectivity: 4 or 8) &pixd (<return> 32 bpp, with c.c. labelled) &ptaa (<return> with pixel locations indexed by c.c.) &ncc (<return> initial number of c.c.) Return: 0 if OK, 1 on error
Notes: (1) This labels the connected components in a 1 bpp pix, and additionally sets up a ptaa that lists the locations of pixels in each of the components. (2) It can be used to initialize the output image and arrays for an application that maintains information about connected components incrementally as pixels are added. (3) pixs can be empty or have some foreground pixels. (4) The connectivity is stored in pixd->special. (5) Always initialize with the first pta in ptaa being empty and representing the background value (index 0) in the pix.
PIX* pixConnCompTransform | ( | PIX * | pixs, |
l_int32 | connect, | ||
l_int32 | depth | ||
) |
Input: pixs (1 bpp) connect (connectivity: 4 or 8) depth (of pixd: 8 or 16 bpp; use 0 for auto determination) Return: pixd (8, 16 or 32 bpp), or null on error
Notes: (1) pixd is 8, 16 or 32 bpp, and the pixel values label the fg component, starting with 1. Pixels in the bg are labelled 0. (2) If = 0, the depth of pixd is 8 if the number of c.c. is less than 254, 16 if the number of c.c is less than 0xfffe, and 32 otherwise. (3) If = 8, the assigned label for the n-th component is 1 + n % 254. We use mod 254 because 0 is uniquely assigned to black: e.g., see pixcmapCreateRandom(). Likewise, if = 16, the assigned label uses mod(2^16 - 2), and if = 32, no mod is taken.
l_int32 pixGetSortedNeighborValues | ( | PIX * | pixs, |
l_int32 | x, | ||
l_int32 | y, | ||
l_int32 | conn, | ||
l_int32 ** | pneigh, | ||
l_int32 * | pnvals | ||
) |
Input: pixs (8, 16 or 32 bpp, with pixels labelled by c.c.) x, y (location of pixel) conn (4 or 8 connected neighbors) &neigh (<return> array of integers, to be filled with the values of the neighbors, if any) &nvals (<return> the number of unique neighbor values found) Return: 0 if OK, 1 on error
Notes: (1) The returned array is the unique set of neighboring pixel values, of size nvals, sorted from smallest to largest. The value 0, which represents background pixels that do not belong to any set of connected components, is discarded. (2) If there are no neighbors, this returns = NULL; otherwise, the caller must free the array. (3) For either 4 or 8 connectivity, the maximum number of unique neighbor values is 4.
PIX* pixLocToColorTransform | ( | PIX * | pixs | ) |
Input: pixs (1 bpp) Return: pixd (32 bpp rgb), or null on error
Notes: (1) This generates an RGB image where each component value is coded depending on the (x.y) location and the size of the fg connected component that the pixel in pixs belongs to. It is independent of the 4-fold orthogonal orientation, and only weakly depends on translations and small angle rotations. Background pixels are black. (2) Such encodings can be compared between two 1 bpp images by performing this transform and calculating the "earth-mover" distance on the resulting R,G,B histograms.