Файл src/watershed.c

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

Классы

struct  L_NewPixel
struct  L_WSPixel

Макросы

#define DEBUG_WATERSHED   0

Определения типов

typedef struct L_NewPixel L_NEWPIXEL
typedef struct L_WSPixel L_WSPIXEL

Функции

static void wshedSaveBasin (L_WSHED *wshed, l_int32 index, l_int32 level)
static l_int32 identifyWatershedBasin (L_WSHED *wshed, l_int32 index, l_int32 level, BOX **pbox, PIX **ppixd)
static l_int32 mergeLookup (L_WSHED *wshed, l_int32 sindex, l_int32 dindex)
static l_int32 wshedGetHeight (L_WSHED *wshed, l_int32 val, l_int32 label, l_int32 *pheight)
static void pushNewPixel (L_QUEUE *lq, l_int32 x, l_int32 y, l_int32 *pminx, l_int32 *pmaxx, l_int32 *pminy, l_int32 *pmaxy)
static void popNewPixel (L_QUEUE *lq, l_int32 *px, l_int32 *py)
static void pushWSPixel (L_HEAP *lh, L_STACK *stack, l_int32 val, l_int32 x, l_int32 y, l_int32 index)
static void popWSPixel (L_HEAP *lh, L_STACK *stack, l_int32 *pval, l_int32 *px, l_int32 *py, l_int32 *pindex)
static void debugPrintLUT (l_int32 *lut, l_int32 size, l_int32 debug)
static void debugWshedMerge (L_WSHED *wshed, char *descr, l_int32 x, l_int32 y, l_int32 label, l_int32 index)
L_WSHEDwshedCreate (PIX *pixs, PIX *pixm, l_int32 mindepth, l_int32 debugflag)
void wshedDestroy (L_WSHED **pwshed)
l_int32 wshedApply (L_WSHED *wshed)
l_int32 wshedBasins (L_WSHED *wshed, PIXA **ppixa, NUMA **pnalevels)
PIXwshedRenderFill (L_WSHED *wshed)
PIXwshedRenderColors (L_WSHED *wshed)

Переменные

static const l_uint32 MAX_LABEL_VALUE = 0x7fffffff

Макросы

#define DEBUG_WATERSHED   0


Типы

typedef struct L_NewPixel L_NEWPIXEL

typedef struct L_WSPixel L_WSPIXEL


Функции

static void debugPrintLUT ( l_int32 lut,
l_int32  size,
l_int32  debug 
) [static]

static void debugWshedMerge ( L_WSHED wshed,
char *  descr,
l_int32  x,
l_int32  y,
l_int32  label,
l_int32  index 
) [static]

static l_int32 identifyWatershedBasin ( L_WSHED wshed,
l_int32  index,
l_int32  level,
BOX **  pbox,
PIX **  ppixd 
) [static]

identifyWatershedBasin()

Input: wshed index (index of basin to be located) level (of basin at point at which the two basins met) &box (<return> bounding box of basin) &pixd (<return> pix of basin, cropped to its bounding box) Return: 0 if OK, 1 on error

Notes: (1) This is a static function, so we assume pixlab, pixs and pixt exist and are the same size. (2) It selects all pixels that have the label in pixlab and that have a value in pixs that is less than . (3) It is used whenever two seeded basins meet (typically at a saddle), or when one seeded basin meets a 'filler'. All identified basins are saved as a watershed.

static l_int32 mergeLookup ( L_WSHED wshed,
l_int32  sindex,
l_int32  dindex 
) [static]

mergeLookup()

Input: wshed sindex (primary index being changed in the merge) dindex (index that will point to after the merge) Return: 0 if OK, 1 on error

