Leptonica  1.82.0
Image processing and image analysis suite
strokes.c File Reference
#include "allheaders.h"

Go to the source code of this file.

Functions

l_ok pixFindStrokeLength (PIX *pixs, l_int32 *tab8, l_int32 *plength)
 
l_ok pixFindStrokeWidth (PIX *pixs, l_float32 thresh, l_int32 *tab8, l_float32 *pwidth, NUMA **pnahisto)
 
NUMApixaFindStrokeWidth (PIXA *pixa, l_float32 thresh, l_int32 *tab8, l_int32 debug)
 
PIXApixaModifyStrokeWidth (PIXA *pixas, l_float32 targetw)
 
PIXpixModifyStrokeWidth (PIX *pixs, l_float32 width, l_float32 targetw)
 
PIXApixaSetStrokeWidth (PIXA *pixas, l_int32 width, l_int32 thinfirst, l_int32 connectivity)
 
PIXpixSetStrokeWidth (PIX *pixs, l_int32 width, l_int32 thinfirst, l_int32 connectivity)
 

Detailed Description

     Operations on 1 bpp images to:
     (1) measure stroke parameters, such as length and average width
     (2) change the average stroke width to a given value by eroding
         or dilating the image.
     These operations are intended to operate on a single text
     character, to regularize the stroke width. It is expected
     that character matching by correlation, as used in the recog
     application, can often be improved by pre-processing both
     template and character images to a fixed stroke width.
     Stroke parameter measurement
           l_int32      pixFindStrokeLength()
           l_int32      pixFindStrokeWidth()
           NUMA        *pixaFindStrokeWidth()
     Stroke width regulation
           PIXA        *pixaModifyStrokeWidth()
           PIX         *pixModifyStrokeWidth()
           PIXA        *pixaSetStrokeWidth()
           PIX         *pixSetStrokeWidth()

Definition in file strokes.c.

Function Documentation

◆ pixaFindStrokeWidth()

NUMA* pixaFindStrokeWidth ( PIXA pixa,
l_float32  thresh,
l_int32 *  tab8,
l_int32  debug 
)

pixaFindStrokeWidth()

Parameters
[in]pixaof 1 bpp images
[in]threshfractional count threshold relative to distance 1
[in]tab8[optional] table for counting fg pixels; can be NULL
[in]debug1 for debug output; 0 to skip
Returns
na array of stroke widths for each pix in pixa; NULL on error
Notes:
     (1) See pixFindStrokeWidth() for details.

Definition at line 212 of file strokes.c.

References L_CLONE, makePixelSumTab8(), L_StrCode::n, numaAddNumber(), numaCreate(), pixaGetCount(), pixaGetPix(), pixaVerifyDepth(), pixDestroy(), and pixFindStrokeWidth().

Referenced by pixaModifyStrokeWidth().

◆ pixaModifyStrokeWidth()

PIXA* pixaModifyStrokeWidth ( PIXA pixas,
l_float32  targetw 
)

pixaModifyStrokeWidth()

Parameters
[in]pixasof 1 bpp pix
[out]targetwdesired width for strokes in each pix
Returns
pixa with modified stroke widths, or NULL on error

Definition at line 258 of file strokes.c.

References L_CLONE, L_INSERT, L_StrCode::n, numaDestroy(), numaGetFValue(), pixaAddPix(), pixaCreate(), pixaFindStrokeWidth(), pixaGetCount(), pixaGetPix(), pixaVerifyDepth(), pixDestroy(), and pixModifyStrokeWidth().

◆ pixaSetStrokeWidth()

PIXA* pixaSetStrokeWidth ( PIXA pixas,
l_int32  width,
l_int32  thinfirst,
l_int32  connectivity 
)

pixaSetStrokeWidth()

