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

thresholdthresholdthresholdThresholdThreshold (Operator)

Name

thresholdthresholdthresholdThresholdThreshold — Segment an image using global threshold.

Signature

threshold(Image : Region : MinGray, MaxGray : )

Herror threshold(const Hobject Image, Hobject* Region, double MinGray, double MaxGray)

Herror T_threshold(const Hobject Image, Hobject* Region, const Htuple MinGray, const Htuple MaxGray)

Herror threshold(Hobject Image, Hobject* Region, const HTuple& MinGray, const HTuple& MaxGray)

HRegion HImage::Threshold(const HTuple& MinGray, const HTuple& MaxGray) const

HRegionArray HImageArray::Threshold(const HTuple& MinGray, const HTuple& MaxGray) const

void HOperatorSetX.Threshold(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*Region, [in] VARIANT MinGray, [in] VARIANT MaxGray)

IHRegionX* HImageX.Threshold(
[in] VARIANT MinGray, [in] VARIANT MaxGray)

static void HOperatorSet.Threshold(HObject image, out HObject region, HTuple minGray, HTuple maxGray)

HRegion HImage.Threshold(HTuple minGray, HTuple maxGray)

HRegion HImage.Threshold(double minGray, double maxGray)

Description

thresholdthresholdthresholdThresholdThreshold selects the pixels from the input image whose gray values g fulfill the following condition:

             MinGray <= g <=  MaxGray .

All points of an image fulfilling the condition are returned as one region. If more than one gray value interval is passed (tuples for MinGrayMinGrayMinGrayMinGrayminGray and MaxGrayMaxGrayMaxGrayMaxGraymaxGray), one separate region is returned for each interval.

Attention

For input images of an integer type, floating point values in MinGrayMinGrayMinGrayMinGrayminGray and MaxGrayMaxGrayMaxGrayMaxGraymaxGray are truncated.

Parallelization

Parameters

ImageImageImageImageimage (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)

Input image.

RegionRegionRegionRegionregion (output_object)  region(-array) objectHRegionHRegionHRegionXHobject *

Segmented region.

MinGrayMinGrayMinGrayMinGrayminGray (input_control)  number(-array) HTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong)

Lower threshold for the gray values.

Default value: 128.0

Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0

MaxGrayMaxGrayMaxGrayMaxGraymaxGray (input_control)  number(-array) HTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong)

Upper threshold for the gray values.

Default value: 255.0

Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0

Restriction: MaxGray >= MinGray

Example (HDevelop)

read_image(Image,'fabrik')
sobel_dir(Image,EdgeAmp,EdgeDir,'sum_abs',3)
threshold(EdgeAmp,Seg,50,255)
skeleton(Seg,Rand)
connection(Rand,Lines)
select_shape(Lines,Edges,'area','and',10,1000000)

Example (C)

read_image(&Image,"fabrik");
sobel_amp(Image,&EdgeAmp,"sum_abs",3);
threshold(EdgeAmp,&Seg,50.0,255.0);
skeleton(Seg,&Rand);
connection(Rand,&Lines);
select_shape(Lines,&Edges,"area","and",10.0,1000000.0);

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[])
{
  if (argc != 4)
  {
    cout << "Usage : " << argv[0] << " 'image' MinGray MaxGray" << endl;
    return (-1);
  }

  HImage   image (argv[1]),
           Sobel;
  HWindow  win;

  image.Display (win);

  int MinGray = atoi (argv[2]);
  int MaxGray = atoi (argv[3]);

  Sobel = image.SobelAmp ("sum_abs", 3);

  HRegionArray rand  = ((image >= MinGray) & (image <= MaxGray)).Skeleton();
  HRegionArray lines = rand.Connection();
  HRegionArray edges = lines.SelectShape("area", "and", 10.0, 10000000.0);

  edges.Display (win);
  win.Click ();

  return (0);
}

Example (HDevelop)

read_image(Image,'fabrik')
sobel_dir(Image,EdgeAmp,EdgeDir,'sum_abs',3)
threshold(EdgeAmp,Seg,50,255)
skeleton(Seg,Rand)
connection(Rand,Lines)
select_shape(Lines,Edges,'area','and',10,1000000)

Example (HDevelop)

read_image(Image,'fabrik')
sobel_dir(Image,EdgeAmp,EdgeDir,'sum_abs',3)
threshold(EdgeAmp,Seg,50,255)
skeleton(Seg,Rand)
connection(Rand,Lines)
select_shape(Lines,Edges,'area','and',10,1000000)

Complexity

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

Result

thresholdthresholdthresholdThresholdThreshold 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

histo_to_threshhisto_to_threshhisto_to_threshHistoToThreshHistoToThresh, min_max_graymin_max_graymin_max_grayMinMaxGrayMinMaxGray, sobel_ampsobel_ampsobel_ampSobelAmpSobelAmp, binomial_filterbinomial_filterbinomial_filterBinomialFilterBinomialFilter, gauss_imagegauss_imagegauss_imageGaussImageGaussImage, reduce_domainreduce_domainreduce_domainReduceDomainReduceDomain, fill_interlacefill_interlacefill_interlaceFillInterlaceFillInterlace

Possible Successors

connectionconnectionconnectionConnectionConnection, dilation1dilation1dilation1Dilation1Dilation1, erosion1erosion1erosion1Erosion1Erosion1, openingopeningopeningOpeningOpening, closingclosingclosingClosingClosing, rank_regionrank_regionrank_regionRankRegionRankRegion, shape_transshape_transshape_transShapeTransShapeTrans, skeletonskeletonskeletonSkeletonSkeleton

Alternatives

class_2dim_supclass_2dim_supclass_2dim_supClass2dimSupClass2dimSup, hysteresis_thresholdhysteresis_thresholdhysteresis_thresholdHysteresisThresholdHysteresisThreshold, dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold, bin_thresholdbin_thresholdbin_thresholdBinThresholdBinThreshold, char_thresholdchar_thresholdchar_thresholdCharThresholdCharThreshold, auto_thresholdauto_thresholdauto_thresholdAutoThresholdAutoThreshold, dual_thresholddual_thresholddual_thresholdDualThresholdDualThreshold

See also

zero_crossingzero_crossingzero_crossingZeroCrossingZeroCrossing, background_segbackground_segbackground_segBackgroundSegBackgroundSeg, regiongrowingregiongrowingregiongrowingRegiongrowingRegiongrowing

Module

Foundation


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