-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_segmentation_into_mesh.py
66 lines (47 loc) · 2.1 KB
/
convert_segmentation_into_mesh.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
import os
import sys
import argparse
import glob
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description="Convert a segmentation of type .nii.gz into a mesh of type obj with ImFusion workspace")
arg_parser.add_argument(
"--root_path_vertebrae",
required=True,
dest="root_path_vertebrae",
help="Root path of the vertebrae folders"
)
arg_parser.add_argument(
"--list_file_names",
required=True,
dest="txt_file",
help="Txt file that contains all spines that contain all lumbar vertebrae"
)
arg_parser.add_argument(
"--workspace_file_segm_to_mesh",
required=True,
dest="workspace_file_segm_to_mesh",
help="ImFusion workspace files that has converts a segm in nii.gz to a mesh in obj"
)
args = arg_parser.parse_args()
# iterate over spine IDS
with open(args.txt_file) as file:
spine_ids = [line.strip() for line in file]
placeholders = ['Name', 'PathToFile', 'PathToSave']
for spine_id in spine_ids:
# get the paths for the segmentations of all vertebrae belonging to this spine
unique_identifier = "*/**" + str(spine_id) + "*_msk*" + ".nii.gz"
vert_segm_paths = sorted(glob.glob(os.path.join(args.root_path_vertebrae, unique_identifier), recursive=True))
for vert_segm_path in vert_segm_paths:
arguments_imfusion = ""
for p in placeholders:
if p == 'PathToFile':
value = vert_segm_path
if p == 'Name':
vert_segm_name = os.path.basename(vert_segm_path)
value =vert_segm_name [:vert_segm_name.find('.nii.gz')]
if p == 'PathToSave':
value = vert_segm_path.replace('.nii.gz','_msh.obj')
arguments_imfusion += p + "=" + value + " "
print('ARGUMENTS: ', arguments_imfusion)
os.system("ImFusionConsole" + " " + args.workspace_file_segm_to_mesh + " " + arguments_imfusion)
print('################################################### ')