@@ -114,7 +114,7 @@ def generate_voxel_data(self, series):
114
114
vol_data = np .stack ([s .get_pixel_array () for s in slices ], axis = 0 )
115
115
# The above get_pixel_array() already considers the PixelRepresentation attribute,
116
116
# 0 is unsigned int, 1 is signed int
117
- if slices [0 ][0x0028 ,0x0103 ].value == 0 :
117
+ if slices [0 ][0x0028 , 0x0103 ].value == 0 :
118
118
vol_data = vol_data .astype (np .uint16 )
119
119
120
120
# For now we support monochrome image only, for which DICOM Photometric Interpretation
@@ -157,24 +157,35 @@ def generate_voxel_data(self, series):
157
157
except KeyError :
158
158
slope = 1
159
159
160
-
161
160
# check if vol_data, intercept, and slope can be cast to uint16 without data loss
162
- if np .can_cast (vol_data , np .uint16 , casting = 'safe' ) and np .can_cast (intercept , np .uint16 , casting = 'safe' ) and np .can_cast (slope , np .uint16 , casting = 'safe' ):
163
- logging .info (f"Casting to uint16" )
161
+ if (
162
+ np .can_cast (vol_data , np .uint16 , casting = "safe" )
163
+ and np .can_cast (intercept , np .uint16 , casting = "safe" )
164
+ and np .can_cast (slope , np .uint16 , casting = "safe" )
165
+ ):
166
+ logging .info ("Casting to uint16" )
164
167
vol_data = np .array (vol_data , dtype = np .uint16 )
165
168
intercept = np .uint16 (intercept )
166
169
slope = np .uint16 (slope )
167
- elif np .can_cast (vol_data , np .float32 , casting = 'safe' ) and np .can_cast (intercept , np .float32 , casting = 'safe' ) and np .can_cast (slope , np .float32 , casting = 'safe' ):
168
- logging .info (f"Casting to float32" )
170
+ elif (
171
+ np .can_cast (vol_data , np .float32 , casting = "safe" )
172
+ and np .can_cast (intercept , np .float32 , casting = "safe" )
173
+ and np .can_cast (slope , np .float32 , casting = "safe" )
174
+ ):
175
+ logging .info ("Casting to float32" )
169
176
vol_data = np .array (vol_data , dtype = np .float32 )
170
177
intercept = np .float32 (intercept )
171
178
slope = np .float32 (slope )
172
- elif np .can_cast (vol_data , np .float64 , casting = 'safe' ) and np .can_cast (intercept , np .float64 , casting = 'safe' ) and np .can_cast (slope , np .float64 , casting = 'safe' ):
173
- logging .info (f"Casting to float64" )
179
+ elif (
180
+ np .can_cast (vol_data , np .float64 , casting = "safe" )
181
+ and np .can_cast (intercept , np .float64 , casting = "safe" )
182
+ and np .can_cast (slope , np .float64 , casting = "safe" )
183
+ ):
184
+ logging .info ("Casting to float64" )
174
185
vol_data = np .array (vol_data , dtype = np .float64 )
175
186
intercept = np .float64 (intercept )
176
187
slope = np .float64 (slope )
177
-
188
+
178
189
if slope != 1 :
179
190
vol_data = slope * vol_data
180
191
0 commit comments