Leptonica 1.68
C Image Processing Library

runlength.c File Reference

Run-length-encoding, horizontal and vertical run membership. More...

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

Go to the source code of this file.

Functions

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)

Detailed Description

Run-length-encoding, horizontal and vertical run membership.

   Label pixels by membership in runs
         PIX        *pixRunlengthTransform()

   Find runs along horizontal and vertical lines
         l_int32     pixFindHorizontalRuns()
         l_int32     pixFindVerticalRuns()

   Compute runlength-to-membership transform on a line
         l_int32     runlengthMembershipOnLine()

   Make byte position LUT
         l_int32     makeMSBitLocTab()

Definition in file runlength.c.


Function Documentation

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

Definition at line 63 of file runlength.c.

References CALLOC, ERROR_PTR, FREE, L_HORIZONTAL_RUNS, L_MAX, L_VERTICAL_RUNS, maxsize, NULL, pixClone(), pixCreate(), pixDestroy(), pixFindHorizontalRuns(), pixFindVerticalRuns(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixInvert(), PROCNAME, runlengthMembershipOnLine(), SET_DATA_BYTE, and SET_DATA_TWO_BYTES.

Referenced by main().

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.

Definition at line 170 of file runlength.c.

References ERROR_INT, FALSE, GET_DATA_BIT, L_RegParams::index, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, and TRUE.

Referenced by pixRunlengthTransform().

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.

Definition at line 246 of file runlength.c.

References ERROR_INT, FALSE, GET_DATA_BIT, L_RegParams::index, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, and TRUE.

Referenced by pixRunlengthTransform().

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.

Definition at line 325 of file runlength.c.

References ERROR_INT, L_MIN, and PROCNAME.

Referenced by pixRunlengthTransform().

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.

Definition at line 381 of file runlength.c.

References CALLOC, ERROR_PTR, NULL, and PROCNAME.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines