Skip to content

Commit abc2f43

Browse files
authored
Merge pull request #652 from mattcieslak/master
FIX: Interpret empty string in SliceThickness DICOM field as missing (default to 1)
2 parents 14083e8 + a06c005 commit abc2f43

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def voxel_sizes(self):
201201
zs = self.get('SpacingBetweenSlices')
202202
if zs is None:
203203
zs = self.get('SliceThickness')
204-
if zs is None:
204+
if zs is None or zs == '':
205205
zs = 1
206206
# Protect from python decimals in pydicom 0.9.7
207207
zs = float(zs)
Binary file not shown.

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
DATA_FILE_SLC_NORM = pjoin(IO_DATA_PATH, 'csa_slice_norm.dcm')
3636
DATA_FILE_DEC_RSCL = pjoin(IO_DATA_PATH, 'decimal_rescale.dcm')
3737
DATA_FILE_4D = pjoin(IO_DATA_PATH, '4d_multiframe_test.dcm')
38+
DATA_FILE_EMPTY_ST = pjoin(IO_DATA_PATH, 'slicethickness_empty_string.dcm')
3839

3940
# This affine from our converted image was shown to match our image spatially
4041
# with an image from SPM DICOM conversion. We checked the matching with SPM
@@ -616,6 +617,11 @@ def test_data_real(self):
616617
assert_equal(sha1(dat_str).hexdigest(),
617618
'149323269b0af92baa7508e19ca315240f77fa8c')
618619

620+
@dicom_test
621+
def test_slicethickness_fallback(self):
622+
dw = didw.wrapper_from_file(DATA_FILE_EMPTY_ST)
623+
assert_equal(dw.voxel_sizes[2], 1.0)
624+
619625
@dicom_test
620626
def test_data_fake(self):
621627
# Test algorithm for get_data

0 commit comments

Comments
 (0)