ダイレクト読み取りモードを使用して画像をIT部門に渡す
画像を直接渡す場合、 vararginパラメータには 2 つの追加のmxArrayが含まれます。1 つは適切な型 (符号付きまたは符号なしの 8、16、または 32 ビット整数) の画像データを含み、もう 1 つは画像をデコード (または再構築) するために必要な情報を含む JSON 形式のchar* です。
rawFileパラメータは、 mxCreateNumericMatrix()関数を使用して作成します。この関数には、行数 ( 1 )、画像配列のサイズ、データ形式を表す定数 ( mxINT8_CLASS 、 mxUINT8_CLASS 、 mxINT16_CLASS 、 mxUINT16_CLASS 、 mxINT32_CLASS 、またはmxUINT32_CLASSのいずれか)、および定数mxRealが渡されます。次に、 mxFree()を使用して元のデータを解放し、 setData()を呼び出して画像配列をmxArrayパラメータにコピーします。
vararginパラメータは、セル配列型のmxArrayです。配列を作成するにはmxCreateCellMatrix()を使用し、追加引数を追加するにはmxSetCell() を使用してください。
RGB および RAW 画像の場合、JSON オブジェクトには、画像の幅、高さ、 ncolors (色の数)、ファイルルート、および拡張子が含まれている必要があります。RAW 画像の場合は、 Read Rawユーティリティを使用して INI ファイルで構成された拡張子を使用します。それ以外の場合は、以下の表のオプションを参照してください。ファイルルートは、出力ファイルの書き込み場所と出力ファイル名を指定するために使用されます。次の C コードスニペットは、unsigned short型の画像配列と JSON メタデータ文字列をmlfBlemish_shell()関数に渡します。
unsigned short *rawPixels;
unsigned int pixelCount;
mxArray *outputJSON = NULL, *inputFile = NULL, *rootDir = NULL, *inputKeys = NULL, *opMode = NULL, *varargin = NULL, *imageData = NULL, *jsonData = NULL;
inputFile = mxCreateString("");
rootDir = mxCreateString("C:\ImatestSamples\");
opMode = mxCreateString("-15");
inputKeys = mxCreateString( "JSON");
jsonData = mxCreateString("{ "height": 1296, "width": 808, "ncolors": 1, "extension": "raw", "fileroot": "C:\ImatestSamples\blemish.raw"}}");
/// Load the image data from your source ...
imageData = mxCreateNumericMatrix(1, pixelCount, mxUINT16_CLASS, mxREAL );
mxFree((mxArray*)mxGetData(imageData));
mxSetData(imageData, rawPixels);
varargin = mxCreateCellMatrix(1, 2);
mxSetCell(varargin, 0, imageData);
mxSetCell(varargin, 1, jsonData);
mlfBlemish_shell(1, &outputJSON, inputFile, rootDir, inputKeys, opMode, varargin);opModeを-15 (デフォルトのINIファイルを使用)または-17 (INIファイルパスを渡す)に設定すると、呼び出し元のプログラムからImatest IT C++ライブラリに画像(処理済みのRGBまたはRAW)を直接渡すことができます。画像を直接渡す方法は、ファイルから読み込む方法よりも一般的に高速であり、速度が重要な大量テストには強く推奨されます。
画像を直接渡す場合、 vararginパラメータには 2 つの追加のmwArrayが含まれます。1 つは適切な型 (符号付きまたは符号なしの 8、16、または 32 ビット整数) の画像データを含み、もう 1 つは画像のデコード (または再構築) に必要な情報を含む JSON 形式の文字列です。
rawFileパラメータは、 mwArrayコンストラクタを使用して作成します。この際、画像配列のサイズ、 1 (1 次元配列の場合)、データ形式を表す定数 ( mxINT8_CLASS 、 mxUINT8_CLASS 、 mxINT16_CLASS 、 mxUINT16_CLASS 、 mxINT32_CLASS 、またはmxUINT32_CLASSのいずれか)、および定数mxReal を渡します。次に、 setData()関数を使用して、画像配列をmwArrayパラメータにコピーします。
vararginパラメータは、セル配列型のmwArrayです。Get ()関数とSet()関数を使用して、追加の引数を追加してください。
RGB および RAW 画像の場合、JSON オブジェクトには、画像の幅、高さ、 ncolors (色の数)、ファイルルート、および拡張子インジケータが含まれている必要があります。RAW 画像の場合は、 Read Rawユーティリティを使用して INI ファイルで構成された拡張子を使用します。それ以外の場合は、以下の表のオプションを参照してください。ファイルルートは、出力ファイルの書き込み場所と出力ファイル名を指定するために使用されます。次の C++ コードスニペットは、 unsigned short型の画像配列と JSON メタデータ文字列をblemish_shell()関数に渡します。
unsigned short *rawPixels;
unsigned int pixelCount;
/// Load the image data from your source here ...
const char *jsonOptionsStr = "{ "jstr": {"width": 1296,"height": 808,"ncolors": 1,"extension": "raw", "fileroot": "C:\ImatestSamples\blemish.raw"}}";
mwArray jsonOutput;
mwArray inputFile = mwArray("");
mwArray rootDir = mwArray("C:\ImatestSamples\");
mwArray inputKeys = mwArray("JSON");
mwArray opMode = mwArray("-15");
mwArray rawFile = mwArray(pixelCount, 1, mxUINT16_CLASS, mxREAL);
rawFile.SetData(rawPixels, pixelCount);
mwArray jsonOptions = mwArray(1,jsonOptionsStr);
mwArray varargin = mwArray(1,2,mxCELL_CLASS);
varargin.Get(1,1).Set(rawFile);
varargin.Get(1,2).Set(jsonOptions);
blemish_shell(1, jsonOutput, inputFile, rootDir, inputKeys, opMode, varargin);op_modeをImatestLibrary.DIRECT_READに設定すると、呼び出し元のプログラムからIT Pythonに画像(処理済みのRGBまたはRAW)を直接渡すことができます。画像を直接渡す方法は、ファイルから読み込む方法よりも一般的に高速であり、速度が重要な大量テストには強く推奨されます。
画像を直接渡す場合、 raw_dataパラメータには画像 (バイナリ文字列として渡され、ピクセルあたり 8、16、または 32 ビット)、またはarray.arrayオブジェクトとして渡され、データ型コードは 'B' (uint8)、'H' (uint16)、または 'I' (uint32) のいずれかです。json_args パラメータには、画像をデコード (または再構築) するために必要な情報を含むJSONオブジェクトが含まれます。
RGB および RAW 画像の場合、 json_argsオブジェクトには、画像の幅、高さ、 ncolors (色の数)、ファイル名、および拡張子インジケータが含まれている必要があります。RAW 画像の場合は、 Read Rawユーティリティを使用して INI ファイルで構成された拡張子を使用します。それ以外の場合は、以下の表のオプションを参照してください。ファイル名は、出力ファイルの書き込み場所と出力ファイル名を指定するために使用されます。次の Python スクリプトは、 ImatestLibrary.build_json_args()関数を使用してjson_args文字列を作成し、それを raw_data とともにblemish_json()関数に渡します。この例はやや不自然であることに注意してください。通常は、ディスクから画像を読み込むのではなく、 raw_dataストリームを他のソースから既に読み込んでいるはずです。
raw_data = None
/// Load your image data here...
raw_image_path = r'C:ImatestSamplesblemish.raw'
json_args = imatestLib.build_json_args(width=1296,
height=808,
ncolors=1,
extension='raw',
filename=raw_image_path)
result = imatestLib.blemish_json(input_file=None,
root_dir=root_dir,
op_mode=ImatestLibrary.OP_MODE_DIRECT_READ,
ini_file=ini_file,
raw_data=raw_data,
json_args=json_args)Images (processed RGB or RAW) can be passed directly from the calling program to the Imatest IT .NET Library. Passing images directly is generally much faster than reading them from files, and strongly recommended for speed-critical high-volume testing.
For direct image passing, use one of the following module method signatures:
string [module].JSON(string rootDir, byte[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, byte[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
string [module].JSON(string rootDir, ushort[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, ushort[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
string [module].JSON(string rootDir, uint[] inputBytes, DirectReadOptions directReadOptions)
string [module].JSON(string rootDir, uint[] inputBytes, DirectReadOptions directReadOptions, string iniFilePath)
[module].JSON(String rootDir, Byte() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, Byte() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
[module].JSON(String rootDir, UInt16() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, UInt16() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
[module].JSON(String rootDir, UInt32() inputBytes, DirectReadOptions directReadOptions) As String
[module].JSON(String rootDir, UInt32() inputBytes, DirectReadOptions directReadOptions, String iniFilePath) As String
The inputBytes parameter contains the image data of the appropriate type (unsigned 8, 16, or 32 bit integers), and the directReadOptions parameter is an object containing the information needed to decode (or reconstruct) the image.
For RGB and RAW images, the DirectReadOptions object must contain the image Width, Height, NumberOfColors, Filename, and Extension values. If it is a RAW image, then use the extension that has been configured in your INI file using the Read Raw utility, otherwise see the table below for options. The Filename property will be used to direct where to write output files, and what the output filenames will be. The following code snippet passes an image array of type byte and a DirectReadOptions object to the blemish_shell() function.
UInt16[] imageData;
// Load the image data from your source ...
DirectReadOptions directReadOptions = new DirectReadOptions();
directReadOptions.Width = 1296;
directReadOptions.Height = 808;
directReadOptions.Extension = "raw";
directReadOptions.Filename = "C:\ImatestSamples\blemish.raw";
directReadOptions.NumberOfColors = 1;
string rootDir = "C:\ImatestSamples\";
string resultJSON = itLib.Blemish.JSON(rootDir, imageData, directReadOptions);
Dim imageData As UInt16
' Load the image data from your source ...
Dim DirectReadOptions As DirectReadOptions
directReadOptions = New DirectReadOptions()
directReadOptions.Width = 1296
directReadOptions.Height = 808
directReadOptions.Extension = "raw"
directReadOptions.Filename = "C:\ImatestSamples\blemish.raw"
directReadOptions.NumberOfColors = 1
Dim rootDir = "C:\ImatestSamples\"
Dim resultJSON = itLib.Blemish.JSON(rootDir, imageData, directReadOptions)
JSON要素名 | 注記 | |
| 必須 | 身長 | 画像配列の行数。 |
| 幅 | 画像配列の列数。 | |
| ncolors | カラーチャンネルの数。ベイヤーRAW画像またはグレースケール画像を解析する場合は、1に設定してください。 | |
| 拡大 | 生画像配列の場合は、Imatest Masterの「Read Raw」設定ダイアログで定義されている拡張機能を使用します。それ以外の場合は、
注:行優先形式の方が一般的ですので、迷った場合はまずそちらを試してみてください。 注:モノクロの行優先データの場合は、「row_major_planar」を使用してください。 | |
| ファイルルート | 結果を保存するための完全な画像パス名(例:*.csv、*.png)。 | |
| オプションの合否出力 | 部品番号 | デバイスの部品番号を含む文字列。デフォルト値は「未入力」です。 |
| シリアルナンバー | デバイスのシリアル番号を含む文字列。デフォルト値は「未入力」です。 | |
| 駅 | 生産ステーション。デフォルトは空の文字列です。 | |
| オペレーター | 駅員。デフォルトは空文字列です。 | |
| 名前 | このフィールドは、値が入力されている場合にのみ、合否結果の出力に表示されます。 | |
| 手術 | このフィールドは、値が入力されている場合にのみ、合否結果の出力に表示されます。 | |
| 状態 | このフィールドは、値が入力されている場合にのみ、合否結果の出力に表示されます。 | |
| オプションの INI オーバーライド [SFRplus のみ] | クロップボーダー | 除外する画像の境界をピクセル単位で定義する整数配列([左、右、上、下]) |
| レンズからチャートまでの距離(cm) | レンズからチャートまでの距離をセンチメートル単位で示すスカラー倍。 | |
| チャートの高さ(cm) | チャートの高さをセンチメートル単位で示すスカラー倍精度浮動小数点数。 | |
| オプションのINI上書き設定(Blemishのみ) | ホットピクセルタイプ | ホットピクセルのしきい値の種類を示すスカラー整数。1 はしきい値なし、2 は絶対値、3 はパーセンテージを表します。 |
| デッドピクセルタイプ | デッドピクセルのしきい値の種類を示すスカラー整数。1 はしきい値なし、2 は絶対値、3 はパーセンテージを表します。 | |
| ホットピクセルしきい値 | ホットピクセルの閾値を[絶対閾値、パーセンテージ閾値]の形式で格納した2要素配列。 | |
| デッドピクセルしきい値 | デッドピクセルのしきい値を[絶対しきい値、パーセントしきい値]の形式で格納した2要素配列。 | |
| 傷の分析 | ニキビ分析のオン/オフを切り替えるブール値フラグ。1に設定するとニキビ分析が有効になり、0に設定すると無効になります。 | |
| 均一性分析 | 均一性分析のオン/オフを切り替えるブール値フラグ。1に設定すると欠陥分析が有効になり、0に設定すると無効になります。 | |
| オプションの診断項目 | 画像を表示する | 指定された画像を読み込んで必要に応じてデコードした後で表示するブール値フラグ。true(または1)に設定すると表示されます。 |