2値化クラス(バンド閾値指定)
Namespace: FVIL.ConversionAssembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)
Syntax
C# |
---|
[SerializableAttribute] public class CFviBinarizeBandThreshold : CFviConversion |
Visual Basic |
---|
<SerializableAttribute> Public Class CFviBinarizeBandThreshold Inherits CFviConversion |
Remarks
マルチコア対応:
このクラスの Execute()()()() メソッドは、 SetParallelNum(Int32) によって設定されたスレッド数に従って、 自動的に処理を並列化します。 マルチコア環境においては、処理を並列化する事によりレーテンシを短縮できる場合があります。 詳しくは、 SetParallelNum(Int32) の説明をご参照ください。
2つの固定閾値を指定して画像データの2値化を行うクラスです。
指定された濃淡画像を2値画像へ変換します。
2値化は、濃淡画像の濃度値を X とした時、
- (ThresholdL ≦ X && X ≦ ThresholdH ) : 1
- (ThresholdL > X || X > ThresholdH ) : 0
閾値パラメータ ThresholdL
と ThresholdH
は、判定時に画像の型に合わせてキャストされた後に評価されます。
キャストを行う前に下記の範囲チェックを行い、条件を満たしていない場合はエラーとなります。
- ThresholdL が型の表現可能な範囲の上限以下である事
- ThresholdH が型の表現可能な範囲の下限以上である事
- ThresholdL と ThresholdH の何れかが型の表現可能な範囲内にある事
下記の条件は無視されます。
- ThresholdL が型の表現可能な範囲の下限を下回っている場合
- ThresholdH が型の表現可能な範囲の上限を超えている場合
例えば、入力画像の型が FVIL::ImageType::UC8 であれば、その下限と上限は 0 と 255 である為、下記のような処理を行います。
要求する入出力画像数:
項目 | 数 | 定数 |
---|---|---|
入力画像 | 1 | SrcImageCount フィールド |
出力画像 | 1 | DstImageCount フィールド |
処理対象画像の条件:
処理対象の画像は下記の条件を満たしている必要が有ります。
- 入出力画像の処理範囲のサイズが等しい事
- 入出力画像のチャネル数が等しい事
- 入力画像の画像種別
-
出力画像の画像種別
- ImageType.BIN
初期値と範囲:
プロパティ | 初期値 | 範囲 |
---|---|---|
ThresholdH | 0.0 | 処理対象画像の画像種別と上下限閾値に矛盾があった場合は、 Execute()()()() メソッドで実行する際にエラーとなります。 |
ThresholdL | 0.0 | 処理対象画像の画像種別と上下限閾値に矛盾があった場合は、 Execute()()()() メソッドで実行する際にエラーとなります。 |
Examples
【入力画像】 | 【出力画像】 | |
ソースコード:
C# | Copy |
---|---|
// $Revision: 1.3 $ using System; using System.Collections.Generic; using System.Text; using System.Drawing; using fvalgcli; // FvPluginXXXX attribute requires fvalgcli namespace User.SampleCode { public partial class Conversion { // ============================================================ /// <summary> /// 2値化クラス(バンド閾値指定) /// </summary> [FvPluginExecute] public void BinarizeBandThreshold() { // 1) インスタンスの準備. FVIL.Conversion.CFviBinarizeBandThreshold parser = new FVIL.Conversion.CFviBinarizeBandThreshold(); FVIL.Data.CFviImage src = new FVIL.Data.CFviImage(); FVIL.Data.CFviImage dst = new FVIL.Data.CFviImage(); // 2) 処理対象画像の取り込み. FVIL.File.Function.LoadImageFile(Defs.TestImageDir + "/book3_UC8.png", src, FVIL.PixelMode.Unpacking); // 3) 処理対象画像の有効性検査. int valid = FVIL.Conversion.CFviBinarizeBandThreshold.CheckValidity(src); if (valid != FVIL.ErrorCode._SUCCESS) throw new FVIL.CFviException(valid, "FVIL.Conversion.CFviBinarizeBandThreshold.CheckValidity"); // 4) 画像処理準備 (共通) parser.SrcImages[0] = src; parser.DstImages[0] = dst; if (!parser.IsValid()) // 有効性検査. parser.Validate(); // 有効化. // 5) パラメータ設定 (固有) parser.ThresholdL = 128; parser.ThresholdH = 255; // 6) 画像処理実行. parser.Execute(); // E) 処理結果画像の保存. FVIL.File.Function.SaveImageFile(Defs.ResultDir + "/Conversion.BinarizeBandThreshold.png", dst); } } } |
Visual Basic | Copy |
---|---|
' $Revision: 1.1 $ Imports System.Collections.Generic Imports System.Text Imports System.Drawing Imports fvalgcli ' FvPluginXXXX attribute requires fvalgcli Namespace SampleCode Public Partial Class Conversion ' ============================================================ ''' <summary> ''' 2値化クラス(バンド閾値指定) ''' </summary> <FvPluginExecute> _ Public Sub BinarizeBandThreshold() ' 1) インスタンスの準備. Dim parser As New FVIL.Conversion.CFviBinarizeBandThreshold() Dim src As New FVIL.Data.CFviImage() Dim dst As New FVIL.Data.CFviImage() ' 2) 処理対象画像の取り込み. FVIL.File.[Function].LoadImageFile(Defs.TestImageDir & "/book3_UC8.png", src, FVIL.PixelMode.Unpacking) ' 3) 処理対象画像の有効性検査. Dim valid As Integer = FVIL.Conversion.CFviBinarizeBandThreshold.CheckValidity(src) If valid <> FVIL.ErrorCode._SUCCESS Then Throw New FVIL.CFviException(valid, "FVIL.Conversion.CFviBinarizeBandThreshold.CheckValidity") End If ' 4) 画像処理準備 (共通) parser.SrcImages(0) = src parser.DstImages(0) = dst If Not parser.IsValid() Then ' 有効性検査. parser.Validate() End If ' 有効化. ' 5) パラメータ設定 (固有) parser.ThresholdL = 128 parser.ThresholdH = 255 ' 6) 画像処理実行. parser.Execute() ' E) 処理結果画像の保存. FVIL.File.[Function].SaveImageFile(Defs.ResultDir & "/Conversion.BinarizeBandThreshold.png", dst) End Sub End Class End Namespace |
Inheritance Hierarchy
System..::..Object
FVIL..::..CFviObject
FVIL..::..CFviImageParser
FVIL.Conversion..::..CFviConversion
FVIL.Conversion..::..CFviBinarizeBandThreshold
FVIL..::..CFviObject
FVIL..::..CFviImageParser
FVIL.Conversion..::..CFviConversion
FVIL.Conversion..::..CFviBinarizeBandThreshold