同時生起行列を用いたエントロピーの算出

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

Syntax

C#
public static int fnFIE_texture_calc_gcm_entropy(
	FMATRIX_PTR mat,
	ref double entropy
)
Visual Basic
Public Shared Function fnFIE_texture_calc_gcm_entropy ( 
	mat As FMATRIX_PTR,
	ByRef entropy As Double
) As Integer

Parameters

mat
Type: fvalgcli..::..FMATRIX_PTR
同時生起行列
  • mat->row == mat->col
  • 0 < mat->row < 16384 かつ 0 < mat->col < 16384
  • mat->row を入力画像の階調数とする
entropy
Type: System..::..Double%
エントロピー

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_PARAM不正なパラメータが渡された
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
    {
        /// <summary>
        /// 同時生起行列を用いたエントロピーの算出.
        /// </summary>
        [FvPluginExecute]
        public void fnFIE_texture_calc_gcm_entropy()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE img = FHANDLE.Zero;        // 同時生起行列算出用の画像.
            FMATRIX_PTR mat = IntPtr.Zero;    // 同時生起行列.

            try
            {
                // テストケース.
                const int gray_level = 9;
                const int dx = 1;
                const int dy = 0;
                const int width = 4;
                const int height = 4;
                byte[,] img_data = new byte[width, height]
                {
                    {0, 1, 2, 0},
                    {3, 4, 5, 6},
                    {6, 7, 8, 6},
                    {1, 1, 3, 3}
                };
                const double ans_entropy = 3.0625293002546;

                // 同時生起行列算出用の画像を用意する.
                img = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 1, width, height);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        api.fnFIE_img_set_dens(img, 0, x, y, img_data[y, x]);
                    }
                }

                // 同時生起行列を確保、算出する.
                mat = api.fnFIE_mat_aalloc(gray_level, gray_level);
                api.fnFIE_texture_coocurrence_matrix(img, dx, dy, gray_level, mat);

                // 同時生起行列を用いたエントロピーの算出.
                double entropy = 0;                // エントロピー.
                status = api.fnFIE_texture_calc_gcm_entropy(mat, ref entropy);

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

                // 結果を出力する.
                ConsoleOut.WriteFunctionName(":\t");
                Console.Write("entropy = {0:f5} ...", entropy);
                ConsoleOut.IsTrue(DblEqual(entropy, ans_entropy));
            }
            finally
            {
                img.Dispose();
                mat.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

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

Public Partial Class FIE
    ''' <summary>
    ''' 同時生起行列を用いたエントロピーの算出.
    ''' </summary>
    <FvPluginExecute> _
    Public Sub fnFIE_texture_calc_gcm_entropy()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim img As FHANDLE = FHANDLE.Zero
        ' 同時生起行列算出用の画像.
        Dim mat As FMATRIX_PTR = IntPtr.Zero
        ' 同時生起行列.
        Try
            ' テストケース.
            Const  gray_level As Integer = 9
            Const  dx As Integer = 1
            Const  dy As Integer = 0
            Const  width As Integer = 4
            Const  height As Integer = 4
            Dim img_data As Byte(,) = New Byte(width - 1, height - 1) {{0, 1, 2, 0}, {3, 4, 5, 6}, {6, 7, 8, 6}, {1, 1, 3, 3}}
            Const  ans_entropy As Double = 3.0625293002546

            ' 同時生起行列算出用の画像を用意する.
            img = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 1, width, height)
            For y As Integer = 0 To height - 1
                For x As Integer = 0 To width - 1
                    api.fnFIE_img_set_dens(img, 0, x, y, img_data(y, x))
                Next
            Next

            ' 同時生起行列を確保、算出する.
            mat = api.fnFIE_mat_aalloc(gray_level, gray_level)
            api.fnFIE_texture_coocurrence_matrix(img, dx, dy, gray_level, mat)

            ' 同時生起行列を用いたエントロピーの算出.
            Dim entropy As Double = 0
            ' エントロピー.
            status = api.fnFIE_texture_calc_gcm_entropy(mat, entropy)

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

            ' 結果を出力する.
            ConsoleOut.WriteFunctionName(":" & vbTab)
            Console.Write("entropy = {0:f5} ...", entropy)
            ConsoleOut.IsTrue(DblEqual(entropy, ans_entropy))
        Finally
            img.Dispose()
            mat.Dispose()
        End Try
    End Sub
End Class

See Also