-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.py
99 lines (81 loc) · 2.49 KB
/
data.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import numpy as np
import nibabel as nib #reading MR images
import glob
import math
from skimage.transform import resize
import os
from PIL import Image
img_path = glob.glob("/storage/research/Intern19_v2/KidneyTumorSegmentationChallenge/kits19/data/Image/case_*/imaging.nii.gz")
mask_path = glob.glob("/storage/research/Intern19_v2/KidneyTumorSegmentationChallenge/kits19/data/Image/case_*/segmentation.nii.gz")
for i in range(1,100,1):
a=[]
a=nib.load(img_path[i])
a=a.get_data()
print("image (%d) loaded"%(i))
a=resize(a,(a.shape[0],600,600))
a=a[40:90,:,:]
for j in range(a.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("trainPNG/Image/"+str(i)+"_"+str(j)+".png")
#np.save("train/Image/"+str(i)+"_"+str(j)+".npy",a[j])
for i in range(1,100,1):
b=[]
b=nib.load(mask_path[i])
b=b.get_data()
print("mask (%d) loaded"%(i))
b=resize(b,(b.shape[0],600,600))
b=b[40:90,:,:]
for j in range(b.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("trainPNG/Mask/"+str(i)+"_"+str(j)+".png")
#np.save("train/Mask/"+str(i)+"_"+str(j)+".npy",b[j])
for i in range(100,200,1):
a=[]
a=nib.load(img_path[i])
a=a.get_data()
print("image (%d) loaded"%(i))
a=resize(a,(a.shape[0],600,600))
a=a[40:90,:,:]
for j in range(a.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("trainPNG/Image/"+str(i)+"_"+str(j)+".png")
#np.save("train/Image/"+str(i)+"_"+str(j)+".npy",a[j])
for i in range(100,200,1):
b=[]
b=nib.load(mask_path[i])
b=b.get_data()
print("mask (%d) loaded"%(i))
b=resize(b,(b.shape[0],600,600))
b=b[40:90,:,:]
for j in range(b.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("trainPNG/Mask/"+str(i)+"_"+str(j)+".png")
#np.save("train/Mask/"+str(i)+"_"+str(j)+".npy",b[j])
for i in range(200,210,1):
a=[]
a=nib.load(img_path[i])
a=a.get_data()
print("image (%d) loaded"%(i))
a=resize(a,(a.shape[0],600,600))
a=a[40:90,:,:]
for j in range(a.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("testPNG/Image/"+str(i)+"_"+str(j)+".png")
#np.save("test/Image/"+str(i)+"_"+str(j)+".npy",a[j])
for i in range(200,210,1):
b=[]
b=nib.load(mask_path[i])
b=b.get_data()
print("mask (%d) loaded"%(i))
b=resize(b,(b.shape[0],600,600))
b=b[40:90,:,:]
for j in range(b.shape[0]):
img = Image.fromarray(a[j,:,:])
img =img.convert("L")
img.save("testPNG/Mask/"+str(i)+"_"+str(j)+".png")
#np.save("test/Mask/"+str(i)+"_"+str(j)+".npy",b[j])