構造要素指定 constrained hit-or-miss

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

Syntax

C#
public static int fnFIE_morphology_CHMT(
	FHANDLE hsrc_img,
	FHANDLE hdst_img,
	FHANDLE hse_FG,
	FHANDLE hse_BG
)
Visual Basic
Public Shared Function fnFIE_morphology_CHMT ( 
	hsrc_img As FHANDLE,
	hdst_img As FHANDLE,
	hse_FG As FHANDLE,
	hse_BG As FHANDLE
) As Integer

Parameters

hsrc_img
Type: fvalgcli..::..FHANDLE
処理対象画像( type: uc8, s16, us16, double )
hdst_img
Type: fvalgcli..::..FHANDLE
処理結果画像( type: uc8, s16, us16, double )
hse_FG
Type: fvalgcli..::..FHANDLE
値が1の画素に対応する構造要素のハンドル
hse_BG
Type: fvalgcli..::..FHANDLE
値が0の画素に対応する構造要素のハンドル

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_IMAGE不正な画像ハンドルが渡されたため、異常終了
F_ERR_INVALID_OBJECT 構造要素に不正なハンドルが指定されたため異常終了
F_ERR_NOMEMORYメモリ不足で確保に失敗した
F_ERR_NO_LICENCEライセンスエラー、または未初期化エラー

Examples

