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

Method __call__

monai/transforms/utility/array.py:921–947  ·  view source on GitHub ↗

Args: select_labels: labels to generate mask from. for 1 channel label, the `select_labels` is the expected label values, like: [1, 2, 3]. for One-Hot format label, the `select_labels` is the expected channel indices. merge_channels: w

(
        self, img: NdarrayOrTensor, select_labels: Sequence[int] | int | None = None, merge_channels: bool = False
    )

Source from the content-addressed store, hash-verified

919 self.merge_channels = merge_channels
920
921 def __call__(
922 self, img: NdarrayOrTensor, select_labels: Sequence[int] | int | None = None, merge_channels: bool = False
923 ) -> NdarrayOrTensor:
924 """
925 Args:
926 select_labels: labels to generate mask from. for 1 channel label, the `select_labels`
927 is the expected label values, like: [1, 2, 3]. for One-Hot format label, the
928 `select_labels` is the expected channel indices.
929 merge_channels: whether to use `np.any()` to merge the result on channel dim. if yes,
930 will return a single channel mask with binary data.
931 """
932 img = convert_to_tensor(img, track_meta=get_track_meta())
933 if select_labels is None:
934 select_labels = self.select_labels
935 else:
936 select_labels = ensure_tuple(select_labels)
937
938 if img.shape[0] > 1:
939 data = img[[*select_labels]]
940 else:
941 where: Callable = np.where if isinstance(img, np.ndarray) else torch.where # type: ignore
942 data = where(in1d(img, select_labels), True, False).reshape(img.shape)
943
944 if merge_channels or self.merge_channels:
945 return data.any(0)[None] # type: ignore
946
947 return data
948
949
950class FgBgToIndices(Transform, MultiSampleTrait):

Callers

nothing calls this directly

Calls 5

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
ensure_tupleFunction · 0.90
in1dFunction · 0.90
whereFunction · 0.85

Tested by

no test coverage detected