質問編集履歴

1

コードの変更

2021/10/08 03:05

投稿

1999si
1999si

スコア0

test CHANGED
File without changes
test CHANGED
@@ -34,109 +34,7 @@
34
34
 
35
35
  ```python
36
36
 
37
- #%%
37
+
38
-
39
- #mhd読み込みtrain
40
-
41
- def load_itk(filename):
42
-
43
- imglist = []
44
-
45
- spacinglist = []
46
-
47
-
48
-
49
- for i in range(len(train_a_FILE)):
50
-
51
- itkimage = sitk.ReadImage(filename)
52
-
53
- raw_image = sitk.GetArrayFromImage(itkimage)
54
-
55
- raw_array = np.asarray(raw_image, dtype=np.float32)
56
-
57
- # raw_array = raw_array.transpose(1, 2, 0)
58
-
59
-
60
-
61
- imglist.append(raw_array)
62
-
63
-
64
-
65
- raw_spacing = itkimage.GetSpacing()
66
-
67
- spacinglist.append(raw_spacing)
68
-
69
- imgdatas = np.asarray(imglist)
70
-
71
- return raw_array , imgdatas , spacinglist
72
-
73
-
74
-
75
-
76
-
77
- #%%
78
-
79
- ###train
80
-
81
- train_a_datalist = []
82
-
83
- train_b_datalist=[]
84
-
85
- for i in range(len(train_FILE)):
86
-
87
- a_train_image,aimagedatas,a_train_spacinglist=load_itk(train_a_FILE[i])
88
-
89
- b_train_image,bimagedatas,b_train_spacinglist=load_itk(train_b_FILE[i])
90
-
91
-
92
-
93
- #入力チェック時のエラー:input_1が4次元であることを期待したが、形状が(48, 180, 180)の配列を得たとエラーが出るので、newaxisで次元追加
94
-
95
- a_train_image=a_train_image[:,:,:,np.newaxis]
96
-
97
- a_train_image=a_train_image[:,:,:,np.newaxis]
98
-
99
- a_train_image = np.array(a_train_image, dtype=np.float32)
100
-
101
- b_train_image = np.array(b_train_image, dtype=np.float32)
102
-
103
-
104
-
105
- #画像の4分割したものをとる
106
-
107
- a_len = len(a_train_image)
108
-
109
- a_min_i = a_len//4
110
-
111
- a_max_i= a_len - a_min_i
112
-
113
-
114
-
115
- b_len = len(b_train_image)
116
-
117
- b_min_i = b_len//4
118
-
119
- b_max_i= b_len - b_min_i
120
-
121
-
122
-
123
-
124
-
125
- train_a_slice=np.array(a_train_image[a_min_i:a_max_i,:,:])
126
-
127
-
128
-
129
- train_a_datalist.append(train_a_slice)
130
-
131
-
132
-
133
-
134
-
135
- train_b_slice=np.array(b_train_image[b_min_i:b_max_i,:,:])
136
-
137
-
138
-
139
- train_b_datalist.append(train_b_slice)
140
38
 
141
39
 
142
40