InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.37k stars 660 forks source link

Dicom series loaded with incorrect origin and spacing (linked from SimpleITK) #4677

Closed chris-rapson-formus closed 1 month ago

chris-rapson-formus commented 1 month ago

Description

I am using SimpleITK to load DICOMs, and raised a ticket with them when some anonymised DICOMs loaded with incorrect origin and spacing. The relevant metadata seems fine, and can be read by other software. It was suggested that I should raise the ticket here.

For more details, please see the SimpleITK ticket.

github-actions[bot] commented 1 month ago

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜 Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

thewtex commented 1 month ago

Hi @chris-rapson-formus ,

There were a number of DICOM origin and spacing improvements made in ITK 5.4rc4. You could try:

pip install --upgrade --pre itk
import itk

image = itk.imread(dicom_folder)
print(itk.origin(image))
print(itk.spacing(image))
chris-rapson-formus commented 1 month ago

@thewtex Thanks for the suggestion. Unfortunately, itk v5.4 is still giving me the same origin and spacing.

>>> import itk
>>> image = itk.imread(dicom_folder)
>>> print(itk.origin(image))
itkPointD3 ([0, 0, 0])
>>> print(itk.spacing(image))
itkVectorD3 ([1, 1, 1])
>>> print(itk.__version__)
5.4.0
thewtex commented 1 month ago

Note that the tags can be listed with print(dict(image)).

@chris-rapson-formus based on your comment:

https://github.com/SimpleITK/SimpleITK/issues/2117#issuecomment-2116374415

The issue may be a removed 0018,0050 tag? See, for example, the discussion and DICOM standard links here: https://github.com/InsightSoftwareConsortium/ITK/pull/4521 . Tag interpretation is also modality dependent.

issakomi commented 1 month ago

What is the value of 'SOP Class UID' (0x0008, 0x0016)? And 0x0002,0x0002? Please prefer dcmdump or gdcmdump for reading attributes.

chris-rapson-formus commented 1 month ago

@thewtex Thanks for linking that discussion. It does look very similar, and the DICOMs were missing the 0018,0050 tags when I initially processed them. However, even after adding this tag, the spacing is still (1., 1., 1.) and the origin is still (0., 0., 0.,). The modality is CT, and that is also what is shown in 0008,0060.

@issakomi 0008,0016 SOP Class UID: 1.2.840.10008.5.1.4.1.1.7 0002,0002 Media Storage SOP Class UID: 1.2.840.10008.5.1.4.1.1.7 I've attached the dcmdump output from a file where I have manually added data for the three missing tags which I suspected were causing the problem (0018,0050, 0018,0088, 0020,1041). As noted above, the symptoms are unchanged even after adding in these tags using dcmodify.

issakomi commented 1 month ago

0008,0016 SOP Class UID: 1.2.840.10008.5.1.4.1.1.7 0002,0002 Media Storage SOP Class UID: 1.2.840.10008.5.1.4.1.1.7

Thank you. Support for Secondary Capture Image Storage has recently been improved (IPP/IOP will be read). It's likely that the ITK 5.4 version you're using doesn't have it (5.4 hasn't been released yet).

chris-rapson-formus commented 1 month ago

Thanks @issakomi, that makes sense. And I was able to confirm it - using the instructions from @thewtex, I had installed 5.4rc2. After updating pip, I was able to install 5.4rc4. Now I get the correct origin and spacing:

>>> import itk
>>> print(itk.__version__)
5.4.0
>>> image = itk.imread('dicom')
>>> print(itk.origin(image))
itkPointD3 ([-208.748, -260.748, 1014.1])
>>> print(itk.spacing(image))
itkVectorD3 ([0.503906, 0.503906, 0.6])

So it looks like there is already a fix and I should just wait for the ITK release (and for that release to filter through to SimpleITK). I'll close this ticket now.