Apply `self.func` to `img`. Args: func: Lambda/function to be applied. Defaults to `self.func`. Raises: TypeError: When ``func`` is not an ``Optional[Callable]``.
(self, img: NdarrayOrTensor, func: Callable | None = None)
| 817 | self.track_meta = track_meta |
| 818 | |
| 819 | def __call__(self, img: NdarrayOrTensor, func: Callable | None = None): |
| 820 | """ |
| 821 | Apply `self.func` to `img`. |
| 822 | |
| 823 | Args: |
| 824 | func: Lambda/function to be applied. Defaults to `self.func`. |
| 825 | |
| 826 | Raises: |
| 827 | TypeError: When ``func`` is not an ``Optional[Callable]``. |
| 828 | |
| 829 | """ |
| 830 | fn = func if func is not None else self.func |
| 831 | if not callable(fn): |
| 832 | raise TypeError(f"func must be None or callable but is {type(fn).__name__}.") |
| 833 | out = fn(img) |
| 834 | # convert to MetaTensor if necessary |
| 835 | if isinstance(out, (np.ndarray, torch.Tensor)) and not isinstance(out, MetaTensor) and self.track_meta: |
| 836 | out = MetaTensor(out) |
| 837 | if isinstance(out, MetaTensor): |
| 838 | self.push_transform(out) |
| 839 | return out |
| 840 | |
| 841 | def inverse(self, data: torch.Tensor): |
| 842 | if isinstance(data, MetaTensor): |
nothing calls this directly
no test coverage detected