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

Fix incorrect DICOMSeries order #1068

Merged

Conversation

Pandede
Copy link
Contributor

@Pandede Pandede commented Mar 17, 2024

Fixes #1067.
The root cause is the series order in DicomSeries.
The whole series shares the identical InstanceNumber. When DicomSeries._sort is invoked, the sorting is no longer sorted by InstanceNumber, but the filename:

# File order in local
[
  './DICOM/DICOM/ST000000/SE000001/MR000000',
  './DICOM/DICOM/ST000000/SE000001/MR000001',
  './DICOM/DICOM/ST000000/SE000001/MR000002',
  './DICOM/DICOM/ST000000/SE000001/MR000003',
  './DICOM/DICOM/ST000000/SE000001/MR000004',
  './DICOM/DICOM/ST000000/SE000001/MR000005',
  ...
]
# File order in Google Colab
[
  '/content/DICOM/DICOM/ST000000/SE000001/MR000020',
  '/content/DICOM/DICOM/ST000000/SE000001/MR000014',
  '/content/DICOM/DICOM/ST000000/SE000001/MR000015',
  '/content/DICOM/DICOM/ST000000/SE000001/MR000001',
  '/content/DICOM/DICOM/ST000000/SE000001/MR000011',
  ...
]

This makes function splitSerieIfRequired splits into 1 series in local while 8 series in Google Colab.
In summary, the series should not be sorted by filename, it should be sorted by the attribute ImagePositionPatient[2] (The z-index of the image?) in the DICOM file.

@Pandede Pandede force-pushed the fix-incorrect-dicom-series-order branch from 32d55e8 to 316ec97 Compare March 17, 2024 13:05
@FirefoxMetzger
Copy link
Contributor

the series should not be sorted by filename, it should be sorted by the attribute ImagePositionPatient[2] (The z-index of the image?) in the DICOM file

Yep, ImagePositionPatient[2] is similar to the z-order of the image stack. It's the z-component of a reference frame that is shared by all images in a series, so if you order by that you get consistent z-ordering and if you look at the values you get information on how far the scans are apart (the spacing along Z).

The whole series shares the identical InstanceNumber. When DicomSeries._sort is invoked, the sorting is no longer sorted by InstanceNumber, but the filename

To clarify: When the InstanceNumber is identical then python will keep files in the order in which they were listed by the OS. Most OS make no guarantees about the order they return when listing a filesystem. While this typically is alphabetical (especially for single disks) it isn't always the case for distributed disks ... and apparently S3 is one example where this is not the case.

Awesome detective work @Pandede - this would have taken me quite a while to find. 🚀

Copy link
Contributor

@FirefoxMetzger FirefoxMetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FirefoxMetzger FirefoxMetzger merged commit 259c545 into imageio:master Mar 18, 2024
21 checks passed
FirefoxMetzger pushed a commit that referenced this pull request Apr 15, 2024
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.

Only partial DICOM layers loading in Google Colab using imageio.volread
2 participants