Dictionary-based wrapper of :py:class:`monai.transforms.Transpose`.
| 634 | |
| 635 | |
| 636 | class Transposed(MapTransform, InvertibleTransform): |
| 637 | """ |
| 638 | Dictionary-based wrapper of :py:class:`monai.transforms.Transpose`. |
| 639 | """ |
| 640 | |
| 641 | backend = Transpose.backend |
| 642 | |
| 643 | def __init__(self, keys: KeysCollection, indices: Sequence[int] | None, allow_missing_keys: bool = False) -> None: |
| 644 | super().__init__(keys, allow_missing_keys) |
| 645 | self.transform = Transpose(indices) |
| 646 | |
| 647 | def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]: |
| 648 | d = dict(data) |
| 649 | for key in self.key_iterator(d): |
| 650 | d[key] = self.transform(d[key]) |
| 651 | # if None was supplied then numpy uses range(a.ndim)[::-1] |
| 652 | indices = self.transform.indices or range(d[key].ndim)[::-1] |
| 653 | self.push_transform(d, key, extra_info={"indices": indices}) |
| 654 | return d |
| 655 | |
| 656 | def inverse(self, data: Mapping[Hashable, Any]) -> dict[Hashable, Any]: |
| 657 | d = dict(data) |
| 658 | for key in self.key_iterator(d): |
| 659 | transform = self.get_most_recent_transform(d, key) |
| 660 | # Create inverse transform |
| 661 | fwd_indices = np.array(transform[TraceKeys.EXTRA_INFO]["indices"]) |
| 662 | inv_indices = np.argsort(fwd_indices) |
| 663 | inverse_transform = Transpose(inv_indices.tolist()) |
| 664 | # Apply inverse |
| 665 | d[key] = inverse_transform(d[key]) |
| 666 | # Remove the applied transform |
| 667 | self.pop_transform(d, key) |
| 668 | return d |
| 669 | |
| 670 | |
| 671 | class DeleteItemsd(MapTransform): |
no outgoing calls
searching dependent graphs…