Herror ::watersheds (
    Hobject GrayImage,
    Hobject *Basins,
    Hobject *Watersheds
)
HRegionArray HImage::Watersheds (
    HRegion *Watersheds
) const
HRegionArray HImageArray::Watersheds (
    HRegionArray *Watersheds
) const

Extract watersheds and basins from an image.

::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 least one pixel wide (points on the ridge which form a plateau). 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., ::gauss_image) to the input image before calling ::watersheds in order to reduce the number of output regions.


Attention

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


Parameters

GrayImage (input_object)
image(-array) -> Hobject: HImage(Array) ( byte )
Images to be segmented.

Basins (output_object)
region-array -> Hobject * : HRegionArray
Segments found (dark basins).

Watersheds (output_object)
region(-array) -> Hobject * : HRegion(Array)
Watersheds between the basins.


Example
#include  <iostream.h>
#include  "HalconCpp.h"

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

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

  cout << "Invert of Gauss " << endl;
  invert = gauss.InvertImage ();
  invert.Display (win);

  HRegion        watersheds;
  HRegionArray   bassins = invert.Watersheds (&watersheds);

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

  return (0);
}

Result

::watersheds always returns 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.


Possible Predecessors

::gauss_image, ::smooth_image, ::invert_image


Possible Successors

::expand_region, ::select_shape, ::reduce_domain, ::opening


Alternatives

::pouring


Module

Region processing



Copyright © 1996-2002 MVTec Software GmbH