DIPlib Documentation - ©1995-2015 Quantitative Imaging Group, Delft University of Technology.

# Watershed

Morphological segmentation

## SYNOPSIS

`#include "dip_morphology.h"`

dip_Error dip_Watershed ( in, mask, out, connectivity, max_depth, max_size, binaryOutput )

## DATA TYPES

integer, float

## FUNCTION

Watershed segmentation with built-in region merging. `max_depth` and `max_size` control the merging procedure. Any region with `max_size` or less pixels and with `max_depth` grey-value difference or less will be merged to neighbouring regions when they touch (as opposed to build a watershed). `max_size` equal to 0 means that the size of the region is not tested when merging. The regions are grown according to the `connectivity` parameter. See The connectivity parameter for more information. The output is either a labelled image where the pixels belonging to a catchment basin are labelled, or a binary image where the watershed pixels are 1 and the rest is 0. This is controlled by `binaryOutput`.

If `mask` is not 0, only the pixels within `mask` will be considered. All the other pixels will be marked as watershed pixels.

## ARGUMENTS

Data type | Name | Description
`dip_Image` | `in` | Input
`dip_Image` | `mask` | Mask
`dip_Image` | `out` | Output
`dip_int` | `connectivity` | Connectivity
`dip_float` | `max_depth` | Maximum depth of a region that can be merged
`dip_int` | `max_size` | Maximum size of a region that can be merged
`dip_Boolean` | `binaryOutput` | `DIP_FALSE` if the output should be a labelled image

## SEE ALSO

`SeededWatershed`, `UpperEnvelope`, `LocalMinima`, `GrowRegions`