Leptonica 1.54
Файл src/runlength.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"

Функции

PIXpixRunlengthTransform (PIX *pixs, l_int32 color, l_int32 direction, l_int32 depth)
l_int32 pixFindHorizontalRuns (PIX *pix, l_int32 y, l_int32 *xstart, l_int32 *xend, l_int32 *pn)
l_int32 pixFindVerticalRuns (PIX *pix, l_int32 x, l_int32 *ystart, l_int32 *yend, l_int32 *pn)
l_int32 runlengthMembershipOnLine (l_int32 *buffer, l_int32 size, l_int32 depth, l_int32 *start, l_int32 *end, l_int32 n)
l_int32makeMSBitLocTab (l_int32 bitval)

Функции

l_int32* makeMSBitLocTab ( l_int32  bitval)

makeMSBitLocTab()

Input: bitval (either 0 or 1) Return: table (giving, for an input byte, the MS bit location, starting at 0 with the MSBit in the byte), or null on error.

Notes: (1) If bitval == 1, it finds the leftmost ON pixel in a byte; otherwise if bitval == 0, it finds the leftmost OFF pixel. (2) If there are no pixels of the indicated color in the byte, this returns 8.

l_int32 pixFindHorizontalRuns ( PIX pix,
l_int32  y,
l_int32 xstart,
l_int32 xend,
l_int32 pn 
)

pixFindHorizontalRuns()

Input: pix (1 bpp) y (line to traverse) xstart (returns array of start positions for fg runs) xend (returns array of end positions for fg runs) &n (<return> the number of runs found) Return: 0 if OK; 1 on error

Notes: (1) This finds foreground horizontal runs on a single scanline. (2) To find background runs, use pixInvert() before applying this function. (3) The xstart and xend arrays are input. They should be of size w/2 + 1 to insure that they can hold the maximum number of runs in the raster line.

l_int32 pixFindVerticalRuns ( PIX pix,
l_int32  x,
l_int32 ystart,
l_int32 yend,
l_int32 pn 
)

pixFindVerticalRuns()

Input: pix (1 bpp) x (line to traverse) ystart (returns array of start positions for fg runs) yend (returns array of end positions for fg runs) &n (<return> the number of runs found) Return: 0 if OK; 1 on error

Notes: (1) This finds foreground vertical runs on a single scanline. (2) To find background runs, use pixInvert() before applying this function. (3) The ystart and yend arrays are input. They should be of size h/2 + 1 to insure that they can hold the maximum number of runs in the raster line.

PIX* pixRunlengthTransform ( PIX pixs,
l_int32  color,
l_int32  direction,
l_int32  depth 
)

pixRunlengthTransform()

Input: pixs (1 bpp) color (0 for white runs, 1 for black runs) direction (L_HORIZONTAL_RUNS, L_VERTICAL_RUNS) depth (8 or 16 bpp) Return: pixd (8 or 16 bpp), or null on error

Notes: (1) The dest Pix is 8 or 16 bpp, with the pixel values equal to the runlength in which it is a member. The length is clipped to the max pixel value if necessary. (2) The color determines if we're labelling white or black runs. (3) A pixel that is not a member of the chosen color gets value 0; it belongs to a run of length 0 of the chosen color. (4) To convert for maximum dynamic range, either linear or log, use pixMaxDynamicRange().

l_int32 runlengthMembershipOnLine ( l_int32 buffer,
l_int32  size,
l_int32  depth,
l_int32 start,
l_int32 end,
l_int32  n 
)

runlengthMembershipOnLine()

Input: buffer (into which full line of data is placed) size (full size of line; w or h) depth (8 or 16 bpp) start (array of start positions for fg runs) end (array of end positions for fg runs) n (the number of runs) Return: 0 if OK; 1 on error

Notes: (1) Converts a set of runlengths into a buffer of runlength membership values. (2) Initialization of the array gives pixels that are not within a run the value 0.