ClassesClassesClassesClasses | | | | Operators

watershedswatershedsWatershedswatershedsWatershedsWatersheds (Operator)

Name

watershedswatershedsWatershedswatershedsWatershedsWatersheds — Extract watersheds and basins from an image.

Signature

watersheds(Image : Basins, Watersheds : : )

Herror watersheds(const Hobject Image, Hobject* Basins, Hobject* Watersheds)

Herror T_watersheds(const Hobject Image, Hobject* Basins, Hobject* Watersheds)

Herror watersheds(Hobject Image, Hobject* Basins, Hobject* Watersheds)

HRegionArray HImage::Watersheds(HRegion* Watersheds) const

HRegionArray HImageArray::Watersheds(HRegionArray* Watersheds) const

void Watersheds(const HObject& Image, HObject* Basins, HObject* Watersheds)

HRegion HImage::Watersheds(HRegion* Watersheds) const

void HOperatorSetX.Watersheds(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*Basins, [out] IHUntypedObjectX*Watersheds)

IHRegionX* HImageX.Watersheds([out] IHRegionX*Watersheds)

static void HOperatorSet.Watersheds(HObject image, out HObject basins, out HObject watersheds)

HRegion HImage.Watersheds(out HRegion watersheds)

Description

watershedswatershedsWatershedswatershedsWatershedsWatersheds 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 BasinsBasinsBasinsBasinsBasinsbasins contains these basins, while WatershedsWatershedsWatershedsWatershedsWatershedswatersheds contains the watersheds, which are at most one pixel wide. WatershedsWatershedsWatershedsWatershedsWatershedswatersheds always is a single region per input image, while BasinsBasinsBasinsBasinsBasinsbasins contains a separate region for each basin.

It is advisable to apply a smoothing operator (e.g., binomial_filterbinomial_filterBinomialFilterbinomial_filterBinomialFilterBinomialFilter or gauss_imagegauss_imageGaussImagegauss_imageGaussImageGaussImage) to the input image before calling watershedswatershedsWatershedswatershedsWatershedsWatersheds 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_thresholdwatersheds_thresholdWatershedsThresholdwatersheds_thresholdWatershedsThresholdWatershedsThreshold instead (for more details please refer to the documentation of watersheds_thresholdwatersheds_thresholdWatershedsThresholdwatersheds_thresholdWatershedsThresholdWatershedsThreshold).

Attention

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

Parallelization

Parameters

ImageImageImageImageImageimage (input_object)  singlechannelimage(-array) objectHImageHImageHImageHImageXHobject (byte / uint2 / real)

Input image.

BasinsBasinsBasinsBasinsBasinsbasins (output_object)  region-array objectHRegionHRegionHRegionArrayHRegionXHobject *

Segmented basins.

WatershedsWatershedsWatershedsWatershedsWatershedswatersheds (output_object)  region(-array) objectHRegionHRegionHRegionHRegionXHobject *

Watersheds between the basins.

Example (C++ (HALCON 5.0-10.0))

#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);
}

Example (C)

read_image(&Cells,"meningg5");
gauss_image(Cells,&CellsGauss,9);
invert_image(CellsGauss,&CellsInvert);
watersheds(CellsInvert,&Bassins,&Watersheds);
set_colored(WindowHandle,12);
disp_region(Bassins,WindowHandle);

Example (C++ (HALCON 5.0-10.0))

#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);
}

Example (C++ (HALCON 5.0-10.0))

#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);
}

Example (C++ (HALCON 5.0-10.0))

#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);
}

Example (C++ (HALCON 5.0-10.0))

#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

watershedswatershedsWatershedswatershedsWatershedsWatersheds 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'"no_object_result""no_object_result""no_object_result""no_object_result""no_object_result", 'empty_region_result'"empty_region_result""empty_region_result""empty_region_result""empty_region_result""empty_region_result", and 'store_empty_region'"store_empty_region""store_empty_region""store_empty_region""store_empty_region""store_empty_region" with set_systemset_systemSetSystemset_systemSetSystemSetSystem. If necessary, an exception is raised.

Possible Predecessors

binomial_filterbinomial_filterBinomialFilterbinomial_filterBinomialFilterBinomialFilter, gauss_imagegauss_imageGaussImagegauss_imageGaussImageGaussImage, smooth_imagesmooth_imageSmoothImagesmooth_imageSmoothImageSmoothImage, invert_imageinvert_imageInvertImageinvert_imageInvertImageInvertImage

Possible Successors

expand_regionexpand_regionExpandRegionexpand_regionExpandRegionExpandRegion, select_shapeselect_shapeSelectShapeselect_shapeSelectShapeSelectShape, reduce_domainreduce_domainReduceDomainreduce_domainReduceDomainReduceDomain, openingopeningOpeningopeningOpeningOpening

Alternatives

watersheds_thresholdwatersheds_thresholdWatershedsThresholdwatersheds_thresholdWatershedsThresholdWatershedsThreshold, pouringpouringPouringpouringPouringPouring

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


ClassesClassesClassesClasses | | | | Operators