Skip to content

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

Merged
merged 12 commits into from
Mar 19, 2019
Merged

Conversation

mgxd
Copy link
Member

@mgxd mgxd commented Feb 20, 2019

Closes #693

Currently, if a Philips DICOM includes a derived volume, MultiframeWrapper blows up due to incorrect image_shape. This PR adds the following:

  • if DICOM has MR Diffusion Sequence (0018, 9117), iter through frames and discard any with type derived
  • hidden attribute _nframes to track if NumberOfFrames has changed
  • 4D diffusion DICOM with tracer volume for testing (thanks to @bmelo)

I 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#275

Relevant material https://github.com/rordenlab/dcm2niix/blob/d04ba75c8b098240d0efef67379947ff75bc1d36/Philips/README.md#derived-parametric-maps-stored-with-raw-diffusion-data

* if DICOM has MR Diffusion Sequence (0018, 9117), discard any derived frames
* out correct final shape
* TODO: fix get_data() repr
@coveralls
Copy link

coveralls commented Feb 21, 2019

Coverage Status

Coverage decreased (-0.0002%) to 91.916% when pulling c59b30b on mgxd:fix/trace into ad0b13f on nipy:master.

Copy link
Member

@effigies effigies left a 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.

# 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)
Copy link
Member

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?

Copy link
Member Author

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)

# 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-io
Copy link

codecov-io commented Feb 27, 2019

Codecov Report

Merging #727 into master will decrease coverage by 0.03%.
The diff coverage is 73.07%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
nibabel/pydicom_compat.py 100% <100%> (ø) ⬆️
nibabel/nicom/dicomwrappers.py 89.43% <68.18%> (-1.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9430224...5181407. Read the comment docs.

@bmelo
Copy link

bmelo commented Mar 8, 2019

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!

@effigies
Copy link
Member

@mgxd Is this still a WIP, or should I review?

@mgxd mgxd changed the title WIP+ENH: Support for Philips DICOMs w/ derived volume ENH: Support for Philips DICOMs w/ derived volume Mar 14, 2019
@mgxd
Copy link
Member Author

mgxd commented Mar 14, 2019

ready for a review

@effigies effigies self-assigned this Mar 14, 2019
@effigies effigies mentioned this pull request Mar 15, 2019
20 tasks
Copy link
Member

@effigies effigies left a 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.

@@ -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)
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?

@effigies
Copy link
Member

@mgxd If you have a few minutes, I think we can probably finish this up today. Just a question and a minor cleanup.

@effigies effigies added this to the 2.4.0 milestone Mar 18, 2019
@effigies
Copy link
Member

LGTM. Merging.

@effigies effigies merged commit 7faf8dd into nipy:master Mar 19, 2019
@effigies
Copy link
Member

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?

@effigies
Copy link
Member

@mgxd Just a bump on this. I believe we were looking for a (possibly truncated) file with a compressed data frame.

@effigies
Copy link
Member

Hi @mgxd, any news here?

@mgxd
Copy link
Member Author

mgxd commented Jul 12, 2019

I'll see if I can get to it this weekend

@effigies
Copy link
Member

effigies commented Aug 21, 2019

Hi @mgxd. Sorry to take so long to think of this, but what if we just create a nibabel-data submodule? I can do it, if you let me know the license the DICOM can be released under.

@mgxd
Copy link
Member Author

mgxd commented Aug 21, 2019

That sounds like a good idea.

@bmelo any restriction with the provided DICOM?

@bmelo
Copy link

bmelo commented Aug 21, 2019

No, you can use it without restrictions.

@effigies
Copy link
Member

Okay, I published under CC0: https://github.com/effigies/nitest-dicom

@bmelo, please let me know if you have any preference for being credited.

@bmelo
Copy link

bmelo commented Aug 21, 2019

I have no preference. Thank you!

@effigies
Copy link
Member

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.

@mgxd mgxd deleted the fix/trace branch February 8, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude trace volume from Philips DICOM? Message: Calculated shape does not match number of frames.
5 participants