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)

void Threshold(const HObject& Image, HObject* Region, const HTuple& MinGray, const HTuple& MaxGray)

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

HRegion HImage::Threshold(double MinGray, double MaxGray) const

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)

def threshold(image: HObject, min_gray: MaybeSequence[Union[int, float, str]], max_gray: MaybeSequence[Union[int, float, str]]) -> HObject

Description

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

All points of an image fulfilling the condition are returned as one region. If more than one gray value interval is passed (tuples for MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray), one separate region is returned for each interval. For vector field images, the threshold is not applied to gray values but to the lengths of the vectors. The parameters MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray can be set to 'min'"min""min""min""min""min" or 'max'"max""max""max""max""max" in order to leave bottom and top limits, respectively, open.

Attention

The usage of MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray can be affected by the input image type.

For images of type integer, floating point values in MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray are truncated. For images of type real or vector field, floating point precision will be used for MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray, if they are of type double.

Execution Information

Parameters

ImageImageImageImageimageimage (input_object)  singlechannelimage(-array) objectHImageHObjectHImageHobject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)

Input image.

RegionRegionRegionRegionregionregion (output_object)  region(-array) objectHRegionHObjectHRegionHobject *

Segmented region.

MinGrayMinGrayMinGrayMinGrayminGraymin_gray (input_control)  number(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (real / integer / string) (double / int / long / string) (double / Hlong / HString) (double / Hlong / char*)

Lower threshold for the gray values or 'min'"min""min""min""min""min".

Default value: 128.0

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

MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray (input_control)  number(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (real / integer / string) (double / int / long / string) (double / Hlong / HString) (double / Hlong / char*)

Upper threshold for the gray values or 'max'"max""max""max""max""max".

Default value: 255.0

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

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

thresholdthresholdThresholdThresholdThresholdthreshold returns 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""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_systemSetSystemSetSystemSetSystemset_system. If necessary, an exception is raised.

Possible Predecessors

histo_to_threshhisto_to_threshHistoToThreshHistoToThreshHistoToThreshhisto_to_thresh, min_max_graymin_max_grayMinMaxGrayMinMaxGrayMinMaxGraymin_max_gray, sobel_ampsobel_ampSobelAmpSobelAmpSobelAmpsobel_amp, binomial_filterbinomial_filterBinomialFilterBinomialFilterBinomialFilterbinomial_filter, gauss_filtergauss_filterGaussFilterGaussFilterGaussFiltergauss_filter, reduce_domainreduce_domainReduceDomainReduceDomainReduceDomainreduce_domain, fill_interlacefill_interlaceFillInterlaceFillInterlaceFillInterlacefill_interlace

Possible Successors

connectionconnectionConnectionConnectionConnectionconnection, dilation1dilation1Dilation1Dilation1Dilation1dilation1, erosion1erosion1Erosion1Erosion1Erosion1erosion1, openingopeningOpeningOpeningOpeningopening, closingclosingClosingClosingClosingclosing, rank_regionrank_regionRankRegionRankRegionRankRegionrank_region, shape_transshape_transShapeTransShapeTransShapeTransshape_trans, skeletonskeletonSkeletonSkeletonSkeletonskeleton

Alternatives

class_2dim_supclass_2dim_supClass2dimSupClass2dimSupClass2dimSupclass_2dim_sup, hysteresis_thresholdhysteresis_thresholdHysteresisThresholdHysteresisThresholdHysteresisThresholdhysteresis_threshold, dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold, binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdBinaryThresholdbinary_threshold, char_thresholdchar_thresholdCharThresholdCharThresholdCharThresholdchar_threshold, auto_thresholdauto_thresholdAutoThresholdAutoThresholdAutoThresholdauto_threshold, dual_thresholddual_thresholdDualThresholdDualThresholdDualThresholddual_threshold

See also

zero_crossingzero_crossingZeroCrossingZeroCrossingZeroCrossingzero_crossing, background_segbackground_segBackgroundSegBackgroundSegBackgroundSegbackground_seg, regiongrowingregiongrowingRegiongrowingRegiongrowingRegiongrowingregiongrowing

Module

Foundation