-
Notifications
You must be signed in to change notification settings - Fork 345
/
2d_from_3d.py
47 lines (34 loc) · 1.33 KB
/
2d_from_3d.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
import cv2
import scipy.misc
import SimpleITK as sitk #reading MR images
import glob
readfolderT = glob.glob('/home/bat161/Desktop/Thesis/EADC_HHP/*_MNI.nii.gz')
readfolderL = glob.glob('/home/bat161/Desktop/Thesis/EADC_HHP/*_HHP_EADC.nii.gz')
TrainingImagesList = []
TrainingLabelsList = []
for i in range(len(readfolderT)):
y_folder = readfolderT[i]
yread = sitk.ReadImage(y_folder)
yimage = sitk.GetArrayFromImage(yread)
x = yimage[:184,:232,112:136]
x = scipy.rot90(x)
x = scipy.rot90(x)
for j in range(x.shape[2]):
TrainingImagesList.append((x[:184,:224,j]))
for i in range(len(readfolderL)):
y_folder = readfolderL[i]
yread = sitk.ReadImage(y_folder)
yimage = sitk.GetArrayFromImage(yread)
x = yimage[:184,:232,112:136]
x = scipy.rot90(x)
x = scipy.rot90(x)
for j in range(x.shape[2]):
TrainingLabelsList.append((x[:184,:224,j]))
for i in range(len(TrainingImagesList)):
xchangeL = TrainingImagesList[i]
xchangeL = cv2.resize(xchangeL,(128,128))
scipy.misc.imsave('/home/bat161/Desktop/Thesis/Image/png_1C_images/'+str(i)+'.png',xchangeL)
for i in range(len(TrainingLabelsList)):
xchangeL = TrainingLabelsList[i]
xchangeL = cv2.resize(xchangeL,(128,128))
scipy.misc.imsave('/home/bat161/Desktop/Thesis/Image/png_1C_labels/'+str(i)+'.png',xchangeL)