HALCON Reference Manual 10.0.2
Table of Contents / Segmentation / Threshold ClassesClassesClasses | | | Operators

dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold (Operator)

Name

dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold — Segment an image using a local threshold.

Signature

dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : )

Herror dyn_threshold(const Hobject OrigImage, const Hobject ThresholdImage, Hobject* RegionDynThresh, double Offset, const char* LightDark)

Herror T_dyn_threshold(const Hobject OrigImage, const Hobject ThresholdImage, Hobject* RegionDynThresh, const Htuple Offset, const Htuple LightDark)

Herror dyn_threshold(Hobject OrigImage, Hobject ThresholdImage, Hobject* RegionDynThresh, const HTuple& Offset, const HTuple& LightDark)

HRegion HImage::DynThreshold(const HImage& ThresholdImage, const HTuple& Offset, const HTuple& LightDark) const

HRegionArray HImageArray::DynThreshold(const HImageArray& ThresholdImage, const HTuple& Offset, const HTuple& LightDark) const

void HOperatorSetX.DynThreshold(
[in] IHUntypedObjectX* OrigImage, [in] IHUntypedObjectX* ThresholdImage, [out] IHUntypedObjectX*RegionDynThresh, [in] VARIANT Offset, [in] VARIANT LightDark)

IHRegionX* HImageX.DynThreshold(
[in] IHImageX* ThresholdImage, [in] VARIANT Offset, [in] BSTR LightDark)

static void HOperatorSet.DynThreshold(HObject origImage, HObject thresholdImage, out HObject regionDynThresh, HTuple offset, HTuple lightDark)

HRegion HImage.DynThreshold(HImage thresholdImage, HTuple offset, string lightDark)

HRegion HImage.DynThreshold(HImage thresholdImage, double offset, string lightDark)

Description

dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold selects from the input image those regions in which the pixels fulfill a threshold condition. Let g_{o} = g_{OrigImageOrigImageOrigImageOrigImageorigImage}, and g_{t} = g_{ThresholdImageThresholdImageThresholdImageThresholdImagethresholdImage}. Then the condition for LightDarkLightDarkLightDarkLightDarklightDark = 'light' is:

                 g_o >= g_t + Offset

For LightDarkLightDarkLightDarkLightDarklightDark = 'dark' the condition is:

                 g_o <= g_t - Offset

For LightDarkLightDarkLightDarkLightDarklightDark = 'equal' it is:

                 g_t - Offset <= g_o <= g_t + Offset

Finally, for LightDarkLightDarkLightDarkLightDarklightDark = 'not_equal' it is:

                 g_t - Offset > g_o or g_o > g_t + Offset

Typically, the threshold images are smoothed versions of the original image (e.g., by applying mean_imagemean_imagemean_imageMeanImageMeanImage, binomial_filterbinomial_filterbinomial_filterBinomialFilterBinomialFilter, gauss_imagegauss_imagegauss_imageGaussImageGaussImage, etc.). Then the effect of dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold is similar to applying thresholdthresholdthresholdThresholdThreshold to a highpass-filtered version of the original image (see highpass_imagehighpass_imagehighpass_imageHighpassImageHighpassImage).

With dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold, contours of an object can be extracted, where the objects' size (diameter) is determined by the mask size of the lowpass filter and the amplitude of the objects' edges:

The larger the mask size is chosen, the larger the found regions become. As a rule of thumb, the mask size should be about twice the diameter of the objects to be extracted. It is important not to set the parameter OffsetOffsetOffsetOffsetoffset to zero because in this case too many small regions will be found (noise). Values between 5 and 40 are a useful choice. The larger OffsetOffsetOffsetOffsetoffset is chosen, the smaller the extracted regions become.

All points of the input image fulfilling the above condition are stored jointly in one region. If necessary, the connected components can be obtained by calling connectionconnectionconnectionConnectionConnection.

Attention

If OffsetOffsetOffsetOffsetoffset is chosen from -1 to 1 usually a very noisy region is generated, requiring large storage. If OffsetOffsetOffsetOffsetoffset is chosen too large (> 60, say) it may happen that no points fulfill the threshold condition (i.e., an empty region is returned). If OffsetOffsetOffsetOffsetoffset is chosen too small (< -60, say) it may happen that all points fulfill the threshold condition (i.e., a full region is returned).

