#!/usr/bin/env python
# coding : utf-8

"""
Main module for VOI analyzer.
"""

import pandas as pd
import numpy as np
import argparse
import os




@@ -138,10 +138,1943 @@
 ort os%0A%0A
+def _analysis(img_mat, voi_mat, voi_no, eps=1e-12):%0A    %22%22%22 Extract VOI statistices for each VOI.%0A    %22%22%22%0A    vec = img_mat%5Bvoi_mat == voi_no%5D%0A    vec2 = vec%5B~np.isnan(vec)%5D%0A%0A    # Statistics%0A    v_mean = float(vec2.mean())%0A    v_sd = float(vec2.std(ddof=1))%0A    v_cov = v_sd / (v_mean + eps) * 100.%0A    v_max = float(vec2.max())%0A    v_min = float(vec2.min())%0A    n_vox = vec.size%0A%0A    # Output%0A    out_tab = pd.DataFrame(%7B%22VOI No.%22 :  %5Bvoi_no%5D,%0A                            %22No. of voxels%22 : %5Bn_vox%5D,%0A                            %22Mean%22 : %5Bv_mean%5D,%0A                            %22SD%22 : %5Bv_sd%5D,%0A                            %22CoV%22 : %5Bv_cov%5D,%0A                            %22Max%22 : %5Bv_max%5D,%0A                            %22Min%22 : %5Bv_min%5D%7D)%0A%0A    return out_tab%0A%0Adef voi_analysis(img_file, voi_file, lut_file=None):%0A    %22%22%22 Extract VOI values.%0A    It outputs Pandas DataFrame for VOI statistics.%0A%0A    Inputs:%0A        img_file   :    Path for image to extract VOI values%0A%0A        voi_file    :   Path for VOI map%0A%0A        lut_file    :   Path for look-up table for VOI map.%0A                        If not None, look-up table is applied to output table.%0A%0A    Output:%0A        out_tab     :   Pandas DataFrame for VOI statistics.%0A    %22%22%22%0A    # Load image & VOI%0A    img_mat, img_aff = utils.loadImage(img_file)%5B:2%5D%0A    voi_mat = utils.loadImage(voi_file)%5B0%5D.astype(np.int16)%0A    %0A    # Extract%0A    maxNo = voi_mat.max()%0A    out_tab = pd.concat(%5B_analysis(img_mat, voi_mat, v_no)%0A                            for v_no in range(1, maxNo + 1, 1)%5D)%0A%0A    # Calculate volumes (unit: cm3)%0A    vol_per_vox = np.abs(np.prod(np.diag(img_aff%5B:3, :3%5D)))%0A    out_tab.loc%5B:, %22Volume%22%5D = out_tab.loc%5B:, %22No. of voxels%22%5D / 1000.%0A%0A    # Apply look-up table%0A    if lut_file is not None:%0A        lut = utils.loadLUT(lut_file)%0A        out_tab.loc%5B:, %22VOI%22%5D = out_tab.loc%5B:, %22VOI No.%22%5D.map(lut)%0A%0A    # Image file name%0A    out_tab.loc%5B:, %22Path%22%5D = img_file%0A%0A    return out_tab
 %0A%0A

Implement basis for VOI analyzer.