#!/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("_","")] 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 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 # RMSINT # for each measure fetch the map of algorithm to synth transform rmsint_measure_per_algorithm = rmsint_result_map.get(current_algorithm, {}) # print rmsint_measure_per_algorithm # for each measure fetch the list over the datasets using the synth transform rmsint_measure = rmsint_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] rmsint_measure[which_dataset] = current_line_entries[2] rmsint_measure_per_algorithm[current_synthetic_transform] = rmsint_measure 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, {}) # for each measure fetch the list over the datasets using the synth transform maxint_measure = maxint_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] maxint_measure[which_dataset] = current_line_entries[5] maxint_measure_per_algorithm[current_synthetic_transform] = maxint_measure 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, {}) # for each measure fetch the list over the datasets using the synth transform nmiint_measure = nmiint_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] nmiint_measure[which_dataset] = current_line_entries[6] nmiint_measure_per_algorithm[current_synthetic_transform] = nmiint_measure 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, {}) # for each measure fetch the list over the datasets using the synth transform medint_measure = medint_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] medint_measure[which_dataset] = current_line_entries[7] medint_measure_per_algorithm[current_synthetic_transform] = medint_measure 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, {}) # for each measure fetch the list over the datasets using the synth transform edge_measure = edge_measure_per_algorithm.get(current_synthetic_transform, ['-1','-1','-1']) which_dataset = datasets_map[current_dataset] edge_measure[which_dataset] = current_line_entries[8] edge_measure_per_algorithm[current_synthetic_transform] = edge_measure 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') 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 intensity\n") for algo in algorithms_orig: measure_per_algorithm = rmsint_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 + "} & [HU] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n') outputfile.write("MAD intensity\n") for algo in algorithms_orig: measure_per_algorithm = medint_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 + "} & [HU] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n') outputfile.write("NMI intensity\n") for algo in algorithms_orig: measure_per_algorithm = nmiint_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') outputfile.write("edge overlap\n") for algo in algorithms_orig: measure_per_algorithm = edge_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') outputfile.write("MAX intensity\n") for algo in algorithms_orig: measure_per_algorithm = maxint_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 + "} & [HU] & " + measure1[0] + " & " + measure1[1] + " & " + measure1[2] + " & " + measure2[0] + " & " + measure2[1] + " & " + measure2[2] + " \\\\") outputfile.write('\n')