カーネルフィルターテンプレート。出力画像の各ピクセルに対し、入力画像で上下左右に範囲を持ったアクセスを行うカーネルフィルタに類似した空間フィルタを実施します。 フィルタの内容はユーザーが引数 pixel_func で自由に指定できます。

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

Syntax

C#
public static int fnFIE_img_filter_template_mxn(
	FHANDLE hsrc,
	FHANDLE hdst,
	F_TEMPLATE_FUNC_MxN pixel_func,
	IntPtr func_param,
	int border_left,
	int border_top,
	int border_right,
	int border_bottom,
	f_border_mode border_mode,
	double border_value
)
Visual Basic
Public Shared Function fnFIE_img_filter_template_mxn ( 
	hsrc As FHANDLE,
	hdst As FHANDLE,
	pixel_func As F_TEMPLATE_FUNC_MxN,
	func_param As IntPtr,
	border_left As Integer,
	border_top As Integer,
	border_right As Integer,
	border_bottom As Integer,
	border_mode As f_border_mode,
	border_value As Double
) As Integer

Parameters

hsrc
Type: fvalgcli..::..FHANDLE
入力画像ハンドル
hdst
Type: fvalgcli..::..FHANDLE
出力画像ハンドル
pixel_func
Type: fvalgcli..::..F_TEMPLATE_FUNC_MxN
1ピクセルだけ処理する内容を記述した関数のデリゲート
func_param
Type: System..::..IntPtr
オプションパラメータ。各画素で pixel_func が実行される際に参照できます。必要がなければ IntPtr.Zero を渡してください。
border_left
Type: System..::..Int32
pixel_func が左方向にアクセスするサイズ
border_top
Type: System..::..Int32
pixel_func が上方向にアクセスするサイズ
border_right
Type: System..::..Int32
pixel_func が右方向にアクセスするサイズ
border_bottom
Type: System..::..Int32
pixel_func が下方向にアクセスするサイズ
border_mode
Type: fvalgcli..::..f_border_mode
ボーダー処理モード
border_value
Type: System..::..Double
ボーダー濃度値。 border_mode が F_BORDER_VALUE の場合のみ使用されます。 その他のモードの場合は、この値は無視されます。

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
//    $Revision: 1.1 $

using System;
using System.Collections.Generic;
using System.Text;

using fvalgcli;

namespace TC
{
    public partial class FIE
    {
        /// <summary>
        /// 1画素単位フィルターテンプレート.
        /// </summary>
        [FvPluginExecute]
        public void fnFIE_img_filter_template_mxn()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE hSrc = FHANDLE.Zero;    // 処理対象画像.
            FHANDLE hDst = FHANDLE.Zero;    // 処理結果画像.

            try
            {
                // 処理対象画像のロード.
                api.fnFIE_load_bmp(TestImageDir + "/testdata/fast2.bmp", ref hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8);

                int channels = api.fnFIE_img_get_channels(hSrc);
                int type = api.fnFIE_img_get_type(hSrc);
                int width = api.fnFIE_img_get_width(hSrc);
                int height = api.fnFIE_img_get_height(hSrc);

                // 処理結果画像の確保.
                hDst = api.fnFIE_img_root_alloc(type, channels, width, height);

                // ピクセル処理関数のデリゲート.
                F_TEMPLATE_FUNC_MxN pixel_func = pixel_func_mxn;
                IntPtr func_param = IntPtr.Zero;

                int border = 2;

                // 処理の実行.
                status = api.fnFIE_img_filter_template_mxn(hSrc, hDst, pixel_func, func_param, border, border, border, border, f_border_mode.F_BORDER_NONE, 0.0);

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

                // 処理結果画像の保存.
                api.fnFIE_save_png(ResultDir + "/fnFIE_img_filter_template_mxn.png", hDst, -1);
            }
            finally
            {
                // オブジェクトの開放.
                hSrc.Dispose();
                hDst.Dispose();
            }
        }

        /// <summary>
        /// ピクセル処理関数.(UC8 のみ対応)
        /// </summary>
        /// <param name="src_pixel"></param>
        /// <param name="step"></param>
        /// <param name="dst_pixel"></param>
        /// <param name="param"></param>
        private void pixel_func_mxn(IntPtr src_pixel, SIZE_T step, IntPtr dst_pixel, IntPtr param)
        {
            // 注意) 簡素化の為、UC8 限定にしています.
            UCHAR_PTR src = src_pixel;
            UCHAR_PTR dst = dst_pixel;

            // 平滑化.(5x5)
            int width = step.ToInt32();
            int sum = 0;
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    sum += src[0 + (2 - y) * width + (2 - x)];
                }
            }

            dst[0] = (byte)(sum / 25);
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text

Imports fvalgcli

Public Partial Class FIE
    ''' <summary>
    ''' 1画素単位フィルターテンプレート.
    ''' </summary>
    <FvPluginExecute> _
    Public Sub fnFIE_img_filter_template_mxn()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim hSrc As FHANDLE = FHANDLE.Zero
        ' 処理対象画像.
        Dim hDst As FHANDLE = FHANDLE.Zero
        ' 処理結果画像.
        Try
            ' 処理対象画像のロード.
            api.fnFIE_load_bmp(TestImageDir & "/testdata/fast2.bmp", hSrc, f_color_img_type.F_COLOR_IMG_TYPE_UC8)

            Dim channels As Integer = api.fnFIE_img_get_channels(hSrc)
            Dim type As Integer = api.fnFIE_img_get_type(hSrc)
            Dim width As Integer = api.fnFIE_img_get_width(hSrc)
            Dim height As Integer = api.fnFIE_img_get_height(hSrc)

            ' 処理結果画像の確保.
            hDst = api.fnFIE_img_root_alloc(type, channels, width, height)

            ' ピクセル処理関数のデリゲート.
            Dim pixel_func As F_TEMPLATE_FUNC_MxN = AddressOf pixel_func_mxn
            Dim func_param As IntPtr = IntPtr.Zero

            Dim border As Integer = 2

            ' 処理の実行.
            status = api.fnFIE_img_filter_template_mxn(hSrc, hDst, pixel_func, func_param, border, border, _
                border, border, f_border_mode.F_BORDER_NONE, 0.0)

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

            ' 処理結果画像の保存.
            api.fnFIE_save_png(ResultDir & "/fnFIE_img_filter_template_mxn.png", hDst, -1)
        Finally
            ' オブジェクトの開放.
            hSrc.Dispose()
            hDst.Dispose()
        End Try
    End Sub

    ''' <summary>
    ''' ピクセル処理関数.(UC8 のみ対応)
    ''' </summary>
    ''' <param name="src_pixel"></param>
    ''' <param name="step"></param>
    ''' <param name="dst_pixel"></param>
    ''' <param name="param"></param>
    Private Sub pixel_func_mxn(src_pixel As IntPtr, [step] As SIZE_T, dst_pixel As IntPtr, param As IntPtr)
        ' 注意) 簡素化の為、UC8 限定にしています.
        Dim src As UCHAR_PTR = src_pixel
        Dim dst As UCHAR_PTR = dst_pixel

        ' 平滑化.(5x5)
        Dim width As Integer = [step].ToInt32()
        Dim sum As Integer = 0
        For y As Integer = 0 To 4
            For x As Integer = 0 To 4
                sum += src(0 + (2 - y) * width + (2 - x))
            Next
        Next

        dst(0) = CByte(sum \ 25)
    End Sub
End Class

See Also