-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcopy_images_to_nnunet_format.py
More file actions
executable file
·30 lines (24 loc) · 1.04 KB
/
copy_images_to_nnunet_format.py
File metadata and controls
executable file
·30 lines (24 loc) · 1.04 KB
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
import os
import os.path as osp
import argparse
import numpy as np
import SimpleITK as sitk
import shutil
from pathlib import Path
from settings import loader_settings
if __name__ == '__main__':
input_path = loader_settings['InputPath'] # Path for the input
output_path = '/nnunet_data'
file_name_list = os.listdir(input_path) # List of files in the input
file_path_list = [os.path.join(input_path, f) for f in file_name_list]
for fil in file_path_list:
if '.nii.gz' in fil: # the suffix is .nii.gz
out_name = os.path.basename(fil).replace('.nii.gz', '_0000.nii.gz')
shutil.copyfile(fil, os.path.join(output_path, out_name))
else: # the suffix is not .nii.gz
file_name = os.path.basename(fil)
base_file_name = file_name.split('.')[0]
# suffix_name = file_name.replace(base_file_name, '')
file_sitk_img = sitk.ReadImage(fil)
sitk.WriteImage(file_sitk_img, os.path.join(output_path, base_file_name + '_0000.nii.gz'))
print("Done")