Skip to content

Commit 6a0d60c

Browse files
authored
Handle exception case with missing DICOM Rescale Intercept and Slope attributes (#236)
* Assume default values for missing Rescale Intercept and Slope attributes. * Sign off Signed-off-by: mmelqin <mingmelvinq@nvidia.com>
1 parent 0e9ca43 commit 6a0d60c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

monai/deploy/operators/dicom_series_to_volume_operator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ def generate_voxel_data(self, series):
8484
# This is to have the same numpy ndarray as from Monai ImageReader (ITK, NiBabel etc).
8585
vol_data = np.stack([np.transpose(s.get_pixel_array()) for s in slices], axis=-1)
8686
vol_data = vol_data.astype(np.int16)
87-
intercept = slices[0][0x0028, 0x1052].value
88-
slope = slices[0][0x0028, 0x1053].value
87+
# Rescale Intercept and Slope attributes might be missing, but safe to assume defaults.
88+
try:
89+
intercept = slices[0][0x0028, 0x1052].value
90+
except KeyError:
91+
intercept = 0
92+
93+
try:
94+
slope = slices[0][0x0028, 0x1053].value
95+
except KeyError:
96+
slope = 1
8997

9098
if slope != 1:
9199
vol_data = slope * vol_data.astype(np.float64)

0 commit comments

Comments
 (0)