Repository navigation
BUG: Fix case where DICOM series order has negative spacing - #6930
Conversation
If the spacing between slices is negative, then direction cosine matrix was not correct with reguards to the sign. This can be easily created with the "ReverseOrder" flag with the series reader and DICOM data. With the correction, a DICOM series mantains its correct physical location when this flag is enabled. (cherry picked from commit 5fdb32d)
(cherry picked from commit a3fa9fb)
a79471e to
447711c
Compare
|
| itkGDCMImageIOGTest.cxx | ||
| itkGDCMSeriesDirectionGTest.cxx | ||
| ) | ||
| creategoogletestdriver(ITKGDCMImageIO "${ITKIOGDCM-Test_LIBRARIES}" "${ITKGDCMImageIOGTests}") |
There was a problem hiding this comment.
The new tests are not included in ctest -L ITKIOGDCM. CreateGoogleTestDriver labels the executable, but it does not label the tests it discovers. Add ITKIOGDCM to the discovered tests so module-only runs include these regression checks.
Knowledge Base Used: Testing and continuous integration
| set_property( | ||
| TARGET | ||
| ITKGDCMImageIOGTestDriver | ||
| APPEND | ||
| PROPERTY | ||
| DEPENDS | ||
| ITKData | ||
| ) |
There was a problem hiding this comment.
Setting the target's DEPENDS property does not make ITKData a build prerequisite. If the external data has not been fetched, building this driver alone leaves ReadSlicesReverseOrder without its DICOM input. Use add_dependencies(ITKGDCMImageIOGTestDriver ITKData) instead.
| set_property( | |
| TARGET | |
| ITKGDCMImageIOGTestDriver | |
| APPEND | |
| PROPERTY | |
| DEPENDS | |
| ITKData | |
| ) | |
| add_dependencies(ITKGDCMImageIOGTestDriver ITKData) |
Knowledge Base Used: Testing and continuous integration
| std::array<double, 3> row = normalize3({ { ca, sa * cb, sa * sb } }); | ||
| std::array<double, 3> col = normalize3({ { -sa, ca * cb, ca * sb } }); | ||
| // Re-orthogonalize col against row (Gram–Schmidt) to keep DICOM happy. | ||
| double dot = row[0] * col[0] + row[1] * col[1] + row[2] * col[2]; | ||
| col = normalize3({ { col[0] - dot * row[0], col[1] - dot * row[1], col[2] - dot * row[2] } }); | ||
| auto n = normalize3(cross(row, col)); |
There was a problem hiding this comment.
The random orientation formula always gives a slice normal of (0, -sin(b), cos(b)). Changing a never changes that normal. The two oblique tests use the same formula, so none of these cases covers a slice direction with three nonzero components. Add a rotation about another axis or generate a full 3D frame to cover that case.
| #define _STRING(s) #s | ||
| #define TOSTRING(s) std::string(_STRING(s)) |
There was a problem hiding this comment.
Macros omit the required prefix
The new _STRING and TOSTRING macros violate the guide's required ITK_UPPERCASE_MACRO naming pattern. The same names appear in itkGDCMSeriesDirectionGTest.cxx. Rename them with an ITK_ prefix in both files. This repository requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
@thewtex @dzenanz @hjmjohnson A user (@zhurong2020) requested that (t)his DICOM fix be back ported to the 5.4 branch. What do you think of this change being back ported? greptile seems to be finding new issues in the test that is in main but just back ported. Should the test be removed from the back port? EDIT: missing t |
|
Thanks, Bradley. To clarify the attribution: the fix is #5357 (yours, with Hans's test). My part was the reproducer, the downstream report and the backport request. On whether it is worth backporting: any 5.4-based reader of series that carry a negative SpacingBetweenSlices (common on Philips CT) gets a volume that is silently mirrored along the slice axis, which downstream segmentation does not detect. On the test, I defer to the maintainers. |
|
@blowekamp I read greptile's findings as test-quality improvements (module label, a true build dependency on the test data, broader oblique-orientation coverage), not defects in the fix. The fix is sound and validated (17/17 new tests pass). For ROI I think the test is fine in the backport as is, and we should improve it in main. Draft #6940 does that, one commit per finding. The |
The non-deterministic nature of the reviews is difficult for back-ports of changes. The detected initial review comments and addressed in the main commit, but them more are created when the patch is back-ported. I am not sure if any policies could or should be changed to address this. |
|
@blowekamp I view this as "don't let pursuit of perfection be the enemy of the good". This backport is good as is and shouldn't be held up if resources can't reach perfection. I'll approve, but you can decide whether you have time/resources/desire to accept this good result as is, or wait for the #6940 from upstream. I'd merge this backport as is. The 6940 improvements are test-based and have better ROI on main than in the backport. |
thewtex
left a comment
There was a problem hiding this comment.
Thank you @blowekamp !
Agree with Hans re: perfect is the enemy of the good, fixing in the test code can be made on main, is not required here.
070c113
into
InsightSoftwareConsortium:release-5.4
…notes Add a Bug Fixes from ITK 5.4.8 section linking to SimpleITK issue SimpleITK#2292 and its upstream fix in InsightSoftwareConsortium/ITK#6930, which corrects an incorrect direction matrix computed by ImageSeriesReader when SpacingBetweenSlices sign disagreed with the slice ordering.
Backport of #5357 to release-5.4. Fixes incorrect direction-cosine sign when
DICOM slice order implies negative inter-slice spacing. Requested in #6859.
Backport notes
Cherry-picked the two upstream commits from #5357 unchanged. The GDCM module's
GoogleTest driver did not exist on release-5.4, so
Modules/IO/GDCM/test/CMakeLists.txtneeded manual merge (kept existing compliance tests, added the
creategoogletestdriverwiring from upstream). Fixed two-Wshadowwarningsin
itkImageSeriesReader.hxxintroduced by the cherry-pick (release-5.4 reusesa single loop variable
jin this function; main declares a fresh one per loop).AI assistance
CMakeLists.txt conflict, fixed the shadow warnings, built and ran tests
Local validation
cmake --build --preset default(full incremental build): succeeds, nowarnings in
itkImageSeriesReader.hxxITKGDCMImageIOGTestDriver --gtest_filter=GDCMSeriesDirection.*: 17/17 passedctest -L ITKIOGDCM: 40/41 passed (pre-existingITKIOGDCMKWStyleTestfailure, identical on upstream main — module's
ITKKWStyleOverwrite.txtdoesn't disable the
Namespacecheck foritkGDCMImageIOGTest.cxx; not aregression from this backport)
ctest -L ITKIOImageBase: 81/81 passed