Skip to content

Handle exception case with missing DICOM Rescale Intercept and Slope attributes #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions monai/deploy/operators/dicom_series_to_volume_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,16 @@ def generate_voxel_data(self, series):
# This is to have the same numpy ndarray as from Monai ImageReader (ITK, NiBabel etc).
vol_data = np.stack([np.transpose(s.get_pixel_array()) for s in slices], axis=-1)
vol_data = vol_data.astype(np.int16)
intercept = slices[0][0x0028, 0x1052].value
slope = slices[0][0x0028, 0x1053].value
# Rescale Intercept and Slope attributes might be missing, but safe to assume defaults.
try:
intercept = slices[0][0x0028, 0x1052].value
except KeyError:
intercept = 0

try:
slope = slices[0][0x0028, 0x1053].value
except KeyError:
slope = 1

if slope != 1:
vol_data = slope * vol_data.astype(np.float64)
Expand Down