Leptonica  1.82.0
Image processing and image analysis suite
runlength.c File Reference
#include <string.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static PIXpixFindMinRunsOrthogonal (PIX *pixs, l_float32 angle, l_int32 depth)
 
PIXpixStrokeWidthTransform (PIX *pixs, l_int32 color, l_int32 depth, l_int32 nangles)
 
PIXpixRunlengthTransform (PIX *pixs, l_int32 color, l_int32 direction, l_int32 depth)
 
l_ok pixFindHorizontalRuns (PIX *pix, l_int32 y, l_int32 *xstart, l_int32 *xend, l_int32 *pn)
 
l_ok pixFindVerticalRuns (PIX *pix, l_int32 x, l_int32 *ystart, l_int32 *yend, l_int32 *pn)
 
NUMApixFindMaxRuns (PIX *pix, l_int32 direction, NUMA **pnastart)
 
l_ok pixFindMaxHorizontalRunOnLine (PIX *pix, l_int32 y, l_int32 *pxstart, l_int32 *psize)
 
l_ok pixFindMaxVerticalRunOnLine (PIX *pix, l_int32 x, l_int32 *pystart, l_int32 *psize)
 
l_ok runlengthMembershipOnLine (l_int32 *buffer, l_int32 size, l_int32 depth, l_int32 *start, l_int32 *end, l_int32 n)
 
l_int32 * makeMSBitLocTab (l_int32 bitval)
 

Detailed Description


    Label pixels by membership in runs
          PIX         *pixStrokeWidthTransform()
          static PIX  *pixFindMinRunsOrthogonal()
          PIX         *pixRunlengthTransform()

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

    Find max runs along horizontal and vertical lines
          l_int32      pixFindMaxRuns()
          l_int32      pixFindMaxHorizontalRunOnLine()
          l_int32      pixFindMaxVerticalRunOnLine()

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

    Make byte position LUT
          l_int32      makeMSBitLocTab()

 Here we're handling runs of either black or white pixels on 1 bpp
 images.  The directions of the runs in the stroke width transform
 are selectable from given sets of angles.  Most of the other runs
 are oriented either horizontally along the raster lines or
 vertically along pixel columns.

Definition in file runlength.c.

Function Documentation

◆ makeMSBitLocTab()

l_int32* makeMSBitLocTab ( l_int32  bitval)

makeMSBitLocTab()

Parameters
[in]bitvaleither 0 or 1
Returns
table: 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 792 of file runlength.c.

◆ pixFindHorizontalRuns()

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

pixFindHorizontalRuns()

Parameters
[in]pix1 bpp
[in]yline to traverse
[in]xstartreturns array of start positions for fg runs
[in]xendreturns array of end positions for fg runs
[out]pnthe number of runs found
Returns
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) 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 375 of file runlength.c.

References pixGetDimensions().

◆ pixFindMaxHorizontalRunOnLine()

l_ok pixFindMaxHorizontalRunOnLine ( PIX pix,
l_int32  y,
l_int32 *  pxstart,
l_int32 *  psize 
)

pixFindMaxHorizontalRunOnLine()

Parameters
[in]pix1 bpp
[in]yline to traverse
[out]pxstart[optional] start position
[out]psizethe size of the run
Returns
0 if OK; 1 on error
Notes:
     (1) This finds the longest foreground horizontal run on a scanline.
     (2) To find background runs, use pixInvert() before applying
         this function.

Definition at line 581 of file runlength.c.

◆ pixFindMaxRuns()

NUMA* pixFindMaxRuns ( PIX pix,
l_int32  direction,
NUMA **  pnastart 
)

pixFindMaxRuns()

Parameters
[in]pix1 bpp
[in]directionL_HORIZONTAL_RUNS or L_VERTICAL_RUNS
[out]pnastart[optional] start locations of longest runs
Returns
na of lengths of runs, or NULL on error
Notes:
     (1) This finds the longest foreground runs by row or column
     (2) To find background runs, use pixInvert() before applying
         this function.

