キトラー(Kittler)法による多値化
Namespace: fvalgcliAssembly: 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 |
---|
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 |
---|
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