Description

Applies the watershed separation filter to an image AOI and returns an 8-bit separation mask.

Return Type

A McImage object.  

A new 8-bit monochrome McImage holding a separation mask.

Syntax

object.Watershed ([mode], [Erosions], [Flags], [vSourceImg])

The Watershed Method syntax has these parts:

PartDescription
objectAn expression evaluating to an object of type McMorpho.
modeOptional. A mcNeighborMode enumeration, as described in settings.

An mcNeighborMode value indicating which neighboring cells to include in computing the distance map. If not given, the default is mcnm16Neighbor, which produces a Euclidian distance map.

ErosionsOptional. A Long value.

If positive, the algorithm only does this many erosions during the separation process. This is equivalent to “pre-flooding” the watershed to within that many pixels of boundaries. If negative or not given, the full distance map is used for the watershed segmentation step. This property is useful for speeding up the filter by limiting the number of passes across the image, but it is not useful for getting rid of noisy boundaries; use the PrefloodLevel property for that. Values of Erosions that are too low (e.g., less than 20) will often result in failure to separate blobs of interest.

FlagsOptional. A mcImageCreateFlags enumeration, as described in settings.

A combination of mcImageCreateFlags used in creation of the output image. If not given, the default is to make the image visible and part of the Images collection.

vSourceImgOptional. A Variant value.

Optional input IMcImage. If not given, the McMorpho operator's parent image is used.

Settings

The settings for mode are:

ConstantValueDescription
 mcnm4Neighbor2

4 pixels Connectivity.

 mcnm8Neighbor0

8 pixels Connectivity.

 mcnm16Neighbor4

16 pixels Connectivity (using Euclidian distance maps to provide a more accurate reduction than binaray morphology).

The settings for Flags are:

ConstantValueDescription
 mcicfDefault0
 mcicfContiguous1

If set, frames are allocated contiguously, and you cannot add to the FrameCount at a later time.

 mcicfNoInit2

Default is to initialize to 0 (black), this flag suppresses initialization.

 mcicfNoAddToCollection4

If set, the image is created, but not added to the collection (see Notes).

 mcicfNotVisible8

If set, the image is created, possibly added to collection (see above), but not made visible.

 mcipfNoImportProperties8388608

Suppress ImportProperties for functions creating an image from another.

Remarks

This method uses the value of the Threshold property to binarize the luminance of the source image, and then creates a new image 8-bit binary image suitable as a mask for separating the binarized blobs (see Example).

The PrefloodLevel property value is used to dermine how much preflooding of the distance map is done to eliminate the effect of small boundary irregularities in determining local maxima in the distance map. The PrefloodLevel value essentially determines how large a boundary “bubble” needs to be before it is considered a separate object. The default value of 1 is suitable for most images; values of zero or greater than 3 are rarely useful.

The Reduce method will create an image showing the preflooded local maxima that are used as the seed points for the watershed separation flooding step when the Erosions argument is negative (the default, unlimited distance map).

The algorithm proceeds as follows:

1) pixels within the bounds of the AOI of the source image are binarized by taking as foreground pixels at Threshold percent above McImage.RangeMin to McImage.RangeMax.

2) The inverse of a distance map is taken of these foreground pixels, creating “valleys” of foreground pixels (if the Erosions argument is positive, then the “depth” of these valleys is limited to the given value).

3) A watershed segmentation is performed on this inverted distance map. Pre-flooding of these “valleys” to the PrefloodLevel is done to eliminate small “puddles” and “moats”. Then “flooding” of the remaining valleys is done until all pre-flooded “watersheds” rejoin. The pixels at the boundaries of the joined watersheds are set to black.

4) The result is an 8-bit image with 255 for every foreground pixel in the original binarized image, except for those between separated blobs. All background and separating pixels are zero in the result image.

The distance map used for the separation is based on reflected pixel values at AOI boundaries. This often results in peak distances being detected at the AOI boundary for foreground blobs that intersect those boundaries.

Exceptions

The exception mceINVALIDARG (E_INVALIDARG) will be thrown if one of the parameters is invalid.