#!/usr/bin/python import sys import ConfigParser import time import datetime import string import csv import os import os.path if len(sys.argv)!=9: print "Wrong Number of Arguments" print "Usage: " + sys.argv[0] + " file_lung1.csv file_lung2.csv file_lung3.csv file_lung4.csv file_lung5.csv file_lung6.csv file_lungAJ.csv output" sys.exit(1) filename_l1 = sys.argv[1] filename_l2 = sys.argv[2] filename_l3 = sys.argv[3] filename_l4 = sys.argv[4] filename_l5 = sys.argv[5] filename_l6 = sys.argv[6] filename_l7 = sys.argv[7] outputfilename = sys.argv[8] filenames = [ filename_l1, filename_l2, filename_l3, filename_l4, filename_l5, filename_l6, filename_l7 ] datasets = ["LUNG_0001", "LUNG_0002", "LUNG_0003", "LUNG_0004", "LUNG_0005", "LUNG_0006", "LUNG_AJ"] datasets_map = {'LUNG_0001' : 0, 'LUNG_0002' : 1, 'LUNG_0003' : 2, 'LUNG_0004' : 3, 'LUNG_0005' : 4, 'LUNG_0006' : 5, 'LUNG_AJ' : 6} algorithms = ["_affine_", "_demons", "_symdemons", "_curvature", "_elastic", "_bspline", "_foerstner","_hybrid","_aniso_of", "_optic_flow"] algorithms_orig = [] for algo in algorithms: algorithms_orig = algorithms_orig + [algo.replace("_","")] rmsint_result_map = {} medint_result_map = {} maxint_result_map = {} edge_result_map = {} nmiint_result_map = {} # go over all three input files for filename in filenames: currentfile = open(filename) try: for currentfile_line in currentfile: # analyze the file input current_line_entries = currentfile_line.split(';') if current_line_entries[0].count('Filename') == 0: # print current_line_entries # column 0 determines the data set current_dataset = '' for test_for_dataset in datasets: if current_line_entries[0].count(test_for_dataset) > 0: current_dataset = test_for_dataset # column 1 determines the registration algorithm current_algorithm = '' for test_for_algorithm in algorithms: if current_line_entries[1].count(test_for_algorithm) > 0: current_algorithm = test_for_algorithm # remove the '_' from test_for_algorithm current_algorithm = current_algorithm.replace("_","") if len(current_algorithm) == 0: current_algorithm = 'affine' print current_dataset + " - " + current_algorithm # RMSINT # for each measure fetch the map of algorithm to synth transform rmsint_measure_per_algorithm = rmsint_result_map.get(current_algorithm, ['-1','-1','-1','-1','-1','-1','-1']) # print rmsint_measure_per_algorithm which_dataset = datasets_map[current_dataset] rmsint_measure_per_algorithm[which_dataset] = current_line_entries[2] rmsint_result_map[current_algorithm] = rmsint_measure_per_algorithm # print rmsint_result_map # print # MAXINT # for each measure fetch the map of algorithm to synth transform maxint_measure_per_algorithm = maxint_result_map.get(current_algorithm, ['-1','-1','-1','-1','-1','-1','-1']) which_dataset = datasets_map[current_dataset] maxint_measure_per_algorithm[which_dataset] = current_line_entries[5] maxint_result_map[current_algorithm] = maxint_measure_per_algorithm # NMIINT # for each measure fetch the map of algorithm to synth transform nmiint_measure_per_algorithm = nmiint_result_map.get(current_algorithm, ['-1','-1','-1','-1','-1','-1','-1']) which_dataset = datasets_map[current_dataset] nmiint_measure_per_algorithm[which_dataset] = current_line_entries[6] nmiint_result_map[current_algorithm] = nmiint_measure_per_algorithm # MEDINT # for each measure fetch the map of algorithm to synth transform medint_measure_per_algorithm = medint_result_map.get(current_algorithm, ['-1','-1','-1','-1','-1','-1','-1']) which_dataset = datasets_map[current_dataset] medint_measure_per_algorithm[which_dataset] = current_line_entries[7] medint_result_map[current_algorithm] = medint_measure_per_algorithm # EDGE # for each measure fetch the map of algorithm to synth transform edge_measure_per_algorithm = edge_result_map.get(current_algorithm, ['-1','-1','-1','-1','-1','-1','-1']) which_dataset = datasets_map[current_dataset] edge_measure_per_algorithm[which_dataset] = current_line_entries[8] edge_result_map[current_algorithm] = edge_measure_per_algorithm # print edge_result_map # print finally: currentfile.close() # now create the result file with the latex tables outputfile = open(outputfilename,'w') outputfile.write("RMS intensity\n") for algo in algorithms_orig: measure = rmsint_result_map.get(algo, []) if len(measure) > 0: outputfile.write( "& \\textit{" + algo + "} & [HU] & " + measure[0] + " & " + measure[1] + " & " + measure[2] + " & " + measure[3] + " & " + measure[4] + " & " + measure[5] + " & " + measure[6] + " \\\\") outputfile.write('\n') outputfile.write("MAD intensity\n") for algo in algorithms_orig: measure = medint_result_map.get(algo, []) if len(measure) > 0: outputfile.write( "& \\textit{" + algo + "} & [HU] & " + measure[0] + " & " + measure[1] + " & " + measure[2] + " & " + measure[3] + " & " + measure[4] + " & " + measure[5] + " & " + measure[6] + " \\\\") outputfile.write('\n') outputfile.write("NMI intensity\n") for algo in algorithms_orig: measure = nmiint_result_map.get(algo, []) if len(measure) > 0: outputfile.write( "& \\textit{" + algo + "} & & " + measure[0] + " & " + measure[1] + " & " + measure[2] + " & " + measure[3] + " & " + measure[4] + " & " + measure[5] + " & " + measure[6] + " \\\\") outputfile.write('\n') outputfile.write("edge overlap\n") for algo in algorithms_orig: measure = edge_result_map.get(algo, []) if len(measure) > 0: outputfile.write( "& \\textit{" + algo + "} & & " + measure[0] + " & " + measure[1] + " & " + measure[2] + " & " + measure[3] + " & " + measure[4] + " & " + measure[5] + " & " + measure[6] + " \\\\") outputfile.write('\n') outputfile.write("MAX intensity\n") for algo in algorithms_orig: measure = maxint_result_map.get(algo, []) if len(measure) > 0: outputfile.write( "& \\textit{" + algo + "} & [HU] & " + measure[0] + " & " + measure[1] + " & " + measure[2] + " & " + measure[3] + " & " + measure[4] + " & " + measure[5] + " & " + measure[6] + " \\\\") outputfile.write('\n')