@@ -112,7 +112,8 @@ def generate_voxel_data(self, series):
112
112
# with the NumPy array returned from the ITK GetArrayViewFromImage on the image
113
113
# loaded from the same DICOM series.
114
114
vol_data = np .stack ([s .get_pixel_array () for s in slices ], axis = 0 )
115
- vol_data = vol_data .astype (np .uint16 )
115
+ if slices [0 ][0x0028 ,0x0103 ].value == 1 :
116
+ vol_data = vol_data .astype (np .uint16 )
116
117
117
118
# For now we support monochrome image only, for which DICOM Photometric Interpretation
118
119
# (0028,0004) has defined terms, MONOCHROME1 and MONOCHROME2, with the former being:
@@ -161,8 +162,10 @@ def generate_voxel_data(self, series):
161
162
# Check if vol_data can be cast to uint16 without data loss
162
163
if np .can_cast (vol_data , np .uint16 , casting = 'safe' ):
163
164
vol_data = np .array (vol_data , dtype = np .uint16 )
164
- else :
165
- vol_data = np .array (vol_data , dtype = np .int32 )
165
+ elif np .can_cast (vol_data , np .float32 , casting = 'safe' ):
166
+ vol_data = np .array (vol_data , dtype = np .float32 )
167
+ elif np .can_cast (vol_data , np .float64 , casting = 'safe' ):
168
+ vol_data = np .array (vol_data , dtype = np .float32 )
166
169
return vol_data
167
170
168
171
def create_volumetric_image (self , vox_data , metadata ):
0 commit comments