HALCON Reference Manual / Segmentation / Topography Operators

watersheds (Operator)

Name

watersheds — Extract watersheds and basins from an image.

Synopsis

watersheds(Image : Basins, Watersheds : : )

Description

watersheds segments an image based on the topology of the gray values. The image is interpreted as a “mountain range.” Higher gray values correspond to “mountains,” while lower gray values correspond to “valleys.” In the resulting mountain range watersheds are extracted. These correspond to the bright ridges between dark basins. On output, the parameter Basins contains these basins, while Watersheds contains the watersheds, which are at most one pixel wide. Watersheds always is a single region per input image, while Basins contains a separate region for each basin.

It is advisable to apply a smoothing operator (e.g., binomial_filter or gauss_image) to the input image before calling watersheds in order to reduce the number of output regions. A more sophisticated way to reduce the number of output regions is to merge neighboring basins based on a threshold criterion by using watersheds_threshold instead (for more details please refer to the documentation of watersheds_threshold).

Attention

If the image contains many fine structures or is noisy, many output regions result, and thus the runtime increases considerably.

Parameters

Image (input_object) image(-array) object (byte / uint2 / real)
Input image.

Basins (output_object) region-array object
Segmented basins.

Watersheds (output_object) region(-array) object
Watersheds between the basins.

Example (Syntax: C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;

int main (int argc, char *argv[])
{
  HImage   image (argv[1]), gauss;
  HWindow  win;

  cout << "Gauss of original " << endl;
  gauss  = image.GaussImage (9);
  image.Display (win);

  HRegion        watersheds;
  HRegionArray   basins = gauss.Watersheds (&watersheds);

  win.SetColored (12);
  basins.Display (win);
  win.Click ();

  return (0);
}

Result

watersheds always returns 2 (H_MSG_TRUE). The behavior with respect to the input images and output regions can be determined by setting the values of the flags 'no_object_result', 'empty_region_result', and 'store_empty_region' with set_system. If necessary, an exception is raised.

Parallelization Information

watersheds is reentrant and automatically parallelized (on tuple level).

Possible Predecessors

binomial_filter, gauss_image, smooth_image, invert_image

Possible Successors

expand_region, select_shape, reduce_domain, opening

Alternatives

watersheds_threshold, pouring

References

L. Vincent, P. Soille: “Watersheds in Digital Space: An Efficient Algorithm Based on Immersion Simulations”; IEEE Transactions on Pattern Analysis and Machine Intelligence; vol. 13, no. 6; pp. 583-598; 1991.

Module

Foundation


HALCON Reference Manual / Segmentation / Topography Operators
Version 9.0.2 Copyright © 1996-2010 MVTec Software GmbH