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

Method __call__

monai/transforms/spatial/array.py:1642–1695  ·  view source on GitHub ↗

Args: img: channel first array, must have shape 2D: (nchannels, H, W), or 3D: (nchannels, H, W, D). mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``}, the interpolation mode. Defaults

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

Source from the content-addressed store, hash-verified

1640 self._zoom = ensure_tuple_rep(self._zoom[0], img.ndim - 2) + ensure_tuple(self._zoom[-1])
1641
1642 def __call__(
1643 self,
1644 img: torch.Tensor,
1645 mode: str | None = None,
1646 padding_mode: str | None = None,
1647 align_corners: bool | None = None,
1648 dtype: DtypeLike | torch.dtype = None,
1649 randomize: bool = True,
1650 lazy: bool | None = None,
1651 ) -> torch.Tensor:
1652 """
1653 Args:
1654 img: channel first array, must have shape 2D: (nchannels, H, W), or 3D: (nchannels, H, W, D).
1655 mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``,
1656 ``"area"``}, the interpolation mode. Defaults to ``self.mode``.
1657 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
1658 padding_mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``,
1659 ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``}
1660 available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}.
1661 One of the listed string values or a user supplied function. Defaults to ``"constant"``.
1662 The mode to pad data after zooming.
1663 See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html
1664 https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html
1665 align_corners: This only has an effect when mode is
1666 'linear', 'bilinear', 'bicubic' or 'trilinear'. Defaults to ``self.align_corners``.
1667 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
1668 dtype: data type for resampling computation. Defaults to ``self.dtype``.
1669 If None, use the data type of input data.
1670 randomize: whether to execute `randomize()` function first, default to True.
1671 lazy: a flag to indicate whether this transform should execute lazily or not
1672 during this call. Setting this to False or True overrides the ``lazy`` flag set
1673 during initialization for this call. Defaults to None.
1674 """
1675 # match the spatial image dim
1676 if randomize:
1677 self.randomize(img=img)
1678
1679 lazy_ = self.lazy if lazy is None else lazy
1680 if not self._do_transform:
1681 out = convert_to_tensor(img, track_meta=get_track_meta(), dtype=torch.float32)
1682 else:
1683 xform = Zoom(
1684 self._zoom,
1685 keep_size=self.keep_size,
1686 mode=mode or self.mode,
1687 padding_mode=padding_mode or self.padding_mode,
1688 align_corners=self.align_corners if align_corners is None else align_corners,
1689 dtype=dtype or self.dtype,
1690 lazy=lazy_,
1691 **self.kwargs,
1692 )
1693 out = xform(img)
1694 self.push_transform(out, replace=True, lazy=lazy_)
1695 return out # type: ignore
1696
1697 def inverse(self, data: torch.Tensor) -> torch.Tensor:
1698 xform_info = self.pop_transform(data)

Callers

nothing calls this directly

Calls 5

randomizeMethod · 0.95
convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
ZoomClass · 0.85
push_transformMethod · 0.80

Tested by

no test coverage detected