キトラー(Kittler)法による多値化

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

Syntax

C#
public static int fnFIE_kittler_multithreshold(
	FHANDLE hsrc,
	FHANDLE hdst,
	INT_PTR thresh,
	int num_discrimination,
	int dst_mode
)
Visual Basic
Public Shared Function fnFIE_kittler_multithreshold ( 
	hsrc As FHANDLE,
	hdst As FHANDLE,
	thresh As INT_PTR,
	num_discrimination As Integer,
	dst_mode As Integer
) As Integer

Parameters

hsrc
Type: fvalgcli..::..FHANDLE
入力画像オブジェクト(type:uc8,us16,s16 and ch:1)
hdst
Type: fvalgcli..::..FHANDLE
結果格納用画像オブジェクト。入力画像オブジェクトと同じ画像タイプ、サイズであること。出力画像が必要でない場合には IntPtr.Zero を指定可能です。
thresh
Type: fvalgcli..::..INT_PTR
多値化閾値結果格納バッファ。閾値の格納用に num_discrimination -1 個のメモリを確保しておいてください。閾値が必要でない場合には IntPtr.Zero を指定可能です。
num_discrimination
Type: System..::..Int32
多値化の分割数(2 ≦ num_discrimination ≦ 入力画像の持つ階調数) ただし、画像の階調数/2 よりも大きな値を指定すると計算不可能になってしまいますので、F_ERR_CALC_IMPOSSIBLE を返します。
dst_mode
Type: System..::..Int32
出力画像を生成する際の各区間の値を決定する動作モード(hdst に IntPtr.Zero が指定された場合にはこの値は使用されません)
  • 0:出力値は、入力画像 hsrc のヒストグラムについて、thresh の各区間に存在する値の重み付き平均値
  • 1:出力値は、入力画像 hsrc における画像タイプの濃度値範囲を num_discrimination で分割する際の等間隔値

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_NOMEMORYメモリ不足エラー
F_ERR_INVALID_IMAGE画像オブジェクトの異常
F_ERR_INVALID_PARAMパラメータ異常
F_ERR_CALC_IMPOSSIBLE計算が出来ない
F_ERR_NO_LICENCEライセンスエラー

Remarks

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_kittler_multithreshold()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE hsrc = FHANDLE.Zero;    // 処理画像.
            FHANDLE hdst = FHANDLE.Zero;    // 出力画像.
            INT_PTR thresholds = INT_PTR.Zero;
            int num_discrimination = 3;
            int dst_mode = 0;

            try
            {
                // 入力画像ファイルのロード.
                api.fnFIE_load_img_file(TestImageDir + "/testdata/gray_04.bmp", ref hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8);

                // 入力画像の情報取得.
                int width = api.fnFIE_img_get_width(hsrc);
                int height = api.fnFIE_img_get_height(hsrc);
                int channels = api.fnFIE_img_get_channels(hsrc);
                int type = api.fnFIE_img_get_type(hsrc);

                // 出力画像の生成.
                hdst = api.fnFIE_img_root_alloc(type, channels, width, height);

                // 閾値.
                thresholds = INT_PTR.alloc(num_discrimination);

                // 処理の実行.
                status = api.fnFIE_kittler_multithreshold(hsrc, hdst, thresholds, num_discrimination, dst_mode);

                // エラー判定.
                Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status);

                // 出力画像の保存.
                api.fnFIE_save_png(ResultDir + "/fnFIE_kittler_multithreshold.png", hdst, -1);

                for (int i = 0; i < num_discrimination; i++)
                    Console.WriteLine("fnFIE_kittler_multithreshold: thresholds[{0}]={1}", i, thresholds[i]);
            }
            finally
            {
                // オブジェクトの開放.
                hsrc.Dispose();
                hdst.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_kittler_multithreshold()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim hsrc As FHANDLE = FHANDLE.Zero
        ' 処理画像.
        Dim hdst As FHANDLE = FHANDLE.Zero
        ' 出力画像.
        Dim thresholds As INT_PTR = INT_PTR.Zero
        Dim num_discrimination As Integer = 3
        Dim dst_mode As Integer = 0

        Try
            ' 入力画像ファイルのロード.
            api.fnFIE_load_img_file(TestImageDir & "/testdata/gray_04.bmp", hsrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8)

            ' 入力画像の情報取得.
            Dim width As Integer = api.fnFIE_img_get_width(hsrc)
            Dim height As Integer = api.fnFIE_img_get_height(hsrc)
            Dim channels As Integer = api.fnFIE_img_get_channels(hsrc)
            Dim type As Integer = api.fnFIE_img_get_type(hsrc)

            ' 出力画像の生成.
            hdst = api.fnFIE_img_root_alloc(type, channels, width, height)

            ' 閾値.
            thresholds = INT_PTR.alloc(num_discrimination)

            ' 処理の実行.
            status = api.fnFIE_kittler_multithreshold(hsrc, hdst, thresholds, num_discrimination, dst_mode)

            ' エラー判定.
            Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err))

            ' 出力画像の保存.
            api.fnFIE_save_png(ResultDir & "/fnFIE_kittler_multithreshold.png", hdst, -1)

            For i As Integer = 0 To num_discrimination - 1
                Console.WriteLine("fnFIE_kittler_multithreshold: thresholds[{0}]={1}", i, thresholds(i))
            Next
        Finally
            ' オブジェクトの開放.
            hsrc.Dispose()
            hdst.Dispose()
            thresholds.Dispose()
        End Try
    End Sub
End Class

See Also