Skip to content

Commit 2b50110

Browse files
Add docstring note that Transpose/Transposed do not update the affine matrix (#8888)
Closes #6711. ### Description This PR adds a documentation note to the `Transpose` and `Transposed` transforms clarifying that they do not update the affine matrix in the image metadata. As established in #5975, this is intended behavior: applying an affine-dependent transform such as `Spacing`/`Spacingd` after `Transpose`/`Transposed` can therefore produce unexpected results. The note points users to `Orientation`/`Orientationd` for affine-aware reorientation. This is a documentation-only change; no functional code is modified. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Akarsh Doki <doki.ak@northeastern.edu> Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
1 parent 15f5073 commit 2b50110

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎monai/transforms/utility/array.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ def __call__(self, img):
571571
class Transpose(Transform):
572572
"""
573573
Transposes the input image based on the given `indices` dimension ordering.
574+
575+
.. note::
576+
This transform does not update the affine matrix in the metadata. As a result,
577+
affine-dependent transforms applied after (e.g. :py:class:`monai.transforms.Spacing`)
578+
may produce unexpected results, because the affine no longer corresponds to the
579+
transposed data. To reorient medical images in an affine-aware way, use
580+
:py:class:`monai.transforms.Orientation` instead.
574581
"""
575582

576583
backend = [TransformBackends.TORCH]

‎monai/transforms/utility/dictionary.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,13 @@ def __call__(self, data: Mapping[Hashable, Any]) -> dict[Hashable, Any]:
636636
class Transposed(MapTransform, InvertibleTransform):
637637
"""
638638
Dictionary-based wrapper of :py:class:`monai.transforms.Transpose`.
639+
640+
.. note::
641+
This transform does not update the affine matrix in the metadata. As a result,
642+
affine-dependent transforms applied after (e.g. :py:class:`monai.transforms.Spacingd`)
643+
may produce unexpected results, because the affine no longer corresponds to the
644+
transposed data. To reorient medical images in an affine-aware way, use
645+
:py:class:`monai.transforms.Orientationd` instead.
639646
"""
640647

641648
backend = Transpose.backend

0 commit comments

Comments
 (0)