Parallelization

Parameters

OrigImageOrigImageOrigImageOrigImageorigImage (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / int2 / uint2 / int4 / real)

Input image.

ThresholdImageThresholdImageThresholdImageThresholdImagethresholdImage (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / int2 / uint2 / int4 / real)

Image containing the local thresholds.

RegionDynThreshRegionDynThreshRegionDynThreshRegionDynThreshregionDynThresh (output_object)  region(-array) objectHRegionHRegionHRegionXHobject *

Segmented regions.

OffsetOffsetOffsetOffsetoffset (input_control)  number HTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong)

Offset applied to ThresholdImage.

Default value: 5.0

Suggested values: 1.0, 3.0, 5.0, 7.0, 10.0, 20.0, 30.0

Typical range of values: -255.0 ≤ Offset Offset Offset Offset offset ≤ 255.0 (lin)

Minimum increment: 0.01

Recommended increment: 5

Restriction: (-255 < Offset) && (Offset < 255)

LightDarkLightDarkLightDarkLightDarklightDark (input_control)  string HTupleHTupleVARIANTHtuple (string) (string) (char*) (BSTR) (char*)

Extract light, dark or similar areas?

Default value: 'light' "light" "light" "light" "light"

List of values: 'dark'"dark""dark""dark""dark", 'light'"light""light""light""light", 'equal'"equal""equal""equal""equal", 'not_equal'"not_equal""not_equal""not_equal""not_equal"

Example (HDevelop)

* Looking for regions with the diameter D
mean_image(Image,Mean,D*2+1,D*2+1)
dyn_threshold(Image,Mean,Seg,5,'light')
connection(Seg,Regions)

Example (C)

/* Looking for regions with the diameter D */
mean_image(Image,&Mean,D*2+1,D*2+1);
dyn_threshold(Image,Mean,&Seg,5.0,"light");
connection(Seg,&Region);

Example (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 ("monkey"),
           mean;
  HWindow  win;

  if (argc != 2)
  {
    cout << "Using: " << argv[0] << " <diameter>" << endl;
    exit (1);
  }

  int d = atoi (argv[1]) * 2 + 1;

  image.Display (win);

  mean = image.MeanImage (d, d);

  HRegionArray seg = image.DynThreshold (mean, 5.0, "light");
  HRegionArray reg = seg.Connection ();

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

  return (0);
}

Example (HDevelop)

* Looking for regions with the diameter D
mean_image(Image,Mean,D*2+1,D*2+1)
dyn_threshold(Image,Mean,Seg,5,'light')
connection(Seg,Regions)

Example (HDevelop)

* Looking for regions with the diameter D
mean_image(Image,Mean,D*2+1,D*2+1)
dyn_threshold(Image,Mean,Seg,5,'light')
connection(Seg,Regions)

Complexity

Let A be the area of the input region. Then the runtime complexity is O(A).

Result

dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold returns 2 (H_MSG_TRUE) if all parameters are correct. 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", '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" with set_systemset_systemset_systemSetSystemSetSystem. If necessary, an exception is raised.

Possible Predecessors

mean_imagemean_imagemean_imageMeanImageMeanImage, smooth_imagesmooth_imagesmooth_imageSmoothImageSmoothImage, binomial_filterbinomial_filterbinomial_filterBinomialFilterBinomialFilter, gauss_imagegauss_imagegauss_imageGaussImageGaussImage

Possible Successors

connectionconnectionconnectionConnectionConnection, select_shapeselect_shapeselect_shapeSelectShapeSelectShape, reduce_domainreduce_domainreduce_domainReduceDomainReduceDomain, select_grayselect_grayselect_graySelectGraySelectGray, rank_regionrank_regionrank_regionRankRegionRankRegion, dilation1dilation1dilation1Dilation1Dilation1, openingopeningopeningOpeningOpening, erosion1erosion1erosion1Erosion1Erosion1

Alternatives

check_differencecheck_differencecheck_differenceCheckDifferenceCheckDifference, thresholdthresholdthresholdThresholdThreshold

See also

highpass_imagehighpass_imagehighpass_imageHighpassImageHighpassImage, sub_imagesub_imagesub_imageSubImageSubImage

Module

Foundation


Table of Contents / Segmentation / Threshold ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH