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

Method __call__

monai/transforms/spatial/array.py:959–1010  ·  view source on GitHub ↗

Args: img: channel first array, must have shape: [chns, H, W] or [chns, H, W, D]. mode: {``"bilinear"``, ``"nearest"``} Interpolation mode to calculate output values. Defaults to ``self.mode``. See also: https://pytorch.org/docs/stable

(
        self,
        img: torch.Tensor,
        mode: str | None = None,
        padding_mode: str | None = None,
        align_corners: bool | None = None,
        dtype: DtypeLike | torch.dtype = None,
        lazy: bool | None = None,
    )

Source from the content-addressed store, hash-verified

957 self.dtype = dtype
958
959 def __call__(
960 self,
961 img: torch.Tensor,
962 mode: str | None = None,
963 padding_mode: str | None = None,
964 align_corners: bool | None = None,
965 dtype: DtypeLike | torch.dtype = None,
966 lazy: bool | None = None,
967 ) -> torch.Tensor:
968 """
969 Args:
970 img: channel first array, must have shape: [chns, H, W] or [chns, H, W, D].
971 mode: {``"bilinear"``, ``"nearest"``}
972 Interpolation mode to calculate output values. Defaults to ``self.mode``.
973 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
974 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
975 Padding mode for outside grid values. Defaults to ``self.padding_mode``.
976 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
977 align_corners: Defaults to ``self.align_corners``.
978 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
979 align_corners: Defaults to ``self.align_corners``.
980 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
981 dtype: data type for resampling computation. Defaults to ``self.dtype``.
982 If None, use the data type of input data. To be compatible with other modules,
983 the output data type is always ``float32``.
984 lazy: a flag to indicate whether this transform should execute lazily or not
985 during this call. Setting this to False or True overrides the ``lazy`` flag set
986 during initialization for this call. Defaults to None.
987
988 Raises:
989 ValueError: When ``img`` spatially is not one of [2D, 3D].
990
991 """
992 img = convert_to_tensor(img, track_meta=get_track_meta())
993 _dtype = get_equivalent_dtype(dtype or self.dtype or img.dtype, torch.Tensor)
994 _mode = mode or self.mode
995 _padding_mode = padding_mode or self.padding_mode
996 _align_corners = self.align_corners if align_corners is None else align_corners
997 im_shape = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:]
998 output_shape = im_shape if self.keep_size else None
999 lazy_ = self.lazy if lazy is None else lazy
1000 return rotate( # type: ignore
1001 img,
1002 self.angle,
1003 output_shape,
1004 _mode,
1005 _padding_mode,
1006 _align_corners,
1007 _dtype,
1008 lazy=lazy_,
1009 transform_info=self.get_transform_info(),
1010 )
1011
1012 def inverse(self, data: torch.Tensor) -> torch.Tensor:
1013 transform = self.pop_transform(data)

Callers

nothing calls this directly

Calls 6

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
get_equivalent_dtypeFunction · 0.90
rotateFunction · 0.90
peek_pending_shapeMethod · 0.80
get_transform_infoMethod · 0.80

Tested by

no test coverage detected