From 5c930981f92bcd603b0b96d56ac16667f8b5cf64 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 11 Apr 2024 14:28:23 -0400 Subject: [PATCH 1/2] ENH: Add more tests for DICOM Secondary Capture Spacing 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 https://github.com/InsightSoftwareConsortium/ITK/pull/4521. Co-authored-by: Sean McBride --- Modules/IO/GDCM/test/Baseline/Lily.mha.cid | 2 +- ...geIOSecondaryCaptureSpacingTestBaseline.mha.cid | 1 + Modules/IO/GDCM/test/CMakeLists.txt | 14 ++++++++++++++ Modules/IO/GDCM/test/Input/image_slice0.dcm.cid | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Modules/IO/GDCM/test/Baseline/itkGDCMImageIOSecondaryCaptureSpacingTestBaseline.mha.cid create mode 100644 Modules/IO/GDCM/test/Input/image_slice0.dcm.cid diff --git a/Modules/IO/GDCM/test/Baseline/Lily.mha.cid b/Modules/IO/GDCM/test/Baseline/Lily.mha.cid index 35cf0d3a7b5..ae5bf585841 100644 --- a/Modules/IO/GDCM/test/Baseline/Lily.mha.cid +++ b/Modules/IO/GDCM/test/Baseline/Lily.mha.cid @@ -1 +1 @@ -bafkreidhatfhe2gdne5k5pyw2rfvnuu3qmedytq7mrdjckmw6zrc5x3srq +bafkreih4irpsshtdat5dvqmkdmgzguaol6qmz5mrskxtxmvjvrawuy32bq diff --git a/Modules/IO/GDCM/test/Baseline/itkGDCMImageIOSecondaryCaptureSpacingTestBaseline.mha.cid b/Modules/IO/GDCM/test/Baseline/itkGDCMImageIOSecondaryCaptureSpacingTestBaseline.mha.cid new file mode 100644 index 00000000000..d1959b85f88 --- /dev/null +++ b/Modules/IO/GDCM/test/Baseline/itkGDCMImageIOSecondaryCaptureSpacingTestBaseline.mha.cid @@ -0,0 +1 @@ +bafkreibzdrcgqyc3xtkxqh7rfpxf5oji35b2g5yujsaiwxltp3kwmxbixe diff --git a/Modules/IO/GDCM/test/CMakeLists.txt b/Modules/IO/GDCM/test/CMakeLists.txt index 6523d4de2a5..7e5411a53d5 100644 --- a/Modules/IO/GDCM/test/CMakeLists.txt +++ b/Modules/IO/GDCM/test/CMakeLists.txt @@ -86,6 +86,20 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOTest4.mha ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOTest4Rescaled.dcm ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOTest4Rescaled.mha) +itk_add_test( + NAME + itkGDCMImageIOSecondaryCaptureSpacingTest + COMMAND + ITKIOGDCMTestDriver + --compare + DATA{Baseline/itkGDCMImageIOSecondaryCaptureSpacingTestBaseline.mha} + ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOSecondaryCaptureSpacingTest.mha + itkGDCMImageIOTest + DATA{Input/image_slice0.dcm} + ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOSecondaryCaptureSpacingTest.dcm + ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOSecondaryCaptureSpacingTest.mha + ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOSecondaryCaptureSpacingTestRescaled.dcm + ${ITK_TEST_OUTPUT_DIR}/itkGDCMImageIOSecondaryCaptureSpacingTestRescaled.mha) itk_add_test( NAME itkGDCMImageIOTest5 diff --git a/Modules/IO/GDCM/test/Input/image_slice0.dcm.cid b/Modules/IO/GDCM/test/Input/image_slice0.dcm.cid new file mode 100644 index 00000000000..740d5398047 --- /dev/null +++ b/Modules/IO/GDCM/test/Input/image_slice0.dcm.cid @@ -0,0 +1 @@ +bafkreigjtwunwnt7ilfegmhub73amtuyzdueyzj6ykftp7usibs57b2aya From 86a0ad5eeedd72c1a2e6a8f02bcceec6ef30deaf Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 11 Apr 2024 14:41:59 -0400 Subject: [PATCH 2/2] BUG: Check for Secondary Capture spacing following DICOM Part 3 Sect A.8.1.3 Following the Secondary Capture Image IOD Module Note: > If Image Position (Patient) (0020,0032) and Image Orientation (Patient) (0020,0037) (from the Image Plane M odule) are present, then the values of Pixel Spacing (0028,0030) (from the Image Plane Module and the Basic Pixel Spacing Calibration Macro included from the SC Image Module) are intended to be used for 3D spatial computations , rather than any values of Nominal Scanned Pixel Spacing (0018,2010) (from the SC Image Module), which may also be present. However, we make sure to throw a warning in `ImageHelper::GetSpacingTagFromMediaStorage` when the tag for a S econdary Capture MediaStorage is requested and SecondaryCaptureImagePlaneModule is enabled because returning a si ngle tag is insufficient for this requirement. This function should not be called on this type of media storage. Pushed upstream here: https://github.com/malaterre/GDCM/pull/170 Co-authored-by: Mihail Isakov Co-authored-by: Mathieu Malaterre Co-authored-by: Steve Pieper --- .../gdcmImageHelper.cxx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx index 888412067f7..81878760b6d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx @@ -1278,6 +1278,9 @@ Tag ImageHelper::GetSpacingTagFromMediaStorage(MediaStorage const &ms) if( ImageHelper::SecondaryCaptureImagePlaneModule ) { // Make SecondaryCaptureImagePlaneModule act as ForcePixelSpacing // This is different from Basic Pixel Spacing Calibration Macro Attributes + // + // Per the note: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.8.html#sect_A.8.1.3 + gdcmWarningMacro( "FIXME: Multiple tags can identify Secondary Capture spacing. This function should not be used for Secondary Capture data." ); t = Tag(0x0028,0x0030); } else { t = Tag(0x0018,0x2010); @@ -1471,7 +1474,25 @@ std::vector ImageHelper::GetSpacingValue(File const & f) } } - Tag spacingtag = GetSpacingTagFromMediaStorage(ms); + Tag spacingtag = Tag(0xffff,0xffff); + if( ms == MediaStorage::SecondaryCaptureImageStorage && SecondaryCaptureImagePlaneModule ) + { + // See the note: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.8.html#sect_A.8.1.3 + if( ds.FindDataElement( Tag(0x0028,0x0030) ) ) + { + // Type 1C in 'SC Image' (for calibrated images) + spacingtag = Tag(0x0028,0x0030); + } + else if( ds.FindDataElement( Tag(0x0018,0x2010) ) ) + { + // Type 3 in 'SC Image' + spacingtag = Tag(0x0018,0x2010); + } + } + else + { + spacingtag = GetSpacingTagFromMediaStorage(ms); + } if( spacingtag != Tag(0xffff,0xffff) && ds.FindDataElement( spacingtag ) && !ds.GetDataElement( spacingtag ).IsEmpty() ) { const DataElement& de = ds.GetDataElement( spacingtag );