-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_output.py
105 lines (64 loc) · 2.76 KB
/
data_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from pathlib import Path
from utils import get_data_root, get_ground_truth_keyword
def get_image_modality_convention_dict():
# We index each modality used in our dataset.
modality_dict = dict()
# The first modality is indexed with 0, following convention in:
# https://github.com/MIC-DKFZ/nnUNet/tree/master/nnunet/dataset_conversion
modality_dict['ct'] = 0
return modality_dict
def get_output_save_folder():
# This is the folder where the output will be saved.
output_save_folder = 'output/'
return output_save_folder
def get_output_folder_structure():
# Convention used in:
# https://github.com/MIC-DKFZ/nnUNet/tree/master/nnunet/dataset_conversion
output_folder_structure = dict()
output_folder_structure['training'] = dict()
output_folder_structure['training']['images'] = 'imagesTr/'
output_folder_structure['training']['ground_truth'] = 'labelsTr/'
output_folder_structure['test'] = dict()
output_folder_structure['test']['images'] = 'imagesTs/'
return output_folder_structure
def get_image_modality_convention(modality):
# Convention used in:
# https://github.com/MIC-DKFZ/nnUNet/tree/master/nnunet/dataset_conversion
modality_dict = get_image_modality_convention_dict()
try:
modality_no = modality_dict[modality]
image_modality_convention = '_{:04.0f}'.format(modality_no)
except (KeyError, TypeError) as e:
image_modality_convention = ''
return image_modality_convention
def get_data_file_prefix():
# Convention used in:
# https://github.com/MIC-DKFZ/nnUNet/tree/master/nnunet/dataset_conversion
data_file_prefix = 'patientID'
return data_file_prefix
def get_output_folder(data_root=None,
modality=None):
if data_root is None:
data_root = get_data_root()
output_folder_structure = get_output_folder_structure()
if modality is None:
folder = ''
elif modality == get_ground_truth_keyword():
folder = output_folder_structure['training']['ground_truth']
else:
folder = output_folder_structure['training']['images']
output_folder = data_root + get_output_save_folder() + folder
Path(output_folder).mkdir(parents=True, exist_ok=True)
return output_folder
def get_output_image_name(patient_no,
output_file_format,
data_root=None,
modality=None):
output_folder = get_output_folder(data_root, modality=modality)
file_name = get_data_file_prefix() + str(patient_no) + get_image_modality_convention(modality) + output_file_format
output_image_name = output_folder + file_name
return output_image_name
def main():
return True
if __name__ == '__main__':
main()