-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate.py
36 lines (27 loc) · 955 Bytes
/
rotate.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
# -*- coding: utf-8 -*-
# @Time : 2022/1/5 0005 14:20
# @Author : Xiaofeng
# @FileName: torch[rotate]
# @Software: Pycharm
# @Usages :
import os
import SimpleITK as sitk
import numpy as np
def pathExist(path):
if not os.path.exists(path):
os.makedirs(path)
return path
raw_dir = r'J:\Dataset\SegWithDistMap\case231\nii\gt'
out_dir = r'J:\Dataset\SegWithDistMap\case231\nii\gt_rotate1'
pathExist(out_dir)
for index,file in enumerate(os.listdir(raw_dir)):
ct = sitk.ReadImage(os.path.join(raw_dir, file), sitk.sitkInt16)
ct_array = sitk.GetArrayFromImage(ct)
print(ct_array.shape)
new_array = np.transpose(ct_array, (1, 2, 0))
#new_array = np.transpose(ct_array, (2, 0, 1))
new_seg = sitk.GetImageFromArray(new_array)
# new_seg.SetDirection(ct.GetDirection())
# new_seg.SetOrigin(ct.GetOrigin())
# new_seg.SetSpacing(ct.GetSpacing())
sitk.WriteImage(new_seg, os.path.join(out_dir, file))