76
76
issequenceiterable ,
77
77
optional_import ,
78
78
)
79
+ from monai .utils .deprecate_utils import deprecated_arg_default
79
80
from monai .utils .enums import GridPatchSort , PatchKeys , TraceKeys , TransformBackends
80
81
from monai .utils .misc import ImageMetaKey as Key
81
82
from monai .utils .module import look_up_option
@@ -557,6 +558,15 @@ class Orientation(InvertibleTransform, LazyTransform):
557
558
558
559
backend = [TransformBackends .NUMPY , TransformBackends .TORCH ]
559
560
561
+ @deprecated_arg_default (
562
+ name = "labels" ,
563
+ old_default = (("L" , "R" ), ("P" , "A" ), ("I" , "S" )),
564
+ new_default = None ,
565
+ msg_suffix = (
566
+ "Default value changed to None meaning that the transform now uses the 'space' of a "
567
+ "meta-tensor, if applicable, to determine appropriate axis labels."
568
+ ),
569
+ )
560
570
def __init__ (
561
571
self ,
562
572
axcodes : str | None = None ,
@@ -574,9 +584,14 @@ def __init__(
574
584
as_closest_canonical: if True, load the image as closest to canonical axis format.
575
585
labels: optional, None or sequence of (2,) sequences
576
586
(2,) sequences are labels for (beginning, end) of output axis.
577
- Defaults to using the ``"space"`` attribute of a metatensor,
578
- where appliable, or (('L', 'R'), ('P', 'A'), ('I', 'S'))``
579
- otherwise (i.e. for plain tensors).
587
+ If ``None``, an appropriate value is chosen depending on the
588
+ value of the ``"space"`` metadata item of a metatensor: if
589
+ ``"space"`` is ``"LPS"``, the value used is ``(('R', 'L'),
590
+ ('A', 'P'), ('I', 'S'))``, if ``"space"`` is ``"RPS"`` or the
591
+ input is not a meta-tensor or has no ``"space"`` item, the
592
+ value ``(('L', 'R'), ('P', 'A'), ('I', 'S'))`` is used. If not
593
+ ``None``, the provided value is always used and the ``"space"``
594
+ metadata item (if any) of the intput is ignored.
580
595
lazy: a flag to indicate whether this transform should execute lazily or not.
581
596
Defaults to False
582
597
@@ -628,7 +643,11 @@ def __call__(self, data_array: torch.Tensor, lazy: bool | None = None) -> torch.
628
643
affine_ = to_affine_nd (sr , affine_np )
629
644
630
645
# Set up "labels" such that LPS tensors are handled correctly by default
631
- if self .labels is None and SpaceKeys (data_array .meta ["space" ]) == SpaceKeys .LPS :
646
+ if (
647
+ self .labels is None
648
+ and "space" in data_array .meta
649
+ and SpaceKeys (data_array .meta ["space" ]) == SpaceKeys .LPS
650
+ ):
632
651
labels = (("R" , "L" ), ("A" , "P" ), ("I" , "S" )) # value for LPS
633
652
634
653
else :
@@ -665,7 +684,12 @@ def inverse(self, data: torch.Tensor) -> torch.Tensor:
665
684
labels = self .labels
666
685
667
686
# Set up "labels" such that LPS tensors are handled correctly by default
668
- if isinstance (data , MetaTensor ) and self .labels is None and SpaceKeys (data .meta ["space" ]) == SpaceKeys .LPS :
687
+ if (
688
+ isinstance (data , MetaTensor )
689
+ and self .labels is None
690
+ and "space" in data .meta
691
+ and SpaceKeys (data .meta ["space" ]) == SpaceKeys .LPS
692
+ ):
669
693
labels = (("R" , "L" ), ("A" , "P" ), ("I" , "S" )) # value for LPS
670
694
671
695
orig_axcodes = nib .orientations .aff2axcodes (orig_affine , labels = labels )
0 commit comments