Skip to content
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

Bunch of multiframe fixes #1340

Merged
merged 8 commits into from
Jul 26, 2024
Merged

Bunch of multiframe fixes #1340

merged 8 commits into from
Jul 26, 2024

Conversation

moloney
Copy link
Contributor

@moloney moloney commented Jul 24, 2024

This fixes a bunch of issues with multiframe DICOM.

Instead of assuming the slice index is correct for ordering slices along the normal direction, I compute the slice location from the ImagePositionPatient for each frame and use that. This avoids slice orientation flips. I also use the ImagePositionPatient value with the minimum slice location as the image_position property, instead of just using the one from the first frame.

Any DimensionIndexValues that don't help to sort the data are ignored, and at the end (if needed) we try combine these into a single tuple index. This approach allows the code to work with a number of real world data sets that previously caused errors.

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 96.05911% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.35%. Comparing base (5d10c5b) to head (629dbb5).

Files Patch % Lines
nibabel/nicom/dicomwrappers.py 95.04% 2 Missing and 3 partials ⚠️
nibabel/nicom/tests/test_dicomwrappers.py 97.05% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1340      +/-   ##
==========================================
+ Coverage   95.34%   95.35%   +0.01%     
==========================================
  Files         207      207              
  Lines       29081    29238     +157     
  Branches     4863     4905      +42     
==========================================
+ Hits        27728    27881     +153     
- Misses        923      925       +2     
- Partials      430      432       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Reading DICOM code is pretty abstract for me, so folks more familiar are welcome to provide a more detailed review. Otherwise, the logic here looks reasonable.

A few comments. And would you mind adding a changelog blurb, since you know best what's significant here? Can just start a new section, e.g.:

Upcoming release (To be determined)
===================================

New features
------------

Enhancements
------------

Bug fixes
---------

Documentation
-------------

Maintenance
-----------

API changes and deprecations
----------------------------

nibabel/nicom/tests/test_dicomwrappers.py Show resolved Hide resolved
nibabel/nicom/tests/test_dicomwrappers.py Outdated Show resolved Hide resolved
nibabel/nicom/dicomwrappers.py Show resolved Hide resolved
@effigies
Copy link
Member

Addressing the type-check failure in #1341. If that gets merged before this, I'll fix up the conflict.

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.

LGTM. I'll give it time to let someone else have a look.

Can't just use number of frame indices to determine shape of data,
as the actual frames could still be split into different files.
Also can't assume a multiframe file is more than a single slice.
Corrects issue where order of slice indices was assumed to match
the order needed to move along the direction of the slice normal,
which resulted in slice orientation flips.

Ignores indices that don't evenly divide data, and at the end will
try to combine those indices (if needed) into a single tuple index.
Explicitly use `InStackPositionNumber` to identify the slice dim,
produce correct output for 2D + time data.
Not sure if this ever actually happens in real multiframe data, but
it does in non-multiframe and I can imagine if a
DimensionIndexSequence element refrences a per-frame AcquisitionTime
then this could happen.
@effigies effigies merged commit 33c6721 into nipy:master Jul 26, 2024
48 of 49 checks passed
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.

2 participants