-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_dataset_json.py
executable file
·54 lines (52 loc) · 1.94 KB
/
create_dataset_json.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
import json
import os
from collections import OrderedDict
from batchgenerators.utilities.file_and_folder_operations import save_json
import shutil
from pymic.io.image_read_write import load_image_as_nd_array, save_nd_array_as_image
from pymic.util.image_process import convert_label
from path_config import path_dict
if __name__ == "__main__":
nnUNet_data_dir = path_dict['nnunet_raw_data_dir'] + "/Task112_MyoPS"
lablesTr_list = (os.listdir(os.path.join(nnUNet_data_dir, "labelsTr")))
lablesTr_list.remove("crop_information.json")
lablesTr_list.sort()
imagesTs_list = (os.listdir(os.path.join(nnUNet_data_dir, "imagesTs")))
imagesTs_list.remove("crop_information.json")
imagesTs_list.sort()
tmp_list = []
for i, item in enumerate(imagesTs_list):
if "0000" in item:
item = item.replace("_0000", "")
tmp_list.append(item)
print(item)
else:
continue
imagesTs_list = tmp_list
json_dict = OrderedDict()
json_dict['name'] = "MyoPS"
json_dict['description'] = "Myocardial pathology segmentation combining multi-sequence CMR"
json_dict['tensorImageSize'] = "4D"
json_dict['reference'] = "TBC"
json_dict['licence'] = "CC BY-NC-ND"
json_dict['release'] = "0.0"
json_dict['modality'] = {
"0": "C0",
"1": "DE",
"2": "T2",
"3": "coarse_seg"
}
json_dict['labels'] = {
"0": "background",
"1": "myo",
"2": "lv",
"3": "rv",
"4": "edema",
"5": "scars"
}
json_dict['numTraining'] = len(lablesTr_list)
json_dict['numTest'] = len(imagesTs_list)
json_dict['training'] = [{'image': "./imagesTr/{0:}".format(item), "label": "./labelsTr/{0:}".format(item)} for item in
lablesTr_list]
json_dict['test'] = ["./imagesTs/{0:}".format(item) for item in imagesTs_list]
save_json(json_dict, os.path.join(nnUNet_data_dir, "dataset.json"))