Leptonica 1.68
C Image Processing Library

ccthin.c File Reference

Connected-component-preserving thinning. More...

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

Go to the source code of this file.

Defines

#define DEBUG_SELS   0

Functions

PIXpixThin (PIX *pixs, l_int32 type, l_int32 connectivity, l_int32 maxiters)
PIXpixThinGeneral (PIX *pixs, l_int32 type, SELA *sela, l_int32 maxiters)
PIXpixThinExamples (PIX *pixs, l_int32 type, l_int32 index, l_int32 maxiters, const char *selfile)

Variables

static const char * sel_4_1 = " x"
static const char * sel_4_2 = " o "
static const char * sel_4_3 = " x"
static const char * sel_4_4 = " o "
static const char * sel_4_5 = " o "
static const char * sel_4_6 = " ox"
static const char * sel_4_7 = " o "
static const char * sel_4_8 = "o x"
static const char * sel_4_9 = " x"
static const char * sel_8_1 = " x "
static const char * sel_8_2 = "o "
static const char * sel_8_3 = " x "
static const char * sel_8_4 = "o "
static const char * sel_8_5 = "o "
static const char * sel_8_6 = "o x"
static const char * sel_8_7 = "oo "
static const char * sel_8_8 = "ox "
static const char * sel_8_9 = " x "
static const char * sel_48_1 = "oo "
static const char * sel_48_2 = "o x"

Detailed Description

Connected-component-preserving thinning.

Definition in file ccthin.c.


Define Documentation

#define DEBUG_SELS   0

Definition at line 121 of file ccthin.c.


Function Documentation

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

pixThin()

Input: pixs (1 bpp) type (L_THIN_FG, L_THIN_BG) connectivity (4 or 8) maxiters (max number of iters allowed; use 0 to iterate until completion) Return: 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) We implement here 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) 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 opposite connectivity gets preserved. For example, to thicken the fg using 4-connectivity, we thin the bg using Sels that preserve 8-connectivity.

Definition at line 165 of file ccthin.c.

References ERROR_PTR, L_THIN_BG, L_THIN_FG, NULL, pixGetDepth(), pixThinGeneral(), PROCNAME, sel_4_1, sel_4_2, sel_4_3, sel_8_2, sel_8_3, sel_8_5, sel_8_6, selaAddSel(), selaCreate(), selaDestroy(), and selCreateFromString().

Referenced by main().

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

pixThinGeneral()

Input: pixs (1 bpp) type (L_THIN_FG, L_THIN_BG) sela (of Sels for parallel composite HMTs) maxiters (max number of iters allowed; use 0 to iterate until completion) Return: pixd, or null on error

Notes: (1) See notes in pixThin(). That function chooses among the best of the Sels for thinning. (2) This is a general function that takes a Sela of HMTs that are used in parallel for thinning from each of four directions. One iteration consists of four such parallel thins.

Definition at line 231 of file ccthin.c.

References ERROR_PTR, L_INFO_INT, L_INSERT, L_THIN_BG, L_THIN_FG, NULL, pixaAddPix(), pixaCreate(), pixaDestroy(), pixaGetPixArray(), pixCopy(), pixCreateTemplate(), pixDestroy(), pixDisplayWithTitle(), pixEqual(), pixGetDepth(), pixHMT(), pixInvert(), pixOr(), pixSubtract(), PROCNAME, selaDisplayInPix(), selaGetCount(), selaGetSel(), selDestroy(), and selRotateOrth().

Referenced by pixThin(), and pixThinExamples().

PIX* pixThinExamples ( PIX pixs,
l_int32  type,
l_int32  index,
l_int32  maxiters,
const char *  selfile 
)

pixThinExamples()

Input: pixs (1 bpp) type (L_THIN_FG, L_THIN_BG) index (into specific examples; valid 1-9; see notes) maxiters (max number of iters allowed; use 0 to iterate until completion) selfile (<optional> filename for output sel display) Return: pixd, or null on error

Notes: (1) See notes in pixThin(). The examples are taken from the paper referenced there. (2) Here we allow specific sets of HMTs to be used in parallel for thinning from each of four directions. One iteration consists of four such parallel thins. (3) The examples are indexed as follows: Thinning (e.g., run to completion): index = 1 sel_4_1, sel_4_5, sel_4_6 index = 2 sel_4_1, sel_4_7, sel_4_7_rot index = 3 sel_48_1, sel_48_1_rot, sel_48_2 index = 4 sel_8_2, sel_8_3, sel_48_2 index = 5 sel_8_1, sel_8_5, sel_8_6 index = 6 sel_8_2, sel_8_3, sel_8_8, sel_8_9 index = 7 sel_8_5, sel_8_6, sel_8_7, sel_8_7_rot Thickening: index = 8 sel_4_2, sel_4_3 (e.g,, do just a few iterations) index = 9 sel_8_4 (e.g., do just a few iterations)

Definition at line 338 of file ccthin.c.

References ERROR_PTR, IFF_PNG, L_THIN_BG, L_THIN_FG, NULL, pixDestroy(), pixGetDepth(), pixRemoveBorderConnComps(), pixThinGeneral(), pixWrite(), PROCNAME, sel_48_1, sel_48_2, sel_4_1, sel_4_2, sel_4_3, sel_4_5, sel_4_6, sel_4_7, sel_8_1, sel_8_2, sel_8_3, sel_8_4, sel_8_5, sel_8_6, sel_8_7, sel_8_8, sel_8_9, selaAddSel(), selaCreate(), selaDestroy(), selaDisplayInPix(), selCreateFromString(), and selRotateOrth().

Referenced by main().


Variable Documentation

const char* sel_4_1 = " x" [static]

Definition at line 38 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_4_2 = " o " [static]

Definition at line 42 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_4_3 = " x" [static]

Definition at line 46 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_4_4 = " o " [static]

Definition at line 50 of file ccthin.c.

const char* sel_4_5 = " o " [static]

Definition at line 54 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_4_6 = " ox" [static]

Definition at line 58 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_4_7 = " o " [static]

Definition at line 62 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_4_8 = "o x" [static]

Definition at line 66 of file ccthin.c.

const char* sel_4_9 = " x" [static]

Definition at line 70 of file ccthin.c.

const char* sel_8_1 = " x " [static]

Definition at line 75 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_8_2 = "o " [static]

Definition at line 79 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_8_3 = " x " [static]

Definition at line 83 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_8_4 = "o " [static]

Definition at line 87 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_8_5 = "o " [static]

Definition at line 91 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_8_6 = "o x" [static]

Definition at line 95 of file ccthin.c.

Referenced by pixThin(), and pixThinExamples().

const char* sel_8_7 = "oo " [static]

Definition at line 99 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_8_8 = "ox " [static]

Definition at line 103 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_8_9 = " x " [static]

Definition at line 107 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_48_1 = "oo " [static]

Definition at line 112 of file ccthin.c.

Referenced by pixThinExamples().

const char* sel_48_2 = "o x" [static]

Definition at line 116 of file ccthin.c.

Referenced by pixThinExamples().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines