Randomize k-space split axis in Motion (#81)#1485
Open
niravpatidar37 wants to merge 3 commits into
Open
Conversation
The Motion transform hardcoded the k-space segmentation to the first spatial axis. Add an `axes=(0, 1, 2)` option (mirroring `Ghosting`) and sample the split axis per application, recorded in the transform params so it is reproducible and per-instance when batched. Pass `axes=(0,)` to keep the previous fixed-axis behavior. The per-axis split is implemented with a vectorized per-element k-space mask, so each batch element can use its own axis. This also makes the implementation match the class docstring, which already documented the split as being "along a random axis". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #81.
The
Motiontransform splits k-space intonum_transforms + 1segments and fills each from a differently moved copy of the image. Previously the split was hardcoded to the first spatial axis, even though the class docstring already documented it as being "along a random axis".This PR randomizes the split axis, following the pattern already used by
Ghosting:axes=(0, 1, 2)constructor option. One axis is chosen at random per application.axes=(0,)to keep the previous fixed-axis behavior."axis"), so it is reproducible and works per-instance when the transform is applied to a batch.Implementation notes
_segment_mask), so each element in a batch can use its own axis without a Python loop over elements._check_segment_sizes, which validates the size of whichever axis is actually used (error message wording unchanged).Tests
TestMotionAxes:axesvalidation, axis recorded in params, the split axis is genuinely randomized across applications, and pinned-axis reproducibility.tests/test_motion.py,tests/test_ghosting.py,tests/test_vectorization.pyandtests/test_per_instance.pyall pass; the vectorization suite confirms the per-element axis handling matches element-by-element application.