【HALCON】閾値処理完全ガイド - threshold関数リファレンス

PUBLISHED 2024-08-20

HALCONの閾値処理(Thresholding)は、画像をセグメンテーション(領域分割)するための基本的な手法です。ピクセルの輝度値を基準値と比較し、条件を満たす領域を抽出します。


グローバル閾値

threshold - 基本閾値処理

指定した輝度値範囲のピクセルを抽出します。最も基本的な閾値処理関数です。

threshold(Image : Region : MinGray, MaxGray : )
* 画像の読み込み
read_image(Image, 'fabrik')
* 閾値処理(128255の範囲を抽出)
threshold(Image, Region, 128, 255)

fast_threshold - 高速閾値処理

thresholdと同様の処理を高速に実行します。リアルタイム処理に最適です。

fast_threshold(Image : Region : MinGray, MaxGray : MinSize)
  • MinSize: 抽出する最小領域サイズ

dual_threshold - 二重閾値処理

2つの閾値範囲を同時に適用し、より精密な領域抽出を行います。

dual_threshold(Image : Region : MinGray, MaxGray : MinSize)

自動閾値

auto_threshold - 自動閾値決定

画像のヒストグラムを解析し、最適な閾値を自動的に決定して二値化します。

auto_threshold(Image : Region : Sigma)
  • Sigma: ヒストグラム平滑化のパラメータ
read_image(Image, 'product.png')
auto_threshold(Image, Region, 2)

binary_threshold - 二値化閾値

最大分離度法(大津の方法)などのアルゴリズムで最適閾値を決定します。

binary_threshold(Image : Region : Method, LightDark : UsedThreshold)
  • Method: 'max_separability'(大津の方法)、'smooth_histo'など
  • LightDark: 'light'(明るい領域)、'dark'(暗い領域)
binary_threshold(Image, Region, 'max_separability', 'light', Threshold)
* Thresholdに使用された閾値が返される

char_threshold - 文字抽出用閾値

文字認識に特化した閾値処理です。テキスト領域の抽出に最適化されています。

char_threshold(Image, HistoRegion : Region : Sigma, Percent : Threshold)

動的閾値(適応的閾値)

dyn_threshold - 動的閾値処理

参照画像との差分を基に閾値処理を行います。照明が不均一な環境で効果的です。

dyn_threshold(OrigImage, ThresholdImage : Region : Offset, LightDark : )
  • ThresholdImage: 参照画像(通常は平滑化した画像)
  • Offset: 閾値オフセット
  • LightDark: 'light''dark''equal''not_equal'
read_image(Image, 'uneven_light.png')
* 平滑化して参照画像を作成
mean_image(Image, MeanImage, 51, 51)
* 動的閾値処理
dyn_threshold(Image, MeanImage, Region, 5, 'light')

local_threshold - ローカル閾値処理

各ピクセルの周辺領域を分析して適応的に閾値を決定します。

local_threshold(Image : Region : Method, LightDark, GenParamName, GenParamValue : )
  • Method: 'adapted_std_deviation''mean''median'など
local_threshold(Image, Region, 'adapted_std_deviation', 'light', [], [])

var_threshold - 分散ベース閾値

ローカルな分散(コントラスト)に基づいて閾値処理を行います。

var_threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark : )
  • MaskWidth, MaskHeight: 局所領域のサイズ
  • StdDevScale: 標準偏差のスケール係数
  • AbsThreshold: 絶対閾値

特殊閾値処理

hysteresis_threshold - ヒステリシス閾値

2段階の閾値を使用し、エッジの連続性を保持しながら閾値処理を行います。Cannyエッジ検出でも使用される手法です。

hysteresis_threshold(Image : Region : Low, High, MaxLength : )
  • Low: 低い閾値(弱いエッジの検出用)
  • High: 高い閾値(強いエッジの検出用)
  • MaxLength: 最大ギャップ長
* エッジ検出
edges_image(Image, Edges, 'canny', 1, 'nms', 20, 40)
* ヒステリシス閾値でエッジを連結
hysteresis_threshold(Edges, Region, 20, 40, 5)

watersheds_threshold - ウォーターシェッド閾値

ウォーターシェッド変換に閾値を組み合わせた領域分割を行います。

watersheds_threshold(Image : Basins, Watersheds : Threshold : )
  • Basins: 分割された流域
  • Watersheds: 分水嶺(境界線)
  • Threshold: 統合閾値

閾値関数の比較

関数用途照明条件
threshold基本的な閾値処理均一
fast_threshold高速処理均一
auto_threshold自動閾値決定均一
binary_threshold最適閾値自動決定均一
dyn_threshold照明変動対応不均一
local_thresholdローカル適応不均一
var_thresholdコントラスト適応不均一
hysteresis_thresholdエッジ連続性保持-

使い分けガイド

照明が均一な場合

* シンプルな閾値処理
threshold(Image, Region, 100, 255)
* または自動閾値
binary_threshold(Image, Region, 'max_separability', 'light', _)

照明が不均一な場合

* 平滑化画像を基準に動的閾値
mean_image(Image, Mean, 51, 51)
dyn_threshold(Image, Mean, Region, 5, 'light')

文字認識の前処理

* 文字に特化した閾値処理
char_threshold(Image, Image, Region, 6, 95, Threshold)

エッジ検出後の処理

* ヒステリシス閾値でエッジを連結
hysteresis_threshold(EdgeImage, Region, 20, 50, 10)

まとめ

HALCONの閾値処理関数は、用途に応じて様々な手法が用意されています。照明条件、処理速度、精度要件に応じて適切な関数を選択することで、効果的なセグメンテーションが可能です。

CATEGORY
TAGS
円