Parameters
[in]pixasof 1 bpp pix
[in]widthset stroke width to this value, in [1 ... 100].
[in]thinfirst1 to thin all pix to a skeleton first; 0 to skip
[in]connectivity4 or 8, to be used if thinfirst == 1
Returns
pixa with all stroke widths being width, or NULL on error
Notes:
     (1) If thinfirst == 1, thin to a skeleton using the specified
         connectivity.  Use thinfirst == 0 if all pix in pixas
         have already been thinned as far as possible.
     (2) The image is dilated to the required width.  This dilation
         is not connectivity preserving, so this is typically
         used in a situation where merging of c.c. in the individual
         pix is not a problem; e.g., where each pix is a single c.c.

Definition at line 349 of file strokes.c.

References L_CLONE, L_INSERT, L_StrCode::n, pixaAddPix(), pixaCreate(), pixaGetCount(), pixaGetPix(), pixaVerifyDepth(), pixDestroy(), and pixSetStrokeWidth().

Referenced by recogTrainFromBoot().

◆ pixFindStrokeLength()

l_ok pixFindStrokeLength ( PIX pixs,
l_int32 *  tab8,
l_int32 *  plength 
)

pixFindStrokeLength()

Parameters
[in]pixs1 bpp
[in]tab8[optional] table for counting fg pixels; can be NULL
[out]plengthestimated length of the strokes
Returns
0 if OK, 1 on error
Notes:
     (1) Returns half the number of fg boundary pixels.

Definition at line 79 of file strokes.c.

References makePixelSumTab8(), L_StrCode::n, pixCountPixels(), pixDestroy(), and pixExtractBoundary().

Referenced by pixFindStrokeWidth().

◆ pixFindStrokeWidth()

l_ok pixFindStrokeWidth ( PIX pixs,
l_float32  thresh,
l_int32 *  tab8,
l_float32 *  pwidth,
NUMA **  pnahisto 
)

pixFindStrokeWidth()

Parameters
[in]pixs1 bpp
[in]threshfractional count threshold relative to distance 1
[in]tab8[optional] table for counting fg pixels; can be NULL
[out]pwidthestimated width of the strokes
[out]pnahisto[optional] histo of pixel distances from bg
Returns
0 if OK, 1 on error
Notes:
     (1) This uses two methods to estimate the stroke width:
         (a) half the fg boundary length
         (b) a value derived from the histogram of the fg distance transform
     (2) Distance is measured in 8-connected
     (3) thresh is the minimum fraction N(dist=d)/N(dist=1) of pixels
         required to determine if the pixels at distance d are above
         the noise. It is typically about 0.15.

Definition at line 127 of file strokes.c.

References makePixelSumTab8(), L_StrCode::n, pixCountPixels(), pixDistanceFunction(), and pixFindStrokeLength().

Referenced by pixaFindStrokeWidth().

◆ pixModifyStrokeWidth()

PIX* pixModifyStrokeWidth ( PIX pixs,
l_float32  width,
l_float32  targetw 
)

pixModifyStrokeWidth()

Parameters
[in]pixsof 1 bpp pix
[in]widthmeasured average stroke width
[in]targetwdesired stroke width
Returns
pix with modified stroke width, or NULL on error

Definition at line 302 of file strokes.c.

Referenced by pixaModifyStrokeWidth().

◆ pixSetStrokeWidth()

PIX* pixSetStrokeWidth ( PIX pixs,
l_int32  width,
l_int32  thinfirst,
l_int32  connectivity 
)

pixSetStrokeWidth()

Parameters
[in]pixs1 bpp
[in]widthset stroke width to this value, in [1 ... 100].
[in]thinfirst1 to thin all pix to a skeleton first; 0 to skip
[in]connectivity4 or 8, to be used if thinfirst == 1
Returns
pixd with stroke width set to width, or NULL on error
Notes:
     (1) See notes in pixaSetStrokeWidth().
     (2) A white border of sufficient width to avoid boundary
         artifacts in the thickening step is added before thinning.
     (3) connectivity == 8 usually gives a slightly smoother result.

Definition at line 401 of file strokes.c.

Referenced by pixaSetStrokeWidth(), and recogModifyTemplate().