Skip to content

auto_thresholdAutoThresholdAutoThresholdauto_thresholdauto_threshold🔗

Short description🔗

auto_thresholdAutoThresholdAutoThresholdauto_thresholdauto_threshold — Segment an image using thresholds determined from its histogram.

Signature🔗

auto_threshold( image Image, out region Regions, number Sigma )void AutoThreshold( const HObject& Image, HObject* Regions, const HTuple& Sigma )static void HOperatorSet.AutoThreshold( HObject image, out HObject regions, HTuple sigma )def auto_threshold( image: HObject, sigma: Union[int, float] ) -> HObject

Herror auto_threshold( const Hobject Image, Hobject* Regions, double Sigma )

Herror T_auto_threshold( const Hobject Image, Hobject* Regions, const Htuple Sigma )

HRegion HImage::AutoThreshold( const HTuple& Sigma ) const

HRegion HImage::AutoThreshold( double Sigma ) const

HRegion HImage.AutoThreshold( HTuple sigma )

HRegion HImage.AutoThreshold( double sigma )

Description🔗

auto_thresholdAutoThreshold segments a single-channel image using multiple thresholding. First, the absolute histogram of the gray values is determined. Then, relevant minima are extracted from the histogram, which are used successively as parameters for a thresholding operation. The thresholds used for byte images are 0, 255, and all minima extracted from the histogram (after the histogram has been smoothed with a Gaussian filter with standard deviation Sigmasigmasigma). For each gray value interval one region is generated. Thus, the number of regions is the number of minima + 1. For uint2 images, the above procedure is used analogously. However, here the highest threshold is 65535. Furthermore, for uint2 images the value of Sigmasigmasigma (virtually) refers to a histogram with 256 values, although internally histograms with a higher resolution are used. This is done to facilitate switching between image types without having to change the parameter Sigmasigmasigma. For float images the thresholds are the minimum and maximum gray value in the image and all minima extracted from the histogram. Here, the scaling of the parameter Sigmasigmasigma refers to the original gray values of the image. The larger the value of Sigmasigmasigma is chosen, the fewer regions will be extracted. This operator is useful if the regions to be extracted exhibit similar gray values (homogeneous regions).

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

  • Automatically parallelized on internal data level.

Parameters🔗

Imageimageimage (input_object) singlechannelimage(-array) → object (byte / uint2 / real)HObject (byte / uint2 / real)HImage (byte / uint2 / real)HObject (byte / uint2 / real)Hobject (byte / uint2 / real)

Input image.

Regionsregionsregions (output_object) region-array → objectHObjectHRegionHObjectHobject *

Regions with gray values within the automatically determined intervals.

Sigmasigmasigma (input_control) number → (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[int, float]Htuple (double / Hlong)

Sigma for the Gaussian smoothing of the histogram.

Default: 2.02.0
Suggested values: 0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.00.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0
Value range: Sigma (lin)
Minimum increment: 0.01
Recommended increment: 0.3

Example🔗

(HDevelop)

read_image (Image, 'fabrik')
median_image (Image, Median, 'circle', 3, 'mirrored')
auto_threshold (Median, Seg, 2.0)
connection (Seg, Connected)
(C)
read_image(&Image,"fabrik")\;
median_image(Image,&Median,"circle",3,"mirrored")\;
auto_threshold(Median,&Seg,2.0)\;
connection(Seg,&Connected)\;
set_colored(WindowHandle,12)\;
disp_obj(Connected,WindowHandle)\;
(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 != 2)
  {
    cout << "Usage : " << argv[0] << " 'image' " << endl\;
    return -1\;
  }
 HImage       image(argv[1])\;
  HImage       med\;
  HWindow      w\;
 w.SetDraw("margin")\;
  w.SetColored(12)\;
 image.Display (w)\;
 med = image.MedianImage("circle", 3, "mirrored")\;
  med.Display(w)\;
 HRegionArray reg = med.AutoThreshold(2.0)\;
  HRegionArray con = reg.Connection()\;
 cout << "Display image after AutoThreshold segmentation " << endl\;
  con.Display(w)\;
  w.Click()\;
 return 0\;
}

Combinations with other operators🔗

Combinations

Possible predecessors

anisotropic_diffusionAnisotropicDiffusion, median_imageMedianImage, illuminateIlluminate

Possible successors

connectionConnection, select_shapeSelectShape, select_graySelectGray

Alternatives

binary_thresholdBinaryThreshold, char_thresholdCharThreshold

See also

gray_histoGrayHisto, gray_histo_absGrayHistoAbs, histo_to_threshHistoToThresh, smooth_funct_1d_gaussSmoothFunct1dGauss, thresholdThreshold

Module🔗

Foundation