キトラー(kittler)法による画像2値化

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

Syntax

C#
public static int fnFIE_kittler_threshold(
	FHANDLE hSrc,
	FHANDLE hDst,
	INT_PTR ipThresh
)
Visual Basic
Public Shared Function fnFIE_kittler_threshold ( 
	hSrc As FHANDLE,
	hDst As FHANDLE,
	ipThresh As INT_PTR
) As Integer

Parameters

hSrc
Type: fvalgcli..::..FHANDLE
入力画像 (type: uc8, us16, s16)
hDst
Type: fvalgcli..::..FHANDLE
出力画像 (type: bin)
ipThresh
Type: fvalgcli..::..INT_PTR
各チャネルの閾値

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

            FHANDLE hsrc = FHANDLE.Zero;    // 処理画像.
            FHANDLE hdst = FHANDLE.Zero;    // 出力画像.
            INT_PTR thresholds = INT_PTR.Zero;

            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 = (int)f_imgtype.F_IMG_BIN;

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

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

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

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

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

                for (int i = 0; i < channels; i++)
                    Console.WriteLine("fnFIE_kittler_threshold: 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_threshold()
        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

        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 = CInt(f_imgtype.F_IMG_BIN)

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

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

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

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

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

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

See Also