-
Notifications
You must be signed in to change notification settings - Fork 261
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
Conversation
* if DICOM has MR Diffusion Sequence (0018, 9117), discard any derived frames * out correct final shape * TODO: fix get_data() repr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume you're already looking into the test failures. Let me know if you want me to look at them too.
nibabel/nicom/dicomwrappers.py
Outdated
# 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 comment
The 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 comment
The 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
# 5D! | |
dim_idxs = [ | |
[1, 4, 2, 1], | |
[1, 2, 2, 1], | |
[1, 3, 2, 1], | |
[1, 1, 2, 1], | |
[1, 4, 2, 2], | |
[1, 2, 2, 2], | |
[1, 3, 2, 2], | |
[1, 1, 2, 2], | |
[1, 4, 1, 1], | |
[1, 2, 1, 1], | |
[1, 3, 1, 1], | |
[1, 1, 1, 1], | |
[1, 4, 1, 2], | |
[1, 2, 1, 2], | |
[1, 3, 1, 2], | |
[1, 1, 1, 2]] | |
fake_mf.update(fake_shape_dependents(dim_idxs, sid_dim=0)) | |
shape = (2, 3, 4, 2, 2) | |
data = np.arange(np.prod(shape)).reshape(shape) | |
sorted_data = data.reshape(shape[:2] + (-1,), order='F') | |
order = [11, 9, 10, 8, 3, 1, 2, 0, | |
15, 13, 14, 12, 7, 5, 6, 4] | |
sorted_data = sorted_data[..., np.argsort(order)] | |
fake_mf['pixel_array'] = np.rollaxis(sorted_data, 2) | |
assert_array_equal(MFW(fake_mf).get_data(), data * 2.0 - 1) |
Codecov Report
@@ Coverage Diff @@
## master #727 +/- ##
==========================================
- Coverage 89.55% 89.51% -0.04%
==========================================
Files 93 93
Lines 11474 11497 +23
Branches 1992 1998 +6
==========================================
+ Hits 10275 10291 +16
- Misses 859 864 +5
- Partials 340 342 +2
Continue to review full report at Codecov.
|
I tested the last commit with the same dataset I was working on when I opened the issue nipy/heudiconv#275. Now I can convert our images to BIDS without problems. @mgxd, thank you so much! |
@mgxd Is this still a WIP, or should I review? |
ready for a review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see this looks reasonable, tests pass, and @bmelo indicates that it resolves his problem over in HeuDiConv.
Inclined to merge, but I'll give it a couple days in case anybody with more DICOM experience wants to weigh in.
A couple comments.
nibabel/nicom/dicomwrappers.py
Outdated
@@ -522,6 +546,9 @@ def image_shape(self): | |||
if stackid_tag in dim_seq: | |||
stackid_dim_idx = dim_seq.index(stackid_tag) | |||
frame_indices = np.delete(frame_indices, stackid_dim_idx, axis=1) | |||
if has_derived: | |||
# derived volume is included | |||
frame_indices = np.delete(frame_indices, 1, axis=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is always the second entry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based off my limited testing yes - however we should definitely keep an eye on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use either a derived index or make an assertion that will fail loudly when the assumption is violated?
@mgxd If you have a few minutes, I think we can probably finish this up today. Just a question and a minor cleanup. |
LGTM. Merging. |
Ugh, saw after merging that your test file is 40MB. Had to force-push master back to pre-merge state. Can you find/produce a smaller version of the file, and open a new PR? |
@mgxd Just a bump on this. I believe we were looking for a (possibly truncated) file with a compressed data frame. |
Hi @mgxd, any news here? |
I'll see if I can get to it this weekend |
Hi @mgxd. Sorry to take so long to think of this, but what if we just create a |
That sounds like a good idea. @bmelo any restriction with the provided DICOM? |
No, you can use it without restrictions. |
Okay, I published under CC0: https://github.com/effigies/nitest-dicom @bmelo, please let me know if you have any preference for being credited. |
I have no preference. Thank you! |
Cool. Feel free to open a PR to add your affiliation, or any provenance of the file here: https://github.com/effigies/nitest-dicom/blob/master/CREDITS Thanks for providing this test file. |
Closes #693
Currently, if a Philips DICOM includes a derived volume,
MultiframeWrapper
blows up due to incorrectimage_shape
. This PR adds the following:hidden attribute_nframes
to track ifNumberOfFrames
has changedI also noticed
get_data()
output is incorrect, but haven't addressed that (any ideas regarding that would be appreciated!) My main motivation for this was to fix nipy/heudiconv#275Relevant material https://github.com/rordenlab/dcm2niix/blob/d04ba75c8b098240d0efef67379947ff75bc1d36/Philips/README.md#derived-parametric-maps-stored-with-raw-diffusion-data