src/selgen.c
NUMA *
pixGetRunCentersOnLine(PIX     *pixs,
                       l_int32  x,
                       l_int32  y,
                       l_int32  minlength)
{
l_int32   w, h, i, r, nruns, len;
NUMA     *naruns, *nad;

    PROCNAME("pixGetRunCentersOnLine");

    if (!pixs)
        return (NUMA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (pixGetDepth(pixs) != 1)
        return (NUMA *)ERROR_PTR("pixs not 1 bpp", procName, NULL);
    if (x != -1 && y != -1)
        return (NUMA *)ERROR_PTR("x or y must be -1", procName, NULL);
    if (x == -1 && y == -1)
        return (NUMA *)ERROR_PTR("x or y cannot both be -1", procName, NULL);

    if ((nad = numaCreate(0)) == NULL)
        return (NUMA *)ERROR_PTR("nad not made", procName, NULL);
    w = pixGetWidth(pixs);
    h = pixGetHeight(pixs);
    if (x == -1) {  /* horizontal run */
        if (y < 0 || y >= h)
            return nad;
        naruns = pixGetRunsOnLine(pixs, 0, y, w - 1, y);
    }
    else {  /* vertical run */
        if (x < 0 || x >= w)
            return nad;
        naruns = pixGetRunsOnLine(pixs, x, 0, x, h - 1);
    }
    nruns = numaGetCount(naruns);

        /* extract run center values; the first run is always bg */
    r = 0;  /* cumulative distance along line */
    for (i = 0; i < nruns; i++) {
        if (i % 2 == 0) {  /* bg run */
            numaGetIValue(naruns, i, &len);
            r += len;
            continue;
        }
        else {
            numaGetIValue(naruns, i, &len);
            if (len >= minlength)
                numaAddNumber(nad, r + len / 2);
            r += len;
        }
    }

    numaDestroy(&naruns);
    return nad;
}
/*!
 *  pixGetRunCentersOnLine()
 *
 *      Input:  pixs (1 bpp)
 *              x, y (set one of these to -1; see notes)
 *              minlength (minimum length of acceptable run)
 *      Return: numa of fg runs, or null on error
 *
 *  Notes:
 *      (1) Action: this function computes the fg (black) and bg (white)
 *          pixel runlengths along the specified horizontal or vertical line,
 *          and returns a Numa of the "center" pixels of each fg run
 *          whose length equals or exceeds the minimum length.
 *      (2) This only works on horizontal and vertical lines.
 *      (3) For horizontal runs, set x = -1 and y to the value
 *          for all points along the raster line.  For vertical runs,
 *          set y = -1 and x to the value for all points along the
 *          pixel column.
 *      (4) For horizontal runs, the points in the Numa are the x
 *          values in the center of fg runs that are of length at
 *          least 'minlength'.  For vertical runs, the points in the
 *          Numa are the y values in the center of fg runs, again
 *          of length 'minlength' or greater.
 *      (5) If there are no fg runs along the line that satisfy the
 *          minlength constraint, the returned Numa is empty.  This
 *          is not an error.
 */
pixGetRunCentersOnLine()
Input:  pixs (1 bpp)
x, y (set one of these to -1; see notes)
minlength (minimum length of acceptable run)
Return: numa of fg runs, or null on error

(1) Action: this function computes the fg (black) and bg (white)
pixel runlengths along the specified horizontal or vertical line,
and returns a Numa of the "center" pixels of each fg run
whose length equals or exceeds the minimum length.
(2) This only works on horizontal and vertical lines.
(3) For horizontal runs, set x = -1 and y to the value
for all points along the raster line.  For vertical runs,
set y = -1 and x to the value for all points along the
pixel column.
(4) For horizontal runs, the points in the Numa are the x
values in the center of fg runs that are of length at
least 'minlength'.  For vertical runs, the points in the
Numa are the y values in the center of fg runs, again
of length 'minlength' or greater.
(5) If there are no fg runs along the line that satisfy the
minlength constraint, the returned Numa is empty.  This
is not an error.
pixGetRunCentersOnLine () Input : pixs ( 1 bpp ) x y ( set one of these to - 1 ; see notes ) minlength ( minimum length of acceptable run ) Return : numa of fg runs or null on error ( 1 ) Action : this function computes the fg ( black ) and bg ( white ) pixel runlengths along the specified horizontal or vertical line and returns a Numa of the " center " pixels of each fg run whose length equals or exceeds the minimum length . ( 2 ) This only works on horizontal and vertical lines . ( 3 ) For horizontal runs set x = - 1 and y to the value for all points along the raster line . For vertical runs set y = - 1 and x to the value for all points along the pixel column . ( 4 ) For horizontal runs the points in the Numa are the x values in the center of fg runs that are of length at least ' minlength ' . For vertical runs the points in the Numa are the y values in the center of fg runs again of length ' minlength ' or greater . ( 5 ) If there are no fg runs along the line that satisfy the minlength constraint the returned Numa is empty . This is not an error .
NUMA *
pixGetRunCentersOnLine(PIX     *pixs,
                       l_int32  x,
                       l_int32  y,
                       l_int32  minlength)
{
l_int32   w, h, i, r, nruns, len;
NUMA     *naruns, *nad;
    PROCNAME("pixGetRunCentersOnLine");
    if (!pixs)
        return (NUMA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (pixGetDepth(pixs) != 1)
        return (NUMA *)ERROR_PTR("pixs not 1 bpp", procName, NULL);
    if (x != -1 && y != -1)
        return (NUMA *)ERROR_PTR("x or y must be -1", procName, NULL);
    if (x == -1 && y == -1)
        return (NUMA *)ERROR_PTR("x or y cannot both be -1", procName, NULL);
    if ((nad = numaCreate(0)) == NULL)
        return (NUMA *)ERROR_PTR("nad not made", procName, NULL);
    w = pixGetWidth(pixs);
    h = pixGetHeight(pixs);
    if (x == -1) {  
        if (y < 0 || y >= h)
            return nad;
        naruns = pixGetRunsOnLine(pixs, 0, y, w - 1, y);
    }
    else {  
        if (x < 0 || x >= w)
            return nad;
        naruns = pixGetRunsOnLine(pixs, x, 0, x, h - 1);
    }
    nruns = numaGetCount(naruns);
    r = 0;  
    for (i = 0; i < nruns; i++) {
        if (i % 2 == 0) {  
            numaGetIValue(naruns, i, &len);
            r += len;
            continue;
        }
        else {
            numaGetIValue(naruns, i, &len);
            if (len >= minlength)
                numaAddNumber(nad, r + len / 2);
            r += len;
        }
    }
    numaDestroy(&naruns);
    return nad;
}
NUMA * pixGetRunCentersOnLine ( PIX * pixs , l_int32 x , l_int32 y , l_int32 minlength ) { l_int32 w , h , i , r , nruns , len ; NUMA * naruns , * nad ; PROCNAME ( " " ) ; if ( ! pixs ) return ( NUMA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( pixGetDepth ( pixs ) != 1 ) return ( NUMA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( x != -1 && y != -1 ) return ( NUMA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( x == -1 && y == -1 ) return ( NUMA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ( nad = numaCreate ( 0 ) ) == NULL ) return ( NUMA * ) ERROR_PTR ( " " , procName , NULL ) ; w = pixGetWidth ( pixs ) ; h = pixGetHeight ( pixs ) ; if ( x == -1 ) { if ( y < 0 || y >= h ) return nad ; naruns = pixGetRunsOnLine ( pixs , 0 , y , w - 1 , y ) ; } else { if ( x < 0 || x >= w ) return nad ; naruns = pixGetRunsOnLine ( pixs , x , 0 , x , h - 1 ) ; } nruns = numaGetCount ( naruns ) ; r = 0 ; for ( i = 0 ; i < nruns ; i ++ ) { if ( i % 2 == 0 ) { numaGetIValue ( naruns , i , & len ) ; r += len ; continue ; } else { numaGetIValue ( naruns , i , & len ) ; if ( len >= minlength ) numaAddNumber ( nad , r + len / 2 ) ; r += len ; } } numaDestroy ( & naruns ) ; return nad ; }
pixGetRunCentersOnLine()
      Input:  pixs (1 bpp)
              x, y (set one of these to -1; see notes)
              minlength (minimum length of acceptable run)
      Return: numa of fg runs, or null on error
pixGetRunCentersOnLine () Input : pixs ( 1 bpp ) x y ( set one of these to - 1 ; see notes ) minlength ( minimum length of acceptable run ) Return : numa of fg runs or null on error
/* horizontal run */ /* vertical run */ /* extract run center values; the first run is always bg */ /* cumulative distance along line */ /* bg run */