Repository navigation
BUG: Accept rounding in ImageOrientationPatient when ordering series - #7177
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
6dc3c16 to
93228d0
Compare
|
Commit 50dfb13 updates the migration guide. With this change I believe the guide is now inaccurate. I don't fully understand the issue, and there seems to be some occupation in the behavior and changes I haven't dug into to fully follow. |
93228d0 to
a08746b
Compare
gdcm::IPPSorter's default tolerance of 0 demands byte-identical ImageOrientationPatient strings, stricter than ITK 5.4's SerieHelper. GE MR series with per-slice rounded direction cosines then failed geometric ordering and threw, or fell back to Instance Number order and could produce a left-handed volume with reversed slices. Keep the exact-match sort first. When it fails, accept the series if every slice's unit row and column cosines are within 1e-6 (1 - cos, about 0.08 degrees) of the first slice's, and sort again with a loose IPPSorter tolerance, which compares unnormalized normals.
a08746b to
c77f723
Compare
|
Thanks @blowekamp — here is the failure in its simplest form. Take a three-slice axial MR series, slices 7 mm apart. Each DICOM file stores its own ImageOrientationPatient as text, and this GE scanner rounds each slice's copy independently:
The orientations are the same plane; the strings differ only in the eighth decimal.
In our 155-session clinical set this happened on 11 series from two GE scanner models (Genesis Signa and SIGNA Voyager) in 3 sessions, and nowhere else. Series with genuinely different orientations (localizers, a tilted slice, an in-plane rotated slice) are still rejected; 5.4 did not check those at all. You're right that the migration guide no longer matched. The |
|
@hjmjohnson I bisected this build failure: https://open.cdash.org/builds/11713417/build
to c77f723. |
|
I just bisected another thing to c77f723. This time a unit test of ours started failing with this commit. GetDidUseAmbiguousOrdering() returned true before, and after this commit now returns false (for some particular DICOM files in this test). In the new code, in This all seems related to #6468 and #6766. I'll have to dig more... |
GDCMSeriesFileNames(since itsgdcm::IPPSorterbackend, 50dfb13) sorts withIPPSorter's default direction-cosine tolerance of 0, which demands byte-identical ImageOrientationPatient strings. That is more stringent than ITK 5.4.8, whoseSerieHelpertook the slice normal from the first file and ordered every slice along it. Real GE MR series with independently rounded direction cosines now fail geometric ordering: the read throws, or withFailOnAmbiguousOrdering(false)falls back to Instance Number order and can produce a left-handed volume with reversed slices. This keeps the exact-match sort first and, only when it fails, accepts the series if every slice's unit row and column cosines are within1 - cos <= 1e-6(about 0.08 deg) of the first slice's. Norelease-5.4backport is needed: 5.4 does not useIPPSorter.Closes #7181. Related: #6467, #6469, #6468, #6656, #5357, #6766, #6940, #7152 (same files; whichever merges second needs a rebase), #6463, #7064.
Real data: where this was found
A 155-session clinical stroke MR test set from four vendors, read on current
mainwith the settings dcm-classifier uses (SetUseSeriesDetails(true),FailOnAmbiguousOrdering(false)). Series rejected byIPPSorteronly because their IOP strings differ by rounding:All other fallbacks were legitimate (multi-volume series with duplicate positions; localizers and other series with genuinely different planes); no other vendor's series failed this way.
Example (GE Genesis Signa, 2005): five 20-slice axial series, uniform 7.0 mm spacing, no gantry-tilt tag, one frame of reference, three distinct IOP strings per series differing by at most 1.6e-8. ITK 5.4.8: right-handed, ascending.
main:IPPSorterfails,GetDidUseAmbiguousOrdering()is true, and the Instance Number fallback yields det(direction) = -1 with the slice axis reversed (physically consistent because of 5fdb32d, but a different voxel order than 5.4.8, which changed downstream CNN results). The new contract test reproduces this rounding pattern; re-reading these clinical series with the fix is still to be done.Why 1e-6, measured
For small angles
1 - cos(theta) ~ theta^2 / 2, so1e-6admits at most 1.4 mrad (0.081 deg): 0.18 mm at 128 mm off-center, below one voxel at clinical MR resolutions (1e-4would admit 0.81 deg, 1.8 mm).On the 155-session set, every series with more than one IOP string, worst slice,
1 - n . n0on unit normals:1e-6sits more than six orders of magnitude above the largest rounding value and 76x below the smallest genuine difference. The check applies the same bound to the row and the column cosine separately, so an in-plane rotation or a flipped normal is rejected too (a normals-only check would accept the former).Compared with 5.4.8: equivalent for rounding; stricter for mixed orientations, which 5.4.8 ordered without checking.
Change and tests
itkGDCMSeriesFileNames.cxx:SortByPosition(files, 0.0)as before; if it fails,OrientationsAgree()scans ImageOrientationPatient, normalizes each slice's row and column cosines, and requires1 - r . r0 <= 1e-6and1 - c . c0 <= 1e-6; if so,SortByPosition(files, 1e-3)with a freshIPPSorter. A nonzeroIPPSortertolerance compares unnormalized normals, so a flat1e-6there would reject identical six-decimal orientations whose normal's squared length is about 1.2e-6 to 1.5e-6 off one (found by Greptile on the first push); the loose retry only absorbs that length error after ITK has applied the real bound. Gantry-tilt, frame-of-reference, and duplicate-position checks inIPPSorterare unchanged.itkGDCMSeriesFileNamesContractGTest.cxx(orientations derived from the test series' own oblique plane, slices taken in sorted name order):OrientationRoundingStillOrdersGeometrically: alternate slices' IOP off by 1e-8 (the GE pattern) must order geometrically, right-handed.IdenticalUnnormalizedOrientationOrders,RoundedUnnormalizedOrientationOrders: the plane rotated 45 deg in-plane at six decimals (and six vs seven) must order.SlightlyTiltedSliceIsAmbiguous: a 0.5 deg tilt (1 - cos = 3.8e-5, accepted by the loose retry alone) must be rejected.InPlaneRotatedSliceIsAmbiguous: same normal, rows and columns rotated 90 deg, must be rejected.DifferentPlaneSliceIsAmbiguous: a sagittal slice must be rejected.FailOnAmbiguousOrdering(false),GetDidUseAmbiguousOrdering().Local run (Linux, GCC, Release; ITK
main772f60f with this PR's two files):mainInPlaneRotatedSliceIsAmbiguous