@@ -112,7 +112,8 @@ def generate_voxel_data(self, series):
112112 # with the NumPy array returned from the ITK GetArrayViewFromImage on the image
113113 # loaded from the same DICOM series.
114114 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 )
116117
117118 # For now we support monochrome image only, for which DICOM Photometric Interpretation
118119 # (0028,0004) has defined terms, MONOCHROME1 and MONOCHROME2, with the former being:
@@ -161,8 +162,10 @@ def generate_voxel_data(self, series):
161162 # Check if vol_data can be cast to uint16 without data loss
162163 if np .can_cast (vol_data , np .uint16 , casting = 'safe' ):
163164 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 )
166169 return vol_data
167170
168171 def create_volumetric_image (self , vox_data , metadata ):
0 commit comments