Notes: (1) The links are a sparse array of Numas showing current back-links. The lut gives the current index (of the seed or the minima for the wshed in which it is located. (2) Think of each entry in the lut. There are two types: owner: lut[index] = index redirect: lut[index] != index (3) This is called each time a merge occurs. It puts the lut and backlinks in a canonical form after the merge, where all entries in the lut point to the current "owner", which has all backlinks. That is, every "redirect" in the lut points to an "owner". The lut always gives the index of the current owner.

static void popNewPixel ( L_QUEUE lq,
l_int32 px,
l_int32 py 
) [static]

static void popWSPixel ( L_HEAP lh,
L_STACK stack,
l_int32 pval,
l_int32 px,
l_int32 py,
l_int32 pindex 
) [static]

static void pushNewPixel ( L_QUEUE lq,
l_int32  x,
l_int32  y,
l_int32 pminx,
l_int32 pmaxx,
l_int32 pminy,
l_int32 pmaxy 
) [static]

static void pushWSPixel ( L_HEAP lh,
L_STACK stack,
l_int32  val,
l_int32  x,
l_int32  y,
l_int32  index 
) [static]

l_int32 wshedApply ( L_WSHED wshed  ) 

wshedApply()

Input: wshed (generated from wshedCreate()) Return: 0 if OK, 1 on error

Iportant note: (1) This is buggy. It seems to locate watersheds that are duplicates. The watershed extraction after complete fill grabs some regions belonging to existing watersheds. See prog/watershedtest.c for testing.

l_int32 wshedBasins ( L_WSHED wshed,
PIXA **  ppixa,
NUMA **  pnalevels 
)

wshedBasins()

Input: wshed &pixa (<optional return>=""> mask of watershed basins) &nalevels (<optional return>=""> watershed levels) Return: 0 if OK, 1 on error

L_WSHED* wshedCreate ( PIX pixs,
PIX pixm,
l_int32  mindepth,
l_int32  debugflag 
)

wshedCreate()

Input: pixs (8 bpp source) pixm (1 bpp 'marker' seed) mindepth (minimum depth; anything less is not saved) debugflag (1 for debug output) Return: WShed, or null on error

Notes: (1) It is not necessary for the fg pixels in the seed image be at minima, or that they be isolated. We extract a single pixel from each connected component, and a seed anywhere in a watershed will eventually label the watershed when the filling level reaches it. (2) Set mindepth to some value to ignore noise in pixs that can create small local minima. Any watershed shallower than mindepth, even if it has a seed, will not be saved; It will either be incorporated in another watershed or eliminated.

void wshedDestroy ( L_WSHED **  pwshed  ) 

wshedDestroy()

Input: &wshed (<will be="" set="" to="" null="" before="" returning>="">) Return: void

static l_int32 wshedGetHeight ( L_WSHED wshed,
l_int32  val,
l_int32  label,
l_int32 pheight 
) [static]

wshedGetHeight()

Input: wshed (array of current indices) val (value of current pixel popped off queue) label (of pixel or 32 bpp label image) &height (<return> height of current value from seed or minimum of watershed) Return: 0 if OK, 1 on error

Notes: (1) It is only necessary to find the height for a watershed that is indexed by a seed or a minima. This function should not be called on a finished watershed (that continues to fill).

PIX* wshedRenderColors ( L_WSHED wshed  ) 

wshedRenderColors()

Input: wshed Return: pixd (initial image with all basins filled), or null on error

PIX* wshedRenderFill ( L_WSHED wshed  ) 

wshedRenderFill()

Input: wshed Return: pixd (initial image with all basins filled), or null on error

static void wshedSaveBasin ( L_WSHED wshed,
l_int32  index,
l_int32  level 
) [static]

wshedSaveBasin()

Input: wshed index (index of basin to be located) level (filling level reached at the time this function is called) Return: 0 if OK, 1 on error

Notes: (1) This identifies a single watershed. It does not change the LUT, which must be done subsequently. (2) The fill level of a basin is taken to be - 1.


Переменные

const l_uint32 MAX_LABEL_VALUE = 0x7fffffff [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9