ヒストグラムからの多値化閾値決定

Namespace: fvalgcli
Assembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)

Syntax

C#
public static int fnFIE_calc_multi_threshold(
	UINT_PTR data_hist,
	int size_hist,
	int mode,
	int num_discrimination,
	INT_PTR thresh
)
Visual Basic
Public Shared Function fnFIE_calc_multi_threshold ( 
	data_hist As UINT_PTR,
	size_hist As Integer,
	mode As Integer,
	num_discrimination As Integer,
	thresh As INT_PTR
) As Integer

Parameters

data_hist
Type: fvalgcli..::..UINT_PTR
ヒストグラムへのポインタ
size_hist
Type: System..::..Int32
data_hist の配列の長さ。[3~]
mode
Type: System..::..Int32
閾値決定手法 [0:大津の方法, 1:kittlerの方法]
num_discrimination
Type: System..::..Int32
多値化の分割数 [2≦num_discrimination≦size_hist]
thresh
Type: fvalgcli..::..INT_PTR
多値化閾値結果格納バッファ。閾値の格納用に (num_discrimination-1) 個のメモリを確保しておいてください。

Return Value

Type: Int32
以下のエラーコードを返します。

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_PARAMパラメータ不正
F_ERR_CALC_IMPOSSIBLE計算不能エラー
F_ERR_NO_LICENCEライセンスエラー、または未初期化エラー

Examples

C# Copy imageCopy
//    $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_multi_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 num = 5;
            INT_PTR thresholds = IntPtr.Zero;

            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);

                // 閾値格納用バッファの確保.
                thresholds = INT_PTR.alloc(num);

                // 閾値の決定.
                status = api.fnFIE_calc_multi_threshold(unHist, iHistLen, mode, num, thresholds);

                // 確認.
                Console.WriteLine("fnFIE_calc_multi_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);
                for (int i = 0; i < num; i++)
                    Console.WriteLine("thresholds[{0}]={1}", i, thresholds[i]);
            }
            finally
            {
                // オブジェクトの開放.
                hsrc.Dispose();
                hreg.Dispose();
                unHist.Dispose();
                thresholds.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli

Public Partial Class FIE
    <FvPluginExecute> _
    Public Sub fnFIE_calc_multi_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 num As Integer = 5
        Dim thresholds As INT_PTR = IntPtr.Zero

        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))

            ' 閾値格納用バッファの確保.
            thresholds = INT_PTR.alloc(num)

            ' 閾値の決定.
            status = api.fnFIE_calc_multi_threshold(unHist, iHistLen, mode, num, thresholds)

            ' 確認.
            Console.WriteLine("fnFIE_calc_multi_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)
            For i As Integer = 0 To num - 1
                Console.WriteLine("thresholds[{0}]={1}", i, thresholds(i))
            Next
        Finally
            ' オブジェクトの開放.
            hsrc.Dispose()
            hreg.Dispose()
            unHist.Dispose()
            thresholds.Dispose()
        End Try
    End Sub
End Class

See Also