-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
GDCM Secondary Capture spatial metadata #4521
GDCM Secondary Capture spatial metadata #4521
Conversation
959a98a
to
1b97204
Compare
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.
This looks good to me, thanks for picking it up 👍
It would be great if someone with more knowledge of the ITK internals wants to also have a look, but I trust @thewtex has that covered so I'll approve.
> The path 'Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/privatedicts.xml' has size 1033 KiB, greater than allowed 1024 KiB.
Code extracted from: https://github.com/malaterre/GDCM.git at commit 06091299f2227f8470a4468821d231b760337ca0 (release).
# By GDCM Upstream * upstream-GDCM: GDCM 2024-03-25 (06091299)
This enables support for reading image orientation patient and image position patient from DICOM secondary capture images. This addresses needs such as reading Visible Human DICOM color images in 3D Slicer: NA-MIC/ProjectWeek#875 and reading highdicom derived secondary capture DICOM in ITK-Snap: ImagingDataCommons/highdicom#247 Update the RGB tests' baseline that were using a .png baseline because they now output spatial metadata.
This is using a Visible Male RGB slice secondary capture DICOM created by David Clunie as an input, described in Issue InsightSoftwareConsortium#4109.
ef5a1d5
to
8eb077a
Compare
Support has been merged into GDCM, thanks @malaterre @issakomi |
@thewtex I believe we discussed it at the last meeting that ITK used in Slicer (and in dcmqi) will be updated after ITK upstream update. Is this the plan, or should that be handled separately? |
I think @jcfr knows the ITK/Slicer update plans. This patch will be included in ITK 5.4rc3, tentatively this week. |
Merging for the 5.4rc3 release. |
Could you include more context. What is the test supposed to validate? Make sure to read DICOM CP 2330 and cc me if regression remains. thanks |
@seanm as @malaterre mentioned, there may be differences in output spatial metadata per DICOM CP 2330, but these are expected. |
So my coworker has reduced it to a small test case. Attached here: repro-case.zip For some DICOM files at least, With 193a2ed (aka
With f545dd8 it outputs:
|
S. here: case MediaStorage::SecondaryCaptureImageStorage:
if( ImageHelper::SecondaryCaptureImagePlaneModule ) {
// Make SecondaryCaptureImagePlaneModule act as ForcePixelSpacing
// This is different from Basic Pixel Spacing Calibration Macro Attributes
t = Tag(0x0028,0x0030);
} else {
t = Tag(0x0018,0x2010);
}
break; This change was not in the first PR malaterre/GDCM#158 (and not in the PR malaterre/GDCM#167) and the issue wouldn't happen with the PRs, it appears in the very final version. |
The DICOM files I provided were created by our app (via ITK, via GDCM), and the intended spacing when they were created was 0.5. So unless there is/was also a bug when writing files, the newer reader behaviour seems wrong to me. |
@issakomi given that your test set contains Nominal Scanned Pixel Spacing (0018,2010) only (with a 0.5mm value) and no other spacing related attributes, I would say the correct behavior for that test set is to return 0.5. I assume that a return value of 1 is the "default" (which I am not excited about since there is no reason it should be assumed to be 1 or anything else ... I might have used 0 to force a failure if it is used). Same goes for the third spacing value - there is no reason it should be 1 (and not, for example, 0) since there is no between slices spacing information in your test files. This has nothing to do with the case when Image Position (Patient), Image Orientation (Patient) and Pixel Spacing (0028,0030) are present, which would then override any Nominal Scanned Pixel Spacing (0018,2010) present (which ideally it would not be in that situation). FYI, the optional presence of the ImagePlane Module and accompanying note about relationship of spacing attributes is now standardized. |
Thank you. Yes, in fact the dataset only has a Nominal Scanned Pixel Spacing (0018,2010) and this attribute is ignored. This is erroneous.
This was proposed by malaterre/GDCM#158 and malaterre/GDCM#167. I am not sure why the final version is different. |
This updates the Lily.mha baseline to including spacing data and adds a new DICOM Secondary Capture input and check for an output spacing for 0.5, 0.5 instead of 1.0, 1.0 per the discussion in InsightSoftwareConsortium#4521. Co-authored-by: Sean McBride <[email protected]>
A follow-up can be found:
I am not sure, but there could be a reasonable attempt to make the function Thank you, @seanm, for finding and reporting the regression and providing the reproducible example. This has been added to the test suite. Thank you, @issakomi , @malaterre , @pieper , for working on the patches to improve DICOM support. Thank you, @dclunie, @fedorov for working on clarification and improvements to the standard. This has been a long-time thorn and impediment for DICOM adoption. I am glad we are making progress. Please review the patch by Monday: the community is understandably anxious to see the ITK 5.4 release minted, and we want to get it out. |
This updates the Lily.mha baseline to including spacing data and adds a new DICOM Secondary Capture input and check for an output spacing for 0.5, 0.5 instead of 1.0, 1.0 per the discussion in #4521. Co-authored-by: Sean McBride <[email protected]>
We've tried git master and we're back to the same behaviour as ITK 5.3. Thanks for fixing that! However like @dclunie said:
Indeed our files have neither
We agree 0.0 would be a better fallback, because 1.0 mm is a very common scan thickness, and one might think it's correct. |
@seanm thanks for verifying! The tag used for that dataset is Nominal Scanned Pixel Spacing (0018,2010). Setting the spacing to 0.0 would not be correct. Assigning an invalid default value to the spacing would be a hack approach to indicate that the spacing is not explicitly defined in the DICOM metadata. If the desire is to check whether spacing is explicitly defined, then it should be done at the application level, or an ivar on the DICOM |
@@ -454,6 +456,8 @@ GDCMImageIO::InternalReadImageInformation() | |||
|
|||
// In general this should be relatively safe to assume | |||
gdcm::ImageHelper::SetForceRescaleInterceptSlope(true); | |||
// Secondary capture image orientation patient and image position patient support | |||
gdcm::ImageHelper::SetSecondaryCaptureImagePlaneModule(true); |
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.
@thewtex Maybe something like
#if (!defined(ITK_USE_SYSTEM_GDCM) || ((GDCM_MAJOR_VERSION == 3 && GDCM_MINOR_VERSION == 0 && GDCM_BUILD_VERSION > 23) || GDCM_MAJOR_VERSION > 3))
#endif
around SetSecondaryCaptureImagePlaneModule? Otherwise, it may cause build failures using external GDCM. There is currently no version of GDCM with this feature.
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.
Fixes Slicer#7937 See original report here about a dataset being scrambled that loaded well in the 5.6.2 release: https://discourse.slicer.org/t/regression-in-the-dicom-data-base/37913 This corresponds to the change in behavior described here, where spacing from ITK that used to be 1 is now, for example 5 or -1: InsightSoftwareConsortium/ITK#4794 Which is believed to be due to the changes here, which was added so that for Secondary Capture files the spacing would be respected if present: InsightSoftwareConsortium/ITK#4521 However adding this code in GDCM meant that if the SpacingBetweenSlices tag is present, even in a CT, it is being used by ITK to calculate spacing, and also ITKToRAS transforms when trying to orthogonalize the transform. Since Slicer doesn't rely on orthogonal IJKToRAS transforms, this change tells ITK to skip that step and instead it relies on the positions and orientations of the slices to calculate the IJKToRAS transform, which is compatible with what Slicer expects. This code was tested on both the CT scan with the negative spacing that was reported in the original issue, and on other CT cans without that tag and the geometry matches what was obtained in 5.6.2. This change was discussed in the Slicer developer meeting 2024-10-08 and determined to be the best course of action. Further fixes in GDCM or ITK were not pursued because it was unclear whta the correct behavior should be at the library level considering that a negative spacing between slices is technically invalid for CT scans according to the DICOM standard.
Fixes #7937 See original report here about a dataset being scrambled that loaded well in the 5.6.2 release: https://discourse.slicer.org/t/regression-in-the-dicom-data-base/37913 This corresponds to the change in behavior described here, where spacing from ITK that used to be 1 is now, for example 5 or -1: InsightSoftwareConsortium/ITK#4794 Which is believed to be due to the changes here, which was added so that for Secondary Capture files the spacing would be respected if present: InsightSoftwareConsortium/ITK#4521 However adding this code in GDCM meant that if the SpacingBetweenSlices tag is present, even in a CT, it is being used by ITK to calculate spacing, and also ITKToRAS transforms when trying to orthogonalize the transform. Since Slicer doesn't rely on orthogonal IJKToRAS transforms, this change tells ITK to skip that step and instead it relies on the positions and orientations of the slices to calculate the IJKToRAS transform, which is compatible with what Slicer expects. This code was tested on both the CT scan with the negative spacing that was reported in the original issue, and on other CT cans without that tag and the geometry matches what was obtained in 5.6.2. This change was discussed in the Slicer developer meeting 2024-10-08 and determined to be the best course of action. Further fixes in GDCM or ITK were not pursued because it was unclear whta the correct behavior should be at the library level considering that a negative spacing between slices is technically invalid for CT scans according to the DICOM standard.
Support reading Secondary Capture spatial metadata with GDCM. Addresses issue #4109 , reading Visible Male RGB secondary capture spatial metadata. Also targeting support for highdicom generated SC re: ImagingDataCommons/highdicom#247.
This is a follow-up to #4111.
The corresponding patch was submitted to GDCM in malaterre/GDCM#158 and malaterre/GDCM#167.
Add tests with the Visible Male data.