diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index c9aef8b75a..03c5d8679d 100644 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -353,8 +353,9 @@ def is_same_series(self, other): return True def _scale_data(self, data): - scale = self.get('RescaleSlope', 1) - offset = self.get('RescaleIntercept', 0) + # depending on pydicom and dicom files, values might need casting from Decimal to float + scale = float(self.get('RescaleSlope', 1)) + offset = float(self.get('RescaleIntercept', 0)) # a little optimization. If we are applying either the scale or # the offset, we need to allow upcasting to float. if scale != 1: diff --git a/nibabel/nicom/tests/data/decimal_rescale.dcm b/nibabel/nicom/tests/data/decimal_rescale.dcm new file mode 100644 index 0000000000..148454a3ac Binary files /dev/null and b/nibabel/nicom/tests/data/decimal_rescale.dcm differ diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index 8017c1f12e..22c79338a5 100644 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -31,6 +31,7 @@ DATA = None DATA_FILE_B0 = pjoin(IO_DATA_PATH, 'siemens_dwi_0.dcm.gz') DATA_FILE_SLC_NORM = pjoin(IO_DATA_PATH, 'csa_slice_norm.dcm') +DATA_FILE_DEC_RSCL = pjoin(IO_DATA_PATH, 'decimal_rescale.dcm') # This affine from our converted image was shown to match our image # spatially with an image from SPM DICOM conversion. We checked the @@ -171,3 +172,10 @@ def test_assert_parallel(): dw = didw.wrapper_from_file(DATA_FILE_SLC_NORM) dw.image_orient_patient = np.c_[[1., 0., 0.], [0., 1., 0.]] assert_raises(AssertionError, dw.__getattribute__, 'slice_normal') + +@dicom_test +def test_decimal_rescale(): + #Test that we don't get back a data array with dtpye np.object when our + #rescale slope is a decimal + dw = didw.wrapper_from_file(DATA_FILE_DEC_RSCL) + assert dw.get_data().dtype != np.object \ No newline at end of file