Definition at line 528 of file runlength.c.

References L_HORIZONTAL_RUNS, and L_VERTICAL_RUNS.

◆ pixFindMaxVerticalRunOnLine()

l_ok pixFindMaxVerticalRunOnLine ( PIX pix,
l_int32  x,
l_int32 *  pystart,
l_int32 *  psize 
)

pixFindMaxVerticalRunOnLine()

Parameters
[in]pix1 bpp
[in]xcolumn to traverse
[out]pystart[optional] start position
[out]psizethe size of the run
Returns
0 if OK; 1 on error
Notes:
     (1) This finds the longest foreground vertical run on a scanline.
     (2) To find background runs, use pixInvert() before applying
         this function.

Definition at line 655 of file runlength.c.

◆ pixFindMinRunsOrthogonal()

static PIX * pixFindMinRunsOrthogonal ( PIX pixs,
l_float32  angle,
l_int32  depth 
)
static

pixFindMinRunsOrthogonal()

Parameters
[in]pixs1 bpp
[in]anglein radians
[in]depthof pixd: 8 or 16 bpp
Returns
pixd 8 or 16 bpp, or NULL on error
Notes:
     (1) This computes, for each fg pixel in pixs, the minimum of
         the runlengths going through that pixel in two orthogonal
         directions: at angle and at (90 + angle).
     (2) We use rotation by shear because the forward and backward
         rotations by the same angle are exact inverse operations.
         As a result, the nonzero pixels in pixd correspond exactly
         to the fg pixels in pixs.  This is not the case with
         sampled rotation, due to spatial quantization.  Nevertheless,
         the result suffers from lack of exact correspondence
         between original and rotated pixels, also due to spatial
         quantization, causing some boundary pixels to be
         shifted from bg to fg or v.v.

Definition at line 199 of file runlength.c.

◆ pixFindVerticalRuns()

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

pixFindVerticalRuns()

Parameters
[in]pix1 bpp
[in]xline to traverse
[in]ystartreturns array of start positions for fg runs
[in]yendreturns array of end positions for fg runs
[out]pnthe number of runs found
Returns
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) 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 452 of file runlength.c.

References pixGetDimensions().

◆ pixRunlengthTransform()

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

pixRunlengthTransform()

Parameters
[in]pixs1 bpp
[in]color0 for white runs, 1 for black runs
[in]directionL_HORIZONTAL_RUNS, L_VERTICAL_RUNS
[in]depth8 or 16 bpp
Returns
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) 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 265 of file runlength.c.

◆ pixStrokeWidthTransform()

PIX* pixStrokeWidthTransform ( PIX pixs,
l_int32  color,
l_int32  depth,
l_int32  nangles 
)

pixStrokeWidthTransform()

Parameters
[in]pixs1 bpp
[in]color0 for white runs, 1 for black runs
[in]depthof pixd: 8 or 16 bpp
[in]nangles2, 4, 6 or 8
Returns
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 stroke width in which it is a member.
         The values are clipped to the max pixel value if necessary.
     (2) color determines if we're labelling white or black strokes.
     (3) A pixel that is not a member of the chosen color gets
         value 0; it belongs to a width of length 0 of the
         chosen color.
     (4) This chooses, for each dest pixel, the minimum of sets
         of runlengths through each pixel.  Here are the sets:
           nangles    increment          set
           -------    ---------    --------------------------------
              2          90       {0, 90}
              4          45       {0, 45, 90, 135}
              6          30       {0, 30, 60, 90, 120, 150}
              8          22.5     {0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5}
     (5) Runtime scales linearly with (nangles - 2).

Definition at line 102 of file runlength.c.

◆ runlengthMembershipOnLine()

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

runlengthMembershipOnLine()

Parameters
[in]bufferinto which full line of data is placed
[in]sizefull size of line; w or h
[in]depth8 or 16 bpp
[in]startarray of start positions for fg runs
[in]endarray of end positions for fg runs
[in]nthe number of runs
Returns
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 736 of file runlength.c.