-
Notifications
You must be signed in to change notification settings - Fork 1
/
preprocess_Prostate.py
27 lines (20 loc) · 1.06 KB
/
preprocess_Prostate.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
import os
import json
data_dir = '../Data/Prostate_6/'
folder_lists = ['BIDMC', 'BMC', 'HK', 'I2CVB', 'RUNMC', 'UCL']
for folder in folder_lists:
dict_lists = []
data_lists = os.listdir(os.path.join(data_dir, folder))
data_names = []
for data in data_lists:
data_names.append(data.strip('_Segmentation.nii.gz').strip('_segmentation.nii.gz').strip('.nii.gz'))
data_names = list(set(data_names))
for data_name in data_names:
if (data_name+'_Segmentation.nii.gz') in data_lists:
dict_lists.append({'image': os.path.join(data_dir, folder, data_name+'.nii.gz'),
'label': os.path.join(data_dir, folder, data_name+'_Segmentation.nii.gz')})
elif (data_name+'_segmentation.nii.gz') in data_lists:
dict_lists.append({'image': os.path.join(data_dir, folder, data_name + '.nii.gz'),
'label': os.path.join(data_dir, folder, data_name + '_segmentation.nii.gz')})
with open(os.path.join('data_lists', folder), 'w') as fout:
json.dump(dict_lists, fout)