Fixing python3 incompatibilities len(list) instead of len(zip)
@@ -16,6 +16,8 @@ MEASURES = (
'fpr', 'ppv', 'npv', 'sensitivity', 'specificity',
'accuracy', 'jaccard', 'dice', 'ave_dist', 'haus_dist'
)
+MEASURES_NEW = ('ref volume', 'seg volume', 'tp', 'fp', 'fn', 'outline_error',
+ 'detection_error', 'dice')
OUTPUT_FORMAT = '{:4f}'
OUTPUT_FILE_PREFIX = 'PairwiseMeasure'
@@ -48,14 +50,14 @@ def run(param, csv_dict):
with open(os.path.join(param.save_csv_dir, out_name), 'w+') as out_stream:
# a trivial PairwiseMeasures obj to produce header_str
m_headers = PairwiseMeasures(0, 0, measures=MEASURES).header_str()
- print >> out_stream, "Name (ref), Name (seg), Label" + m_headers + '\n'
+ out_stream.write("Name (ref), Name (seg), Label" + m_headers + '\n')
# do the pairwise evaluations
for i, pair_ in enumerate(pair_list):
seg_name = pair_[0]
ref_name = pair_[1]
print('>>> {} of {} evaluations, comparing {} and {}.'.format(
- i + 1, len(pair_list), ref_name, seg_name))
+ i + 1, len(list(pair_list)), ref_name, seg_name))
seg_nii = nib.load(os.path.join(param.seg_dir, seg_name))
ref_nii = nib.load(os.path.join(param.ref_dir, ref_name))
voxel_sizes = seg_nii.header.get_zooms()[0:3]
@@ -92,8 +94,8 @@ def run(param, csv_dict):
print("Empty foreground in thresholded binary image.")
continue
PE = PairwiseMeasures(seg_binary, ref_binary,
- measures=MEASURES, num_neighbors=6,
+ measures=MEASURES_NEW, num_neighbors=6,
pixdim=voxel_sizes)
fixed_fields = "{}, {}, {},".format(ref_name, seg_name, j)
- print >> out_stream, fixed_fields + PE.to_string(
- OUTPUT_FORMAT) + '\n'
+ out_stream.write(fixed_fields + PE.to_string(
+ OUTPUT_FORMAT) + '\n')
