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

Method __call__

monai/transforms/spatial/array.py:812–888  ·  view source on GitHub ↗

Args: img: channel first array, must have shape: (num_channels, H[, W, ..., ]). mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``} The interpolation mode. Defaults to ``

(
        self,
        img: torch.Tensor,
        mode: str | None = None,
        align_corners: bool | None = None,
        anti_aliasing: bool | None = None,
        anti_aliasing_sigma: Sequence[float] | float | None = None,
        dtype: DtypeLike | torch.dtype = None,
        lazy: bool | None = None,
    )

Source from the content-addressed store, hash-verified

810 self.dtype = dtype
811
812 def __call__(
813 self,
814 img: torch.Tensor,
815 mode: str | None = None,
816 align_corners: bool | None = None,
817 anti_aliasing: bool | None = None,
818 anti_aliasing_sigma: Sequence[float] | float | None = None,
819 dtype: DtypeLike | torch.dtype = None,
820 lazy: bool | None = None,
821 ) -> torch.Tensor:
822 """
823 Args:
824 img: channel first array, must have shape: (num_channels, H[, W, ..., ]).
825 mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``,
826 ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``}
827 The interpolation mode. Defaults to ``self.mode``.
828 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
829 align_corners: This only has an effect when mode is
830 'linear', 'bilinear', 'bicubic' or 'trilinear'. Defaults to ``self.align_corners``.
831 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
832 anti_aliasing: bool, optional
833 Whether to apply a Gaussian filter to smooth the image prior
834 to downsampling. It is crucial to filter when downsampling
835 the image to avoid aliasing artifacts. See also ``skimage.transform.resize``
836 anti_aliasing_sigma: {float, tuple of floats}, optional
837 Standard deviation for Gaussian filtering used when anti-aliasing.
838 By default, this value is chosen as (s - 1) / 2 where s is the
839 downsampling factor, where s > 1. For the up-size case, s < 1, no
840 anti-aliasing is performed prior to rescaling.
841 dtype: data type for resampling computation. Defaults to ``self.dtype``.
842 If None, use the data type of input data.
843 lazy: a flag to indicate whether this transform should execute lazily or not
844 during this call. Setting this to False or True overrides the ``lazy`` flag set
845 during initialization for this call. Defaults to None.
846 Raises:
847 ValueError: When ``self.spatial_size`` length is less than ``img`` spatial dimensions.
848
849 """
850 anti_aliasing = self.anti_aliasing if anti_aliasing is None else anti_aliasing
851 anti_aliasing_sigma = self.anti_aliasing_sigma if anti_aliasing_sigma is None else anti_aliasing_sigma
852
853 input_ndim = img.ndim - 1 # spatial ndim
854 if self.size_mode == "all":
855 output_ndim = len(ensure_tuple(self.spatial_size))
856 if output_ndim > input_ndim:
857 input_shape = ensure_tuple_size(img.shape, output_ndim + 1, 1)
858 img = img.reshape(input_shape)
859 elif output_ndim < input_ndim:
860 raise ValueError(
861 "len(spatial_size) must be greater or equal to img spatial dimensions, "
862 f"got spatial_size={output_ndim} img={input_ndim}."
863 )
864 _sp = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:]
865 sp_size = fall_back_tuple(self.spatial_size, _sp)
866 else: # for the "longest" mode
867 img_size = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:]
868 if not isinstance(self.spatial_size, int):
869 raise ValueError("spatial_size must be an int number if size_mode is 'longest'.")

Callers

nothing calls this directly

Calls 8

ensure_tupleFunction · 0.90
ensure_tuple_sizeFunction · 0.90
fall_back_tupleFunction · 0.90
get_equivalent_dtypeFunction · 0.90
resizeFunction · 0.90
maxFunction · 0.85
peek_pending_shapeMethod · 0.80
get_transform_infoMethod · 0.80

Tested by

no test coverage detected