-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitk_nrrd_nii.py
49 lines (28 loc) · 1005 Bytes
/
sitk_nrrd_nii.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 14 11:13:32 2020
@author: wangmeiqi
"""
import os
import nrrd
import nibabel as nib
import numpy as np
import SimpleITK as sitk
#where you want to save ouput files
save_route = '/Users/wangmeiqi/code_and_data/HCC/ntuh/hcc_ntuh_niigz_1012'
#where are your input files
main_route = '/Users/wangmeiqi/code_and_data/HCC/ntuh/HCC_labeled'
filename = 'temp'
route = os.path.join(main_route, filename)
dir_ = []
path = []
for root, dirs, files in os.walk(route):
for file in files:
if file != '.DS_Store':
filename = os.path.join(root, file)
read_img = sitk.ReadImage(filename)
name = root.split("/")
output_path = os.path.join(save_route, file[:-5] + '_' + name[-1] + '.nii.gz')
sitk.WriteImage(read_img, output_path)
print("fininshing: " + output_path)