C# Copy imageCopy
//    $Revision: 1.1 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        /// <summary>
        /// 構造要素指定 constrained hit-or-miss.
        /// </summary>
        [FvPluginExecute]
        public void fnFIE_morphology_CHMT()
        {
            int status = (int)f_err.F_ERR_NONE;

            const int height_r = 256;
            const int width_r2 = 341;
            const int height = 10;
            const int width = 11;
            FHANDLE himg1 = FHANDLE.Zero;
            FHANDLE himg2 = FHANDLE.Zero;
            FHANDLE himg3 = FHANDLE.Zero;
            FHANDLE himg4 = FHANDLE.Zero;
            FHANDLE hc2 = FHANDLE.Zero;
            FHANDLE hFG = FHANDLE.Zero;
            FHANDLE hBG = FHANDLE.Zero;
            FHANDLE pp = FHANDLE.Zero;
            UCHAR_PTR ucFG = IntPtr.Zero;
            UCHAR_PTR ucBG = IntPtr.Zero;
            int x, y, i;
            SIZE_T step;

            try
            {
                byte[] ptrn1 =
                {
                    0,0,0,0,0,1,0,0,1,0,0, //0
                    0,0,0,0,1,1,1,0,1,0,0, //1
                    0,0,0,1,1,1,1,1,1,0,0, //2
                    0,0,1,1,1,1,1,1,1,0,0, //3
                    0,1,1,1,1,1,1,1,1,1,0, //4
                    1,1,1,1,1,1,1,1,1,1,1, //5
                    0,0,1,0,0,0,0,0,1,0,0, //6
                    0,0,1,0,0,0,0,0,1,0,0, //7
                    0,0,1,0,0,0,0,0,1,0,0, //8
                    0,0,1,1,1,1,1,1,1,0,0  //9
                };

                byte[] ptrn2 = new byte[ptrn1.Length];
                for (i = 0; i < width * height; i++)
                    ptrn2[i] = (byte)((ptrn1[i] == 1) ? 0 : 1);

                // 入力用画像の生成.
                himg1 = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 1, 256, 256);
                himg2 = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 1, width_r2, height_r);
                himg3 = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 1, 256, 256);
                himg4 = api.fnFIE_img_root_alloc((int)f_imgtype.F_IMG_UC8, 1, width, height);
                hc2 = api.fnFIE_img_child_alloc(himg2, 0, 0, 256, 256);

                UCHAR_PTR pntr = api.fnFIE_img_get_adrs(himg4);
                step = api.fnFIE_img_get_step(himg4);
                for (y = 0; y < height; y++)
                    for (x = 0; x < width; x++)
                        pntr[x + y * step] = ptrn1[x + y * width];

                api.fnFIE_copy_border(himg4, himg3, 0, 0, f_border_mode.F_BORDER_MIRROR2, 0);
                api.fnFIE_img_copy(himg3, himg1);

                // アンマネージアドレスの取得.
                ucFG = Marshal.UnsafeAddrOfPinnedArrayElement(ptrn1, 0);
                ucBG = Marshal.UnsafeAddrOfPinnedArrayElement(ptrn2, 0);

                // 構造要素の生成.
                hFG = api.fnFIE_morphology_se_alloc(ucFG, width, height, width, 5, 4);
                hBG = api.fnFIE_morphology_se_alloc(ucBG, width, height, width, 5, 4);

                // 処理の実行.
                status = api.fnFIE_morphology_CHMT(himg1, hc2, hFG, hBG);

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

                // 出力画像の保存.
                api.fnFIE_save_png(ResultDir + "/fnFIE_morphology_CHMT.png", hc2, -1);
            }
            finally
            {
                // オブジェクトの開放.
                himg1.Dispose();
                himg2.Dispose();
                himg3.Dispose();
                himg4.Dispose();
                hFG.Dispose();
                hBG.Dispose();
                hc2.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports fvalgcli

Public Partial Class FIE
    ''' <summary>
    ''' 構造要素指定 constrained hit-or-miss.
    ''' </summary>
    <FvPluginExecute> _
    Public Sub fnFIE_morphology_CHMT()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Const  height_r As Integer = 256
        Const  width_r2 As Integer = 341
        Const  height As Integer = 10
        Const  width As Integer = 11
        Dim himg1 As FHANDLE = FHANDLE.Zero
        Dim himg2 As FHANDLE = FHANDLE.Zero
        Dim himg3 As FHANDLE = FHANDLE.Zero
        Dim himg4 As FHANDLE = FHANDLE.Zero
        Dim hc2 As FHANDLE = FHANDLE.Zero
        Dim hFG As FHANDLE = FHANDLE.Zero
        Dim hBG As FHANDLE = FHANDLE.Zero
        Dim pp As FHANDLE = FHANDLE.Zero
        Dim ucFG As UCHAR_PTR = IntPtr.Zero
        Dim ucBG As UCHAR_PTR = IntPtr.Zero
        Dim x As Integer, y As Integer, i As Integer
        Dim [step] As SIZE_T

        Try
            '0
            '1
            '2
            '3
            '4
            '5
            '6
            '7
            '8
                '9
            Dim ptrn1 As Byte() = {0, 0, 0, 0, 0, 1, _
                0, 0, 1, 0, 0, 0, _
                0, 0, 0, 1, 1, 1, _
                0, 1, 0, 0, 0, 0, _
                0, 1, 1, 1, 1, 1, _
                1, 0, 0, 0, 0, 1, _
                1, 1, 1, 1, 1, 1, _
                0, 0, 0, 1, 1, 1, _
                1, 1, 1, 1, 1, 1, _
                0, 1, 1, 1, 1, 1, _
                1, 1, 1, 1, 1, 1, _
                0, 0, 1, 0, 0, 0, _
                0, 0, 1, 0, 0, 0, _
                0, 1, 0, 0, 0, 0, _
                0, 1, 0, 0, 0, 0, _
                1, 0, 0, 0, 0, 0, _
                1, 0, 0, 0, 0, 1, _
                1, 1, 1, 1, 1, 1, _
                0, 0}

            Dim ptrn2 As Byte() = New Byte(ptrn1.Length - 1) {}
            For i = 0 To width * height - 1
                ptrn2(i) = CByte(If((ptrn1(i) = 1), 0, 1))
            Next

            ' 入力用画像の生成.
            himg1 = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 1, 256, 256)
            himg2 = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 1, width_r2, height_r)
            himg3 = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 1, 256, 256)
            himg4 = api.fnFIE_img_root_alloc(CInt(f_imgtype.F_IMG_UC8), 1, width, height)
            hc2 = api.fnFIE_img_child_alloc(himg2, 0, 0, 256, 256)

            Dim pntr As UCHAR_PTR = api.fnFIE_img_get_adrs(himg4)
            [step] = api.fnFIE_img_get_step(himg4)
            For y = 0 To height - 1
                For x = 0 To width - 1
                    pntr(x) = ptrn1(x + y * width)
                Next
                pntr += [step].ToInt64()
            Next

            api.fnFIE_copy_border(himg4, himg3, 0, 0, f_border_mode.F_BORDER_MIRROR2, 0)
            api.fnFIE_img_copy(himg3, himg1)

            ' アンマネージアドレスの取得.
            ucFG = Marshal.UnsafeAddrOfPinnedArrayElement(ptrn1, 0)
            ucBG = Marshal.UnsafeAddrOfPinnedArrayElement(ptrn2, 0)

            ' 構造要素の生成.
            hFG = api.fnFIE_morphology_se_alloc(ucFG, width, height, width, 5, 4)
            hBG = api.fnFIE_morphology_se_alloc(ucBG, width, height, width, 5, 4)

            ' 処理の実行.
            status = api.fnFIE_morphology_CHMT(himg1, hc2, hFG, hBG)

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

            ' 出力画像の保存.
            api.fnFIE_save_png(ResultDir & "/fnFIE_morphology_CHMT.png", hc2, -1)
        Finally
            ' オブジェクトの開放.
            himg1.Dispose()
            himg2.Dispose()
            himg3.Dispose()
            himg4.Dispose()
            hFG.Dispose()
            hBG.Dispose()
            hc2.Dispose()
        End Try
    End Sub
End Class

See Also