-
Notifications
You must be signed in to change notification settings - Fork 266
ENH: Support for Philips DICOMs w/ derived volume #727
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
Changes from 4 commits
3a985f5
bbd420a
b7ef629
6ec7b0a
039d4f0
2af8950
c59b30b
f95d716
469f623
5409f50
dfd93e1
5181407
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
from .dwiparams import B2q, nearest_pos_semi_def, q2bg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from ..openers import ImageOpener | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from ..onetime import setattr_on_read as one_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from ..pydicom_compat import tag_for_keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from ..pydicom_compat import tag_for_keyword, Sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class WrapperError(Exception): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -461,10 +461,23 @@ def __init__(self, dcm_data): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wrapper.__init__(self, dcm_data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.dcm_data = dcm_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.frames = dcm_data.get('PerFrameFunctionalGroupsSequence') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._nframes = self.get('NumberOfFrames') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.frames[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
except TypeError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise WrapperError("PerFrameFunctionalGroupsSequence is empty.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# DWI image where derived isotropic, ADC or trace volume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# was appended to the series | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self.frames[0].get([0x18, 0x9117], None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.frames = Sequence( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
frame for frame in self.frames if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
frame.get([0x18, 0x9117])[0].get([0x18, 0x9075]).value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
!= 'ISOTROPIC' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._nframes = len(self.frames) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
except AttributeError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mgxd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.shared = dcm_data.get('SharedFunctionalGroupsSequence')[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
except TypeError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -503,8 +516,7 @@ def image_shape(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
if None in (rows, cols): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise WrapperError("Rows and/or Columns are empty.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Check number of frames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n_frames = self.get('NumberOfFrames') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert len(self.frames) == n_frames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert len(self.frames) == self._nframes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
frame_indices = np.array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[frame.FrameContentSequence[0].DimensionIndexValues | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for frame in self.frames]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -528,12 +540,15 @@ def image_shape(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Store frame indices | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._frame_indices = frame_indices | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if n_dim < 4: # 3D volume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return rows, cols, n_frames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return rows, cols, self._nframes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# More than 3 dimensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ns_unique = [len(np.unique(row)) for row in self._frame_indices.T] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(ns_unique) == 3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# derived volume is included | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ns_unique.pop(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really follow this guard. Can you elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this addresses the problem properly / gracefully, but I'm unsure how to proceed. I've come across a derived image included in the diffusion DICOM, which is currently not properly handled. I thought this meant 5D data wasn't yet handled, but in fact there is a test specifically for this introduced in 3f04e3c (maybe @matthew-brett can share some wisdom) nibabel/nibabel/nicom/tests/test_dicomwrappers.py Lines 656 to 682 in ad0b13f
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shape = (rows, cols) + tuple(ns_unique) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n_vols = np.prod(shape[3:]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if n_frames != n_vols * shape[2]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self._nframes != n_vols * shape[2]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise WrapperError("Calculated shape does not match number of " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"frames.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return tuple(shape) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.