Skip to content

thresholdThresholdThresholdthresholdthreshold🔗

説明🔗

thresholdThresholdThresholdthresholdthreshold — グローバルしきい値を指定して画像を分割する。

書式🔗

threshold( image Image, out region Region, number MinGray, number MaxGray )void Threshold( const HObject& Image, HObject* Region, const HTuple& MinGray, const HTuple& MaxGray )static void HOperatorSet.Threshold( HObject image, out HObject region, HTuple minGray, HTuple maxGray )def threshold( image: HObject, min_gray: MaybeSequence[Union[int, float, str]], max_gray: MaybeSequence[Union[int, float, str]] ) -> HObject

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 )

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

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

HRegion HImage.Threshold( HTuple minGray, HTuple maxGray )

HRegion HImage.Threshold( double minGray, double maxGray )

説明🔗

thresholdThreshold は、グレイ値 \(g\) が以下に示す条件を満足するピク セルを入力画像から選択します。

\[\begin{eqnarray*} \textrm{MinGray} \le g \le \textrm{MaxGray} \enspace . \end{eqnarray*}\]

条件を満たす画像のすべての点が 1 つの領域として返されます。複数の グレイ値間隔(MinGrayminGraymin_gray と MaxGraymaxGraymax_gray の tuple)が渡 された場合、各間隔に対して 1 つの領域が返されます。 ベクトル場画像の対しては、しきい値はグレイ値に適用されず、 ベクトルの長さに対して適用されます。 パラメータMinGrayminGraymin_grayとMaxGraymaxGraymax_grayは、それぞれ下限と上限を開いた状態にするために、 'min'"min"または'max'"max"に設定できます。

注意🔗

MinGrayminGraymin_gray と MaxGraymaxGraymax_gray の使用は、入力画像タイプの影響を受ける可能性があります。 入力画像が int 型の画像である場合、MinGrayminGraymin_gray と MaxGraymaxGraymax_gray に浮動小数値が与えられると小数点以下が切り捨てられます。 real、および vector_field 型の画像に対して、MinGrayminGraymin_gray と MaxGraymaxGraymax_gray の値がdouble型である場合、浮動小数点が使用されます。

実行情報🔗

実行情報
  • マルチスレッドタイプ: リエントラント(非排他なオペレーターと並列に動作)

  • マルチスレッドスコープ: グローバル(他のスレッドから呼び出される可能性あり)

  • tupleレベルで自動的に並列演算処理を実施

  • 内部データレベルで自動的に並列演算処理を実施

パラメーター🔗

Imageimageimage (input_object) singlechannelimage(-array) → object (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)HObject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)HImage (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)HObject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)Hobject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real / vector_field)

入力画像

Regionregionregion (output_object) region(-array) → objectHObjectHRegionHObjectHobject *

セグメント化された領域

MinGrayminGraymin_gray (input_control) number(-array) → (real / integer / string)HTuple (double / Hlong / HString)HTuple (double / int / long / string)MaybeSequence[Union[int, float, str]]Htuple (double / Hlong / char*)

グレイ値の下限しきい値または'min'"min"

初期値: 128.0128.0
推奨値: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0, 'min'0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0, "min"

MaxGraymaxGraymax_gray (input_control) number(-array) → (real / integer / string)HTuple (double / Hlong / HString)HTuple (double / int / long / string)MaybeSequence[Union[int, float, str]]Htuple (double / Hlong / char*)

グレイ値の上限しきい値または'max'"max"

初期値: 255.0255.0
推奨値: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0, 'max'0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0, "max"
制限: MaxGray >= MinGray

例🔗

(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)
(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)\;
(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)\;
}

複雑性🔗

入力領域の面積を \(A\) とします。その場合、実行時間は \(O(A)\) です。

結果🔗

thresholdThreshold は、すべてのパラメーターが正しい場合に 2 (H_MSG_TRUE) を返 します。 入力画像と出力領域に関する動作は、set_systemSetSystem でフラグ 'no_object_result'"no_object_result"、'empty_region_result'"empty_region_result"、およ び 'store_empty_region'"store_empty_region" の値を設定することによって決定さ れます。 必要に応じて、例外が発生します。

他のオペレーターとの組み合わせ🔗

組み合わせ

前処理の候補

histo_to_threshHistoToThresh, min_max_grayMinMaxGray, sobel_ampSobelAmp, binomial_filterBinomialFilter, gauss_filterGaussFilter, reduce_domainReduceDomain, fill_interlaceFillInterlace

後処理の候補

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

他の選択候補

class_2dim_supClass2dimSup, hysteresis_thresholdHysteresisThreshold, dyn_thresholdDynThreshold, binary_thresholdBinaryThreshold, char_thresholdCharThreshold, auto_thresholdAutoThreshold, dual_thresholdDualThreshold

関連項目

zero_crossingZeroCrossing, background_segBackgroundSeg, regiongrowingRegiongrowing

モジュール🔗

Foundation