MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __call__

Method __call__

monai/transforms/utility/array.py:819–839  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 2

MetaTensorClass · 0.90
push_transformMethod · 0.80

Tested by

no test coverage detected