Skip to content

Commit 9408ae8

Browse files
committed
Backport gh-1296: Conditionally drop derived volumes from DWI sequences
DATA: Add dcm_qa_xa30 as submodule for test data TEST: Add test for Siemens TRACE volume FIX: Conditionally drop isotropic frames
1 parent ee684eb commit 9408ae8

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
[submodule "nibabel-data/nitest-dicom"]
2020
path = nibabel-data/nitest-dicom
2121
url = https://github.com/effigies/nitest-dicom
22+
[submodule "nibabel-data/dcm_qa_xa30"]
23+
path = nibabel-data/dcm_qa_xa30
24+
url = https://github.com/neurolabusc/dcm_qa_xa30.git

nibabel-data/dcm_qa_xa30

Submodule dcm_qa_xa30 added at 89b2509

nibabel/nicom/dicomwrappers.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,14 @@ def image_shape(self):
509509
if hasattr(first_frame, 'get') and first_frame.get([0x18, 0x9117]):
510510
# DWI image may include derived isotropic, ADC or trace volume
511511
try:
512-
self.frames = pydicom.Sequence(
512+
anisotropic = pydicom.Sequence(
513513
frame
514514
for frame in self.frames
515515
if frame.MRDiffusionSequence[0].DiffusionDirectionality != 'ISOTROPIC'
516516
)
517+
# Image contains DWI volumes followed by derived images; remove derived images
518+
if len(anisotropic) != 0:
519+
self.frames = anisotropic
517520
except IndexError:
518521
# Sequence tag is found but missing items!
519522
raise WrapperError('Diffusion file missing information')

nibabel/nicom/tests/test_dicomwrappers.py

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
DATA_FILE_EMPTY_ST = pjoin(IO_DATA_PATH, 'slicethickness_empty_string.dcm')
3636
DATA_FILE_4D_DERIVED = pjoin(get_nibabel_data(), 'nitest-dicom', '4d_multiframe_with_derived.dcm')
3737
DATA_FILE_CT = pjoin(get_nibabel_data(), 'nitest-dicom', 'siemens_ct_header_csa.dcm')
38+
DATA_FILE_SIEMENS_TRACE = pjoin(
39+
get_nibabel_data(),
40+
'dcm_qa_xa30',
41+
'In/20_DWI_dir80_AP/0001_1.3.12.2.1107.5.2.43.67093.2022071112140611403312307.dcm',
42+
)
3843

3944
# This affine from our converted image was shown to match our image spatially
4045
# with an image from SPM DICOM conversion. We checked the matching with SPM
@@ -656,6 +661,13 @@ def test_data_derived_shape(self):
656661
with pytest.warns(UserWarning, match='Derived images found and removed'):
657662
assert dw.image_shape == (96, 96, 60, 33)
658663

664+
@dicom_test
665+
@needs_nibabel_data('dcm_qa_xa30')
666+
def test_data_trace(self):
667+
# Test that a standalone trace volume is found and not dropped
668+
dw = didw.wrapper_from_file(DATA_FILE_SIEMENS_TRACE)
669+
assert dw.image_shape == (72, 72, 39, 1)
670+
659671
@dicom_test
660672
@needs_nibabel_data('nitest-dicom')
661673
def test_data_unreadable_private_headers(self):

0 commit comments

Comments
 (0)