BF: Resolve slice starts against axis length in slice_affine - #1534
BF: Resolve slice starts against axis length in slice_affine#1534wterrr wants to merge 1 commit into
Conversation
`SpatialFirstSlicer.slice_affine` copied `subslicer.start` straight into the affine translation. Two cases were therefore wrong: * A negative start (``img.slicer[-2:]``) put the negative value into the affine instead of the equivalent positive index. * A negative step with an implicit start (``img.slicer[::-1]``) used 0 as the origin, but the first voxel of the result is the *last* voxel of the axis. In both cases the returned data was correct while the affine was not, so the image was silently shifted in RAS+ space. ``img.slicer[-2:]`` and ``img.slicer[8:]`` select the same voxels but produced affines 20 mm apart. `nib-roi` is affected too, since it accepts negative starts and ``:-1`` steps and calls `slice_affine` directly. Resolve each spatial subslicer with `slice.indices()` so the transform is built from the concrete start and step that `dataobj[slicer]` uses. Closes nipygh-1533. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@wterrr The three follow-on pieces are up as wterrr#1 against this branch, opened on 27 July: the doctest update, an independent affine assertion in Flagging them here because two of them affect what this PR leaves behind:
The third is one line asserting Whichever is least work for you. If you would rather not take a PR into your branch, I can open the doctest and No rush from my side. I just did not want the doctest to slip through quietly. |
SpatialFirstSlicer.slice_affinecopiedsubslicer.startstraight into the affine translation. Two cases were therefore wrong:img.slicer[-2:]) put the negative value into the affine instead of the equivalent positive index.img.slicer[::-1]) used 0 as the origin, but the first voxel of the result is the last voxel of the axis.In both cases the returned data was correct while the affine was not, so the image was silently shifted in RAS+ space.
img.slicer[-2:]andimg.slicer[8:]select the same voxels but produced affines 20 mm apart.nib-roiis affected too, since it accepts negative starts and:-1steps and callsslice_affinedirectly.Resolve each spatial subslicer with
slice.indices()so the transform is built from the concrete start and step thatdataobj[slicer]uses.Closes gh-1533.