ClassesClassesClassesClasses | | | | Operators

pouringpouringPouringpouringPouringPouring (Operator)

Name

pouringpouringPouringpouringPouringPouring — Segment an image by “pouring water” over it.

Signature

pouring(Image : Regions : Mode, MinGray, MaxGray : )

Herror pouring(const Hobject Image, Hobject* Regions, const char* Mode, const Hlong MinGray, const Hlong MaxGray)

Herror T_pouring(const Hobject Image, Hobject* Regions, const Htuple Mode, const Htuple MinGray, const Htuple MaxGray)

Herror pouring(Hobject Image, Hobject* Regions, const HTuple& Mode, const HTuple& MinGray, const HTuple& MaxGray)

HRegionArray HImage::Pouring(const HTuple& Mode, const HTuple& MinGray, const HTuple& MaxGray) const

void Pouring(const HObject& Image, HObject* Regions, const HTuple& Mode, const HTuple& MinGray, const HTuple& MaxGray)

HRegion HImage::Pouring(const HString& Mode, Hlong MinGray, Hlong MaxGray) const

HRegion HImage::Pouring(const char* Mode, Hlong MinGray, Hlong MaxGray) const

void HOperatorSetX.Pouring(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*Regions, [in] VARIANT Mode, [in] VARIANT MinGray, [in] VARIANT MaxGray)

IHRegionX* HImageX.Pouring(
[in] BSTR Mode, [in] Hlong MinGray, [in] Hlong MaxGray)

static void HOperatorSet.Pouring(HObject image, out HObject regions, HTuple mode, HTuple minGray, HTuple maxGray)

HRegion HImage.Pouring(string mode, int minGray, int maxGray)

Description

pouringpouringPouringpouringPouringPouring regards the input image as a “mountain range.” Larger gray values correspond to mountain peaks, while smaller gray values correspond to valley bottoms. pouringpouringPouringpouringPouringPouring segments the input image in several steps. First, the local maxima are extracted, i.e., pixels which either alone or in the form of an extended plateau have larger gray values than their immediate neighbors (in 4-neighborhood). In the next step, the maxima thus found are the starting points for an expansion until “valley bottoms” are reached. The expansion is done as long as there are chains of pixels in which the gray value becomes smaller (like water running downhill from the maxima in all directions). Again, the 4-neighborhood is used, but with a weaker condition (smaller or equal). This means that points at valley bottoms may belong to more than one maximum. These areas are at first not assigned to a region, but rather are split among all competing segments in the last step. The split is done by a uniform expansion of all involved segments, until all ambiguous pixels were assigned. The parameter ModeModeModeModeModemode determines which steps are executed. The following values are possible:

'all'

This is the normal mode of operation. All steps of the segmentation are performed. The regions are assigned to maxima, and overlapping regions are split.

'maxima'

The segmentation only extracts the local maxima of the input image. No corresponding regions are extracted.

'regions'

The segmentation extracts the local maxima of the input image and the corresponding regions, which are uniquely determined. Areas that were assigned to more than one maximum are not split.

In order to prevent the algorithm from splitting a uniform background that is different from the rest of the image, the parameters MinGrayMinGrayMinGrayMinGrayMinGrayminGray and MaxGrayMaxGrayMaxGrayMaxGrayMaxGraymaxGray determine gray value thresholds for regions in the image that should be regarded as background. All parts of the image having a gray value smaller than MinGrayMinGrayMinGrayMinGrayMinGrayminGray or larger than MaxGrayMaxGrayMaxGrayMaxGrayMaxGraymaxGray are disregarded for the extraction of the maxima as well as for the assignment of regions. For a complete segmentation of the image, MinGrayMinGrayMinGrayMinGrayMinGrayminGray = 0 and MaxGrayMaxGrayMaxGrayMaxGrayMaxGraymaxGray = 255 should be selected. MinGrayMinGrayMinGrayMinGrayMinGrayminGray < MaxGrayMaxGrayMaxGrayMaxGrayMaxGraymaxGray must be observed.

Parallelization

Parameters

ImageImageImageImageImageimage (input_object)  singlechannelimage objectHImageHImageHImageHImageXHobject (byte)

Input image.

RegionsRegionsRegionsRegionsRegionsregions (output_object)  region-array objectHRegionHRegionHRegionArrayHRegionXHobject *

Segmented regions.

ModeModeModeModeModemode (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Mode of operation.

Default value: 'all' "all" "all" "all" "all" "all"

List of values: 'all'"all""all""all""all""all", 'maxima'"maxima""maxima""maxima""maxima""maxima", 'regions'"regions""regions""regions""regions""regions"

MinGrayMinGrayMinGrayMinGrayMinGrayminGray (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

All gray values smaller than this threshold are disregarded.

Default value: 0

Suggested values: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110

Typical range of values: 0 ≤ MinGray MinGray MinGray MinGray MinGray minGray ≤ 255 (lin)

Minimum increment: 1

Recommended increment: 10

Restriction: MinGray >= 0

MaxGrayMaxGrayMaxGrayMaxGrayMaxGraymaxGray (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

All gray values larger than this threshold are disregarded.

Default value: 255

Suggested values: 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 255

Typical range of values: 0 ≤ MaxGray MaxGray MaxGray MaxGray MaxGray maxGray ≤ 255 (lin)

Minimum increment: 1

Recommended increment: 10

Restriction: MaxGray <= 255 && MaxGray > MinGray

Example (HDevelop)

* Segment a filtered image
read_image(Image,'particle')
mean_image(Image,Mean,11,11)
pouring(Mean,Seg,'all',0,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

* Segment an image while masking the dark background
read_image(Image,'particle')
mean_image(Image,ImageMean,15,15)
pouring(Mean,Seg,'all',90,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

Example (C)

/* Segmentation of a filtered image */
read_image(&Image,"br2");
mean_image(Image,&Mean,11,11);
pouring(Mean,&Seg,"all",0,255);
disp_image(Mean,WindowHandle);
set_colored(WindowHandle,12);
disp_region(Seg,WindowHandle);

/* Segmentation of an image with masking of a dark backround */
read_image(&Image,"hand");
mean_image(Image,&Mean,15,15);
pouring(Mean,&Seg,"all",40,255);
disp_image(Mean,WindowHandle);
set_colored(WindowHandle,12);
disp_region(Seg,WindowHandle);

Example (HDevelop)

* Segment a filtered image
read_image(Image,'particle')
mean_image(Image,Mean,11,11)
pouring(Mean,Seg,'all',0,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

* Segment an image while masking the dark background
read_image(Image,'particle')
mean_image(Image,ImageMean,15,15)
pouring(Mean,Seg,'all',90,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

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   img1 ("br2"),
           img2 ("hand"),
           img3 ("monkey"),
           texture,
           testreg;

  HWindow      w1, w2, w3;
  HRegion      region;
  HRegionArray seg;

  w1.SetColored (12);   img1.Display (w1);
  w2.SetColored (12);   img2.Display (w2);
  w3.SetColored (12);   img3.Display (w3);

  cout << "Smoothing of images 1 and 2 ..." << endl;

  HImage mean1 = img1.MeanImage (11, 11);
  HImage mean2 = img2.MeanImage (15, 15);

  cout << "Full segmentation of images ... " << endl;
  seg = mean1.Pouring ("all", 0, 255);
  seg.Display (w1);

  cout << "Segmentation with: a) masked background " << endl;
  cout << "                   b) intersection " << endl;
  seg = mean2.Pouring ("regions", 40, 255);
  seg.Display (w2);

  cout << "Segmentation in 2d-histogram" << endl;
  cout << "Draw region with the mouse: " << endl;

  region  = w3.DrawRegion ();
  texture = img3.TextureLaws ("el", 2, 5);

  testreg = texture.ReduceDomain (region);
  histo   = testreg.Histo2dim (texture, region);
  seg     = histo.Pouring ("all", 0, 255);

  seg.Display (w3);
  w3.Click ();
  return (0);
}

Example (HDevelop)

* Segment a filtered image
read_image(Image,'particle')
mean_image(Image,Mean,11,11)
pouring(Mean,Seg,'all',0,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

* Segment an image while masking the dark background
read_image(Image,'particle')
mean_image(Image,ImageMean,15,15)
pouring(Mean,Seg,'all',90,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

Example (HDevelop)

* Segment a filtered image
read_image(Image,'particle')
mean_image(Image,Mean,11,11)
pouring(Mean,Seg,'all',0,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

* Segment an image while masking the dark background
read_image(Image,'particle')
mean_image(Image,ImageMean,15,15)
pouring(Mean,Seg,'all',90,255)
dev_display(Mean)
dev_set_colored(12)
dev_display(Seg)

Complexity

Let N be the number of pixels in the input image and M be the number of found segments, where the enclosing rectangle of the segment i contains m_{i} pixels. Furthermore, let K_{i} be the number of chords in segment i. Then the runtime complexity is

Result

pouringpouringPouringpouringPouringPouring usually returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Possible Predecessors

binomial_filterbinomial_filterBinomialFilterbinomial_filterBinomialFilterBinomialFilter, gauss_filtergauss_filterGaussFiltergauss_filterGaussFilterGaussFilter, smooth_imagesmooth_imageSmoothImagesmooth_imageSmoothImageSmoothImage, mean_imagemean_imageMeanImagemean_imageMeanImageMeanImage

Alternatives

watershedswatershedsWatershedswatershedsWatershedsWatersheds, local_maxlocal_maxLocalMaxlocal_maxLocalMaxLocalMax

See also

histo_2dimhisto_2dimHisto2dimhisto_2dimHisto2dimHisto2dim, expand_regionexpand_regionExpandRegionexpand_regionExpandRegionExpandRegion, expand_grayexpand_grayExpandGrayexpand_grayExpandGrayExpandGray, expand_gray_refexpand_gray_refExpandGrayRefexpand_gray_refExpandGrayRefExpandGrayRef

Module

Foundation


ClassesClassesClassesClasses | | | | Operators