Mean-Shift 法による多値化

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

Syntax

C#
public static int fnFIE_meanshift_multithreshold(
	FHANDLE hsrc,
	FHANDLE hdst,
	ref INT_PTR thresh,
	ref int num_discrimination,
	double bandwidth,
	double union_thresh,
	int dst_mode
)
Visual Basic
Public Shared Function fnFIE_meanshift_multithreshold ( 
	hsrc As FHANDLE,
	hdst As FHANDLE,
	ByRef thresh As INT_PTR,
	ByRef num_discrimination As Integer,
	bandwidth As Double,
	union_thresh As Double,
	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%
多値化閾値結果格納バッファ。 関数へのエントリー時、内容が IntPtr.Zero でなければいけません。 関数内部で必要なメモリを確保してアドレスを返します。 不要になったら fnFIE_free_object() で解放してください。
  • num_discrimination が 1 以外の場合、thresh は、(num_discrimination - 1) 個分のメモリを確保し、閾値を格納します。
  • num_discrimination が 1 の場合は、要素1個分のメモリを確保し、入力画像が取りうる値の最小値を格納します。
num_discrimination
Type: System..::..Int32%
多値化の分割数。エントリ時は 0 で構いません。内部で計算された結果が格納されます。
bandwidth
Type: System..::..Double
カーネル幅 (0 < bandwidth) 大きくなるほど多値化の分割数が小さくなります。 また、収束値の差が bandwidth 以下の標本点は、同じクラスタと見なされます。つまり、dst_mode = 0 の場合、出力画像の出現濃度値の間隔は、bandwidth 以上が保証されます。
union_thresh
Type: System..::..Double
クラスタ統合閾値 (0 ≦ union_thresh ≦ 1) 所属する標本点数が union_thresh * (全体の画素数) 以下のクラスタを最も近いものに統合します。推奨値は、0.01 ~ 0.05 です。
dst_mode
Type: System..::..Int32
出力画像を生成する際の動作モード [0,1]
  • 0 : 出力値は、注目クラスタの Mean-Shift 収束値の平均を四捨五入した値。
  • 1 : 出力値は、入力画像 hsrc における画像タイプの濃度値範囲を num_discrimination で分割する際の等間隔値。
(hdst に IntPtr.Zero が指定された場合にはこの値は使用されません。)

Return Value

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

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

Examples

C# Copy imageCopy
using System;
using System.Collections.Generic;
using System.Text;
using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        [FvPluginExecute]
        public void fnFIE_meanshift_multithreshold()
        {
            int status = (int)f_err.F_ERR_NONE;

            for (int dst_mode = 0; dst_mode < 2; dst_mode++)
            {
                FHANDLE hsrc = FHANDLE.Zero;    // 処理画像.
                FHANDLE hdst = FHANDLE.Zero;    // 出力画像.
                INT_PTR thresholds = INT_PTR.Zero;
                int num_discrimination = 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);

                    // 処理の実行.
                    status = api.fnFIE_meanshift_multithreshold(hsrc, hdst, ref thresholds, ref num_discrimination, 5, 0.05, dst_mode);

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

                    // 出力画像の保存.
                    api.fnFIE_save_png(ResultDir + string.Format("/fnFIE_meanshift_multithreshold-{0}.png", dst_mode), hdst, -1);

                    if (num_discrimination == 1)
                    {
                        Console.WriteLine("fnFIE_meanshift_multithreshold: thresholds[{0}]={1}", 0, thresholds[0]);
                    }
                    else
                    {
                        for (int i = 0; i < num_discrimination-1; i++)
                            Console.WriteLine("fnFIE_meanshift_multithreshold: thresholds[{0}]={1}", i, thresholds[i]);
                    }
                }
                finally
                {
                    // オブジェクトの開放.
                    hsrc.Dispose();
                    hdst.Dispose();
                    thresholds.Dispose();
                }
            }
        }
    }
}


Visual Basic Copy imageCopy
Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli

Public Partial Class FIE
    <FvPluginExecute> _
    Public Sub fnFIE_meanshift_multithreshold()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        For dst_mode As Integer = 0 To 1
            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 = 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)

                ' 処理の実行.
                status = api.fnFIE_meanshift_multithreshold(hsrc, hdst, thresholds, num_discrimination, 5, 0.05, _
                    dst_mode)

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

                ' 出力画像の保存.
                api.fnFIE_save_png(ResultDir & String.Format("/fnFIE_meanshift_multithreshold-{0}.png", dst_mode), hdst, -1)

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

See Also