ヒストグラムからの二値化閾値決定
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static int fnFIE_calc_binarize_threshold( UINT_PTR data_hist, int size_hist, int mode, ref int threshold ) |
Visual Basic |
---|
Public Shared Function fnFIE_calc_binarize_threshold ( data_hist As UINT_PTR, size_hist As Integer, mode As Integer, ByRef threshold As Integer ) As Integer |
Parameters
- data_hist
- Type: fvalgcli..::..UINT_PTR
ヒストグラムへのポインタ
- size_hist
- Type: System..::..Int32
data_hist の配列の長さ。[3~]
- mode
- Type: System..::..Int32
閾値決定手法 [0:大津の方法, 1:kittlerの方法]
- threshold
- Type: System..::..Int32%
算出した閾値
Return Value
Type: Int32以下のエラーコードを返します。
エラーコード:
f_err | 内容 |
---|---|
F_ERR_NONE | 正常終了 |
F_ERR_INVALID_PARAM | パラメータ不正 |
F_ERR_CALC_IMPOSSIBLE | 計算不能エラー |
F_ERR_NO_LICENCE | ライセンスエラー、または未初期化エラー |
Examples
C# | Copy |
---|---|
// $Revision: 1.1 $ using System; using System.Collections.Generic; using System.Text; using fvalgcli; namespace TC { public partial class FIE { [FvPluginExecute] public void fnFIE_calc_binarize_threshold() { int status = (int)f_err.F_ERR_NONE; FHANDLE hsrc = FHANDLE.Zero; // 処理画像. FHANDLE hreg = FHANDLE.Zero; // リージョン. int iChaNo = 0; UINT_PTR unHist = UINT_PTR.Zero; int iHistLen = 0; int mode = 0; // 0:大津, 1:kittler int threshold = 0; try { // 入力画像ファイルのロード. api.fnFIE_load_img_file(TestImageDir + "/testdata/colorg.bmp", ref hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8); // ヒストグラム計測. hreg = api.fnFIE_create_region_rect(97, 56, 330, 343); status = api.fnFIE_img_histogram(hsrc, hreg, iChaNo, ref unHist, ref iHistLen); // エラー判定. Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status); // 閾値の決定. status = api.fnFIE_calc_binarize_threshold(unHist, iHistLen, mode, ref threshold); // 確認. Console.WriteLine("fnFIE_calc_binarize_threshold"); for (int i = 0; i < iHistLen; i++) { Console.Write("{0},", unHist[i]); if (((i + 1) % 16) == 0) Console.WriteLine(""); } Console.WriteLine(""); Console.WriteLine("iHistLen={0}", iHistLen); Console.WriteLine("threshold={0}", threshold); } finally { // オブジェクトの開放. hsrc.Dispose(); hreg.Dispose(); unHist.Dispose(); } } } } |
Visual Basic | Copy |
---|---|
' $Revision: 1.1 $ Imports System.Collections.Generic Imports System.Text Imports fvalgcli Public Partial Class FIE <FvPluginExecute> _ Public Sub fnFIE_calc_binarize_threshold() Dim status As Integer = CInt(f_err.F_ERR_NONE) Dim hsrc As FHANDLE = FHANDLE.Zero ' 処理画像. Dim hreg As FHANDLE = FHANDLE.Zero ' リージョン. Dim iChaNo As Integer = 0 Dim unHist As UINT_PTR = UINT_PTR.Zero Dim iHistLen As Integer = 0 Dim mode As Integer = 0 ' 0:大津, 1:kittler Dim threshold As Integer = 0 Try ' 入力画像ファイルのロード. api.fnFIE_load_img_file(TestImageDir & "/testdata/colorg.bmp", hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8) ' ヒストグラム計測. hreg = api.fnFIE_create_region_rect(97, 56, 330, 343) status = api.fnFIE_img_histogram(hsrc, hreg, iChaNo, unHist, iHistLen) ' エラー判定. Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err)) ' 閾値の決定. status = api.fnFIE_calc_binarize_threshold(unHist, iHistLen, mode, threshold) ' 確認. Console.WriteLine("fnFIE_calc_binarize_threshold") For i As Integer = 0 To iHistLen - 1 Console.Write("{0},", unHist(i)) If ((i + 1) Mod 16) = 0 Then Console.WriteLine("") End If Next Console.WriteLine("") Console.WriteLine("iHistLen={0}", iHistLen) Console.WriteLine("threshold={0}", threshold) Finally ' オブジェクトの開放. hsrc.Dispose() hreg.Dispose() unHist.Dispose() End Try End Sub End Class |