#!/usr/bin/python import sys import ConfigParser import time import datetime import string import csv import os import os.path if len(sys.argv)!=5: print "Wrong Number of Arguments" print "Usage: " + sys.argv[0] + " file_nlm.csv file_sheep.csv file_human.csv output" sys.exit(1) filename_nlm = sys.argv[1] filename_sheep = sys.argv[2] filename_human = sys.argv[3] outputfilename = sys.argv[4] filenames = [ filename_nlm, filename_sheep, filename_human ] datasets = ["nlm", "sheep", "lung5"] datasets_map = { 'nlm' : 0, 'sheep' : 1, 'lung5' : 2 } synthetic_transformations = ["grid_32_2", "grid_32_4", "grid_32_8", "grid_32_12", "simbr_10_5", "simbr_25_10", "simbr_55_25", "simbr_70_30"] algorithms = ["_affine_", "_demons_", "_symdemons", "_curvature_", "_elastic_", "_bspline_", "_foerstner_","_hybrid_","_optic_flow_","_aniso_of_"] algorithms_orig = [] for algo in algorithms: algorithms_orig = algorithms_orig + [algo.replace("_","")] rmsdisp_result_map = {} meddisp_result_map = {} maxdisp_result_map = {} jacdisp_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 and the synthetic transformation current_dataset = '' for test_for_dataset in datasets: if current_line_entries[0].count(test_for_dataset) > 0: current_dataset = test_for_dataset current_synthetic_transform = '' for test_for_synth_transform in synthetic_transformations: if current_line_entries[0].count(test_for_synth_transform) > 0: current_synthetic_transform = test_for_synth_transform # 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_synthetic_transform + " - " + current_algorithm # RMSDISP # for each measure fetch the map of algorithm to synth transform rmsdisp_measure_per_algorithm = rmsdisp_result_map.get(current_algorithm, {}) # print rmsdisp_measure_per_algorithm # for each measure fetch the list over the datasets using the synth transform rmsdisp_measure = rmsdisp_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] rmsdisp_measure[which_dataset] = current_line_entries[2] rmsdisp_measure_per_algorithm[current_synthetic_transform] = rmsdisp_measure rmsdisp_result_map[current_algorithm] = rmsdisp_measure_per_algorithm # print rmsdisp_result_map # print # MAXDISP # for each measure fetch the map of algorithm to synth transform maxdisp_measure_per_algorithm = maxdisp_result_map.get(current_algorithm, {}) # for each measure fetch the list over the datasets using the synth transform maxdisp_measure = maxdisp_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] maxdisp_measure[which_dataset] = current_line_entries[3] maxdisp_measure_per_algorithm[current_synthetic_transform] = maxdisp_measure maxdisp_result_map[current_algorithm] = maxdisp_measure_per_algorithm # MEDDISP # for each measure fetch the map of algorithm to synth transform meddisp_measure_per_algorithm = meddisp_result_map.get(current_algorithm, {}) # for each measure fetch the list over the datasets using the synth transform meddisp_measure = meddisp_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] meddisp_measure[which_dataset] = current_line_entries[4] meddisp_measure_per_algorithm[current_synthetic_transform] = meddisp_measure meddisp_result_map[current_algorithm] = meddisp_measure_per_algorithm # JACDISP # for each measure fetch the map of algorithm to synth transform jacdisp_measure_per_algorithm = jacdisp_result_map.get(current_algorithm, {}) # for each measure fetch the list over the datasets using the synth transform jacdisp_measure = jacdisp_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] jacdisp_measure[which_dataset] = current_line_entries[5] jacdisp_measure_per_algorithm[current_synthetic_transform] = jacdisp_measure jacdisp_result_map[current_algorithm] = jacdisp_measure_per_algorithm print jacdisp_result_map print finally: currentfile.close() # now create the result file with the latex tables outputfile = open(outputfilename,'w') synth_transform_pair_list = [ ['simbr_10_5','simbr_25_10'], ['simbr_55_25', 'simbr_70_30'], ['grid_32_2', 'grid_32_4'], ['grid_32_8','grid_32_12'] ] for synth_transform_pair in synth_transform_pair_list: outputfile.write(synth_transform_pair[0] + " and " + synth_transform_pair[1] + "\n") outputfile.write("RMS displacement\n") # print rmsdisp_result_map for algo in algorithms_orig: measure_per_algorithm = rmsdisp_result_map.get(algo, {}) # print measure_per_algorithm if len(measure_per_algorithm) > 0: synthi = synth_transform_pair[0] measure1 = measure_per_algorithm.get(synthi, []) synthi = synth_transform_pair[1] measure2 = measure_per_algorithm.get(synthi, []) # print len(measure1) # print len(measure2) if len(measure1) > 0 and len(measure2) > 0: outputfile.write( "& \\textit{" + algo + "} & [mm] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n') outputfile.write("MAD displacement\n") for algo in algorithms_orig: measure_per_algorithm = meddisp_result_map.get(algo, {}) if len(measure_per_algorithm) > 0: synthi = synth_transform_pair[0] measure1 = measure_per_algorithm.get(synthi, []) synthi = synth_transform_pair[1] measure2 = measure_per_algorithm.get(synthi, []) if len(measure1) > 0 and len(measure2) > 0: outputfile.write( "& \\textit{" + algo + "} & [mm] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n') outputfile.write("MAX displacement\n") for algo in algorithms_orig: measure_per_algorithm = maxdisp_result_map.get(algo, {}) if len(measure_per_algorithm) > 0: synthi = synth_transform_pair[0] measure1 = measure_per_algorithm.get(synthi, []) synthi = synth_transform_pair[1] measure2 = measure_per_algorithm.get(synthi, []) if len(measure1) > 0 and len(measure2) > 0: outputfile.write( "& \\textit{" + algo + "} & [mm] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n') outputfile.write("jacobian displacement\n") for algo in algorithms_orig: measure_per_algorithm = jacdisp_result_map.get(algo, {}) if len(measure_per_algorithm) > 0: synthi = synth_transform_pair[0] measure1 = measure_per_algorithm.get(synthi, []) synthi = synth_transform_pair[1] measure2 = measure_per_algorithm.get(synthi, []) if len(measure1) > 0 and len(measure2) > 0: outputfile.write( "& \\textit{" + algo + "} & & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n')