使用 Imatest IT 和 Python 實現 CPIQ 分析自動化

Imatest IT的Python 介面提供了一種簡單的方法來呼叫 Imatest 的測試。本文將展示如何自動化 Imatest 的運行,以及如何收集和輕鬆處理這些測試結果。在本範例中,我們將針對三個光照等級執行五個 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()

主處理腳本呼叫五個模組,收集它們的資料輸出並將其儲存到 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 檔案修改工具都能保留節和鍵的大小寫。

然後,在我們的 multicharts 函數呼叫中,使用從 JSON 檔案載入的值來呼叫這些函數:

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 天免費試用版,以便在購買前了解其功能是否適合您。

相關網路研討會