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

Go to the source code of this file.

Functions

PIXApixaThinConnected (PIXA *pixas, l_int32 type, l_int32 connectivity, l_int32 maxiters)
 
PIXpixThinConnected (PIX *pixs, l_int32 type, l_int32 connectivity, l_int32 maxiters)
 
PIXpixThinConnectedBySet (PIX *pixs, l_int32 type, SELA *sela, l_int32 maxiters)
 
SELAselaMakeThinSets (l_int32 index, l_int32 debug)
 

Detailed Description


    PIXA   *pixaThinConnected()
    PIX    *pixThinConnected()
    PIX    *pixThinConnectedBySet()
    SELA   *selaMakeThinSets()

Definition in file ccthin.c.

Function Documentation

◆ pixaThinConnected()

PIXA* pixaThinConnected ( PIXA pixas,
l_int32  type,
l_int32  connectivity,
l_int32  maxiters 
)

pixaThinConnected()

Parameters
[in]pixasof 1 bpp pix
[in]typeL_THIN_FG, L_THIN_BG
[in]connectivity4 or 8
[in]maxitersmax number of iters allowed; use 0 to iterate until completion
Returns
pixds, or NULL on error
Notes:
     (1) See notes in pixThinConnected().

Definition at line 72 of file ccthin.c.

References L_CLONE, L_INSERT, L_THIN_BG, L_THIN_FG, pixaAddPix(), pixaCreate(), pixaGetCount(), pixaGetPix(), pixaVerifyDepth(), pixDestroy(), pixThinConnectedBySet(), selaDestroy(), and selaMakeThinSets().

◆ pixThinConnected()

PIX* pixThinConnected ( PIX pixs,
l_int32  type,
l_int32  connectivity,
l_int32  maxiters 
)

pixThinConnected()

Parameters
[in]pixs1 bpp
[in]typeL_THIN_FG, L_THIN_BG
[in]connectivity4 or 8
[in]maxitersmax number of iters allowed; use 0 to iterate until completion
Returns
pixd, or NULL on error
Notes:
     (1) See "Connectivity-preserving morphological image transformations,"
         Dan S. Bloomberg, in SPIE Visual Communications and Image
         Processing, Conference 1606, pp. 320-334, November 1991,
         Boston, MA.   A web version is available at
             http://www.leptonica.com/papers/conn.pdf
     (2) This is a simple interface for two of the best iterative
         morphological thinning algorithms, for 4-c.c and 8-c.c.
         Each iteration uses a mixture of parallel operations
         (using several different 3x3 Sels) and serial operations.
         Specifically, each thinning iteration consists of
         four sequential thinnings from each of four directions.
         Each of these thinnings is a parallel composite
         operation, where the union of a set of HMTs are set
         subtracted from the input.  For 4-cc thinning, we
         use 3 HMTs in parallel, and for 8-cc thinning we use 4 HMTs.
     (3) A "good" thinning algorithm is one that generates a skeleton
         that is near the medial axis and has neither pruned
         real branches nor left extra dendritic branches.
     (4) Duality between operations on fg and bg require switching
         the connectivity.  To thin the foreground, which is the usual
         situation, use type == L_THIN_FG.  Thickening the foreground
         is equivalent to thinning the background (type == L_THIN_BG),
         where the alternate connectivity gets preserved.
         For example, to thicken the fg with 2 rounds of iterations
         using 4-c.c., thin the bg using Sels that preserve 8-connectivity:
            Pix *pix = pixThinConnected(pixs, L_THIN_BG, 8, 2);
     (5) This makes and destroys the sela set each time. It's not a large
         overhead, but if you are calling this thousands of times on
         very small images, you can avoid the overhead; e.g.
            Sela *sela = selaMakeThinSets(1, 0);  // for 4-c.c.
            Pix *pix = pixThinConnectedBySet(pixs, L_THIN_FG, sela, 0);
         using set 1 for 4-c.c. and set 5 for 8-c.c operations.

Definition at line 162 of file ccthin.c.

◆ pixThinConnectedBySet()

PIX* pixThinConnectedBySet ( PIX pixs,
l_int32  type,
SELA sela,
l_int32  maxiters 
)

pixThinConnectedBySet()

Parameters
[in]pixs1 bpp
[in]typeL_THIN_FG, L_THIN_BG
[in]selaof Sels for parallel composite HMTs
[in]maxitersmax number of iters allowed; use 0 to iterate until completion
Returns
pixd, or NULL on error
Notes:
     (1) See notes in pixThinConnected().
     (2) This takes a sela representing one of 11 sets of HMT Sels.
         The HMTs from this set are run in parallel and the result
         is OR'd before being subtracted from the source.  For each
         iteration, this "parallel" thin is performed four times
         sequentially, for sels rotated by 90 degrees in all four
         directions.
     (3) The "parallel" and "sequential" nomenclature is standard
         in digital filtering.  Here, "parallel" operations work on the
         same source (pixd), and accumulate the results in a temp
         image before actually applying them to the source (in this
         case, using an in-place subtraction).  "Sequential" operations
         operate directly on the source (pixd) to produce the result
         (in this case, with four sequential thinning operations, one
         from each of four directions).

Definition at line 224 of file ccthin.c.

Referenced by pixaThinConnected().

◆ selaMakeThinSets()

SELA* selaMakeThinSets ( l_int32  index,
l_int32  debug 
)

selaMakeThinSets()

Parameters
[in]indexinto specific sets
[in]debug1 to output display of sela
Returns
sela, or NULL on error
Notes:
     (1) These are specific sets of HMTs to be used in parallel for
         for thinning from each of four directions.
     (2) The sets are indexed as follows:
         For thinning (e.g., run to completion):
             index = 1     sel_4_1, sel_4_2, sel_4_3
             index = 2     sel_4_1, sel_4_5, sel_4_6
             index = 3     sel_4_1, sel_4_7, sel_4_7_rot
             index = 4     sel_48_1, sel_48_1_rot, sel_48_2
             index = 5     sel_8_2, sel_8_3, sel_8_5, sel_8_6
             index = 6     sel_8_2, sel_8_3, sel_48_2
             index = 7     sel_8_1, sel_8_5, sel_8_6
             index = 8     sel_8_2, sel_8_3, sel_8_8, sel_8_9
             index = 9     sel_8_5, sel_8_6, sel_8_7, sel_8_7_rot
         For thickening (e.g., just a few iterations):
             index = 10    sel_4_2, sel_4_3
             index = 11    sel_8_4
     (3) For a very smooth skeleton, use set 1 for 4 connected and
         set 5 for 8 connected thins.

Definition at line 345 of file ccthin.c.

References L_COPY, L_INSERT, lept_mkdir(), sela4and8ccThin(), sela4ccThin(), sela8ccThin(), selaAddSel(), selaCreate(), selaDestroy(), selaDisplayInPix(), selaFindSelByName(), and selRotateOrth().

Referenced by pixaThinConnected().