NaN( 非数 )を数値に置き換える

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

Syntax

C#
public static int fnFIE_replace_nan(
	FHANDLE hsrc,
	FHANDLE hdst,
	double val
)
Visual Basic
Public Shared Function fnFIE_replace_nan ( 
	hsrc As FHANDLE,
	hdst As FHANDLE,
	val As Double
) As Integer

Parameters

hsrc
Type: fvalgcli..::..FHANDLE
入力画像ハンドル( type: double, float )
hdst
Type: fvalgcli..::..FHANDLE
出力画像ハンドル( type: double, float )
val
Type: System..::..Double
NaN を置き換える数値
DOUBLE 型で入力されます。 対象画像のタイプが F_IMG_FLOAT の場合は単純キャストされます。

Return Value

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

エラーコード:
f_err内容
F_ERR_NONE正常終了
F_ERR_INVALID_IMAGE不正な画像ハンドルが渡されたため、異常終了
F_ERR_NO_LICENCEライセンスエラー、または未初期化エラー

Examples

C# Copy imageCopy
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace TC
{
    public partial class FIE
    {
        // ============================================================
        /// <summary>
        /// NaN( 非数 )を数値に置き換える.
        /// </summary>
        [FvPluginExecute]
        public void fnFIE_replace_nan()
        {
            int status = (int)f_err.F_ERR_NONE;

            FHANDLE hsrc = FHANDLE.Zero;    // 入力画像.
            FHANDLE hdst = FHANDLE.Zero;    // 出力画像.

            try
            {
                const int width = 3;
                const int height = 2;

                // 領域確保.                
                hsrc = api.fnFIE_img_root_alloc(f_imgtype.F_IMG_DOUBLE, 1, width, height);
                hdst = api.fnFIE_img_root_alloc(f_imgtype.F_IMG_DOUBLE, 1, width, height);

                // テストデータの作成.
                {
                    DOUBLE_PTR psrc = api.fnFIE_img_get_adrs(hsrc);
                    var src_step = api.fnFIE_img_get_step(hsrc);
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            if (x % 2 == 0)
                                psrc[x] = Double.NaN;
                            else
                                psrc[x] = 0;
                        }
                        psrc += src_step;
                    }
                }

                // 実行.
                status = api.fnFIE_replace_nan(hsrc, hdst, 99.9);

                // 結果.
                {
                    int errors = 0;
                    DOUBLE_PTR pdst = api.fnFIE_img_get_adrs(hdst);
                    var dst_step = api.fnFIE_img_get_step(hdst);
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            if (x % 2 == 0)
                            {
                                if (pdst[x] != 99.9) errors++;
                            }
                            else
                            {
                                if (pdst[x] != 0.0) errors++;
                            }

                            Console.WriteLine("{0},{1}: {2,5:F2}", y, x, pdst[x]);
                        }
                        pdst += dst_step;
                    }
                    if (errors > 0)
                    {
                        Console.WriteLine("処理結果に誤りがあります。erros={0}", errors);
                    }
                }
            }
            finally
            {
                // オブジェクトの開放.
                hsrc.Dispose();
                hdst.Dispose();
            }
        }
    }
}


Visual Basic Copy imageCopy
Imports System.Collections.Generic
Imports System.Text
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Partial Public Class FIE
    ' ============================================================
    ''' <summary>
    ''' NaN( 非数 )を数値に置き換える.
    ''' </summary>
    <FvPluginExecute> _
    Public Sub fnFIE_replace_nan()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        ' 入力画像.
        Dim hsrc As FHANDLE = FHANDLE.Zero
        ' 出力画像.
        Dim hdst As FHANDLE = FHANDLE.Zero

        Try
            Const width As Integer = 3
            Const height As Integer = 2

            ' 領域確保.                
            hsrc = api.fnFIE_img_root_alloc(f_imgtype.F_IMG_DOUBLE, 1, width, height)
            hdst = api.fnFIE_img_root_alloc(f_imgtype.F_IMG_DOUBLE, 1, width, height)

            ' テストデータの作成.
            If True Then
                Dim psrc As DOUBLE_PTR = api.fnFIE_img_get_adrs(hsrc)
                Dim src_step As SIZE_T = api.fnFIE_img_get_step(hsrc)
                For y As Integer = 0 To height - 1
                    For x As Integer = 0 To width - 1
                        If x Mod 2 = 0 Then
                            psrc(x) = [Double].NaN
                        Else
                            psrc(x) = 0
                        End If
                    Next
                    psrc += src_step
                Next
            End If

            ' 実行.
            status = api.fnFIE_replace_nan(hsrc, hdst, 99.9)

            ' 結果.
            If True Then
                Dim errors As Integer = 0
                Dim pdst As DOUBLE_PTR = api.fnFIE_img_get_adrs(hdst)
                Dim dst_step As SIZE_T = api.fnFIE_img_get_step(hdst)
                For y As Integer = 0 To height - 1
                    For x As Integer = 0 To width - 1
                        If x Mod 2 = 0 Then
                            If pdst(x) <> 99.9 Then
                                errors += 1
                            End If
                        Else
                            If pdst(x) <> 0.0 Then
                                errors += 1
                            End If
                        End If

                        Console.WriteLine("{0},{1}: {2,5:F2}", y, x, pdst(x))
                    Next
                    pdst += dst_step
                Next
                If errors > 0 Then
                    Console.WriteLine("処理結果に誤りがあります。erros={0}", errors)
                End If
            End If
        Finally
            ' オブジェクトの開放.
            hsrc.Dispose()
            hdst.Dispose()
        End Try
    End Sub
End Class

See Also