Skip to content

dual_thresholdDualThresholdDualThresholddual_thresholddual_threshold🔗

Short description🔗

dual_thresholdDualThresholdDualThresholddual_thresholddual_threshold — Threshold operator for signed images.

Signature🔗

dual_threshold( image Image, out region RegionCrossings, integer MinSize, real MinGray, real Threshold )void DualThreshold( const HObject& Image, HObject* RegionCrossings, const HTuple& MinSize, const HTuple& MinGray, const HTuple& Threshold )static void HOperatorSet.DualThreshold( HObject image, out HObject regionCrossings, HTuple minSize, HTuple minGray, HTuple threshold )def dual_threshold( image: HObject, min_size: int, min_gray: float, threshold: float ) -> HObject

Herror dual_threshold( const Hobject Image, Hobject* RegionCrossings, const Hlong MinSize, double MinGray, double Threshold )

Herror T_dual_threshold( const Hobject Image, Hobject* RegionCrossings, const Htuple MinSize, const Htuple MinGray, const Htuple Threshold )

HRegion HImage::DualThreshold( Hlong MinSize, double MinGray, double Threshold ) const

HRegion HImage.DualThreshold( int minSize, double minGray, double threshold )

Description🔗

dual_thresholdDualThreshold segments the input image into a region with gray values \(\ge\)Thresholdthresholdthreshold (“positive” regions) and a region with gray values \(\le-\)Thresholdthresholdthreshold (“negative” regions). Only “positive” or “negative” regions having a size larger than MinSizeminSizemin_size are taken into account. And regions whose maximum gray value is less than MinGrayminGraymin_gray in absolute value are suppressed.

The segmentation performed is not complete, i.e., the “positive” and “negative” regions together do not necessarily cover the entire image: Areas with a gray value between \(-\)Thresholdthresholdthreshold and Thresholdthresholdthreshold, \(-\)MinGrayminGraymin_gray and MinGrayminGraymin_gray, respectively, are not taken into account.

dual_thresholdDualThreshold is usually called after applying a Laplace operator (laplaceLaplace, laplace_of_gaussLaplaceOfGauss, derivate_gaussDerivateGauss or diff_of_gaussDiffOfGauss) to an image or with the difference of two images (sub_imageSubImage).

The zero crossings of a Laplace image correspond to edges in an image, and are the separating regions of the “positive” and “negative” regions in the Laplace image. They can be determined by calling dual_thresholdDualThreshold with Thresholdthresholdthreshold = 1 and then creating the complement regions with complementComplement. The parameter MinGrayminGraymin_gray determines the noise invariance, while MinSizeminSizemin_size determines the resolution of the edge detection.

Using byte images, only the positive part of the operator is applied. Therefore dual_thresholdDualThreshold behaves like a standard threshold operator (thresholdThreshold) with successive connectionConnection and select_graySelectGray.

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 / int1 / int2 / int4 / real)HObject (byte / int1 / int2 / int4 / real)HImage (byte / int1 / int2 / int4 / real)HObject (byte / int1 / int2 / int4 / real)Hobject (byte / int1 / int2 / int4 / real)

Input image.

RegionCrossingsregionCrossingsregion_crossings (output_object) region-array → objectHObjectHRegionHObjectHobject *

Positive and negative regions.

MinSizeminSizemin_size (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Regions smaller than MinSize are suppressed.

Default: 2020
Suggested values: 0, 10, 20, 50, 100, 200, 500, 10000, 10, 20, 50, 100, 200, 500, 1000
Value range: 0 ≤ MinSize ≤ 10000 (lin)
Minimum increment: 1
Recommended increment: 10

MinGrayminGraymin_gray (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Regions whose maximum absolute gray value is smaller than MinGray are suppressed.

Default: 5.05.0
Suggested values: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 15.0, 20.01.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 15.0, 20.0
Value range: 0 ≤ MinGray (lin)
Minimum increment: 1.0
Recommended increment: 10.0

Thresholdthresholdthreshold (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Regions that have a gray value smaller than Threshold (or larger than -Threshold) are suppressed.

Default: 2.02.0
Suggested values: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 15.0, 20.01.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 15.0, 20.0
Value range: 0 ≤ Threshold (lin)
Minimum increment: 1.0
Recommended increment: 10.0

Example🔗

(HDevelop)

* Edge detection with the Laplace operator (and edge thinning)
diff_of_gauss(Image,Laplace,2.0,1.6)
* find "`positive"' and "`negative"' regions:
dual_threshold(Laplace,Region,20,2,1)
* The zero runnings are the complement to these image section:
complement(Region,ZeroCrossings)

* Simulation of dual_threshold
dual_threshold(Laplace,Result,MinS,MinG,Threshold)
threshold(Laplace,Tmp1,Threshold,999999)
connection(Tmp1,Tmp2)
select_shape(Tmp2,Tmp3,'area','and',MinS,999999)
select_gray(Laplace,Tmp3,Tmp4,'max','and',MinG,999999)
threshold(Laplace,Tmp5,-999999,-Threshold)
connection(Tmp5,Tmp6)
select_shape(Tmp6,Tmp7,'area','and',MinS,999999)
select_gray(Laplace,Tmp7,Tmp8,'min','and',-999999,-MinG)
concat_obj(Tmp4,Tmp8,Result)
(C)
/* Edge detection with the Laplace operator (and edge thinning) */
diff_of_gauss(Image,&Laplace,2.0,1.6)\;
/* find "`positive"' and "`negative"' regions: */
dual_threshold(Laplace,&Region,20,2,1)\;
/*The zero runnings are the complement to these image section: */
complement(Region,ZeroCrossings)\;
(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]),
               laplace\;
  HWindow      win\;
 HRegionArray region,
               nulldg\;
 image.Display (win)\;
 laplace = image.DiffOfGauss (2.0, 1.6)\;
  region  = laplace.DualThreshold (20, 2, 1)\;
  nulldg  = region.Complement ()\;
 laplace.Display (win)\;     win.Click ()\;
  region.Display (win)\;      win.Click ()\;
  nulldg.Display (win)\;      win.Click ()\;
 return (0)\;
}

Result🔗

dual_thresholdDualThreshold 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", 'empty_region_result'"empty_region_result", and 'store_empty_region'"store_empty_region" with set_systemSetSystem. If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

min_max_grayMinMaxGray, sobel_ampSobelAmp, binomial_filterBinomialFilter, gauss_filterGaussFilter, reduce_domainReduceDomain, diff_of_gaussDiffOfGauss, sub_imageSubImage, derivate_gaussDerivateGauss, laplace_of_gaussLaplaceOfGauss, laplaceLaplace, expand_regionExpandRegion

Possible successors

connectionConnection, dilation1Dilation1, erosion1Erosion1, openingOpening, closingClosing, rank_regionRankRegion, shape_transShapeTrans, skeletonSkeleton

Alternatives

thresholdThreshold, dyn_thresholdDynThreshold, check_differenceCheckDifference

See also

connectionConnection, select_shapeSelectShape, select_graySelectGray

Module🔗

Foundation