Imatest ITとPythonを使用したCPIQ分析の自動化

Imatest ITのPythonインターフェースを使用すると、Imatestのテストを簡単に実行できます。この記事では、Imatestの実行を自動化し、テスト結果を収集して簡単に処理する方法を紹介します。この例では、3つのライトレベルで5つのImatestモジュールを実行し、 CPIQ品質損失メトリクスを抽出します。

開発環境のセットアップ

画像コレクション

各デバイスについて、異なる照度レベルで様々なテストチャートの画像を撮影します。(注:詳細については、2017年3月に規格が公開される際にお知らせします。)

すべてのテストを実行中

これらの画像を「DeviceX」という名前のフォルダに収集したら、照明条件を定義し、Imatest ITライブラリを初期化して、このデバイスと他のいくつかのデバイスに対して処理関数を実行します。

led5k = "5000KLED_1000lux"               # Light Levels
tl84 = "TL84_100lux"
tung = "Tung_10lux"
light_conditions = [led5k, tl84, tung]
imatest = ImatestLibrary()
phones = ['DeviceX',                     # Just for example...
          'DeviceY',
          'DeviceZ']
for phone in phones:
    calc_phone(phone)
 
imatest.terminate_library()

メイン処理スクリプトは、5つのモジュールを呼び出し、それらのデータ出力を収集してJSONファイルに保存します。

def calc_phone(phone):
    print('Calculating Metrics for '+phone+ ' *****************************')
    uniformity_results = uniformity(phone) # Uniformity
    multitest_results  = multitest(phone) # Multitest
    dotpattern_results = dotpattern(phone) # Dot Pattern
    esfriso_results    = esfriso(phone) # eSFR ISO
    random_results     = random(phone) # Random
 
    # Output data to disk
    file_name = os.path.join(images_dir, phone, phone + '.json')
    with open(file_name, 'w') as outfile:
        full_data = {'multitest'  : multitest_results,
                     'dotpattern' : dotpattern_results,
                     'esfriso' : esfriso_results,
                     'random' : random_results,
                     'uniformity' : uniformity_results}
        json.dump(full_data, outfile, indent=4, separators=(',',': '))
 
    return full_data

各照明条件ごとに、Imatest eSFR ISOモジュールを呼び出します。

# eSFR ISO (ISO 12233:2014) is used to test Visual Noise (VN) 
# and Spatial Frequency Response (SFR)
def esfriso(base):
    global images_dir, ini_file, light_conditions, op_mode
    output = {}
    for light_source in light_conditions:
        print('Testing ' + base + ' eSFR ISO at ' + light_source)
        input_file = os.path.join(images_dir, base, base+'_eSFR_'+light_source+'.jpg')
        if os.path.exists(input_file) != True:
            raise Exception('File ' + input_file + 'not found!')
        print('opening ' + input_file)
        result = imatest.esfriso_json(input_file=input_file, root_dir=root_dir, 
                                      op_mode=op_mode, ini_file=ini_file)
        data = json.loads(result)
        output[light_source] = data['esfrisoResults'];
 
return output

INIファイルのオンザフライ変更

この処理で最も難しいのは、Multitest への呼び出しの領域選択を手動で更新することです。Multitest には、Colorchecker SG ターゲットの自動領域検出機能がまだありません (近日中に実装予定)。

この場合、[sg] roi、nwid_save、およびnht_saveキーを、このmulticharts-rois.jsonファイルに格納されている値に置き換えます。

{
"DeviceX_SG_5000KLED_1000lux.JPG": "468 417 2122 1578 468 1588 2102 397",
"DeviceX_SG_TL84_100lux.JPG":"482 376 2142 1571 482 1561 2157 376",
"DeviceX_SG_Tung_10lux.JPG":"386 336 2016 1492 401 1497 2021 321",
"width":"2592",
"height":"1936"
}

このスクリプトを使用してINIファイルを変更し、さまざまな設定を動的に挿入します。

import ConfigParser
 
def get_config(path): # Used make ConfigParser case sensitive
    config = ConfigParser.ConfigParser()
    config.optionxform=str  # make configparser preserve case
    try:
        config.read(os.path.expanduser(path))
        return config
     except Exception, e:
        log.error(e)
 
def setROI(roi,width,height):
    global ini_file
    imatestini = get_config(ini_file)
 
    imatestini.set('ccsg', 'roi', roi)
    imatestini.set('ccsg', 'nwid_save', width)
    imatestini.set('ccsg', 'nht_save', height)
    with open(tempINI, 'w') as outfile:
        imatestini.write(outfile)
    return

ImatestのINIファイルは大文字と小文字を区別します。INIファイルを操作するツールは、セクション名とキーの大文字と小文字を正しく保持することを確認してください。

これらの関数は、JSONファイルから読み込まれた値を使用して、multicharts関数呼び出し内で呼び出されます。

roi_overrides = {}
roi_overrides_lower = {}
roi_override_file = os.path.join(images_dir,base,'multicharts-rois.json')
if os.path.exists(roi_override_file):
    with open(roi_override_file,'r') as fh: # read ROI override file
        roi_overrides = json.load(fh)
    for override, rois in roi_overrides.iteritems(): # convert to lowercase
        roi_overrides_lower[override.lower()] = rois
else:
    raise Exception('ROI override file ' + roi_override_file + ' not found.')
 
if image_file.lower() in roi_overrides_lower:
     setROI(roi_overrides_lower[image_file.lower()], roi_overrides['width'], roi_overrides['height'])
     selectedINI = tempINI
else:
     raise Exception('Missing ROI override for ' + image_file)

スコアの抽出

最後に、主要業績評価指標(KPI)を抽出します。これらはすべて知覚品質損失(QL)を最小可弁差(JND)単位で表したものです。このスクリプトはこの記事には少し長すぎるので、興味のある方はGitHubのソースコードをご覧ください。

計算結果の指標セットをJSON形式で以下に示します。

{ 'DeviceX': 
    { 'CL_QL': { '5000KLED_1000lux': 0.9142,
                 'TL84_100lux': 0.1803,
                 'Tung_10lux': 2.565},
      'CU_QL': 0.07498,
      'LCD_QL': 0,
      'LGD_QL': 0,
      'SFR_QL': { '5000KLED_1000lux': 0.0,
                  'TL84_100lux': 0.1969,
                  'Tung_10lux': 0.3946},
      'TB_QL': { '5000KLED_1000lux': 1.2,
                 'TL84_100lux': 6.25,
                 'Tung_10lux': 9.1},
      'VN_QL': { '5000KLED_1000lux': 1.113,
                 'TL84_100lux': 2.409,
                 'Tung_10lux': 8.531}},
      'Combined_QL': 11.0245
}

IEEE適合性評価プログラムによって試験手順と総合スコアの算出方法が確定すると、これらの結果が統合され、シンプルなカメラ付き携帯電話の評価スコアとして表示されます。

この例の完全なPythonソースコードはGitHubに掲載されています。

既存のImatest Masterライセンスにこれらの自動化機能を追加するには、 Imatest Ultimateにアップグレードしてください。また、購入前にImatest ITの30日間無料トライアルをお試しいただき、ご自身の環境でどのように機能するかをご確認いただくこともできます。

関連ウェビナー