Zooms an ND image using :py:class:`torch.nn.functional.interpolate`. For details, please see https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html. Different from :py:class:`monai.transforms.resize`, this transform takes scaling factors as input, and provid
| 1042 | |
| 1043 | |
| 1044 | class Zoom(InvertibleTransform, LazyTransform): |
| 1045 | """ |
| 1046 | Zooms an ND image using :py:class:`torch.nn.functional.interpolate`. |
| 1047 | For details, please see https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html. |
| 1048 | |
| 1049 | Different from :py:class:`monai.transforms.resize`, this transform takes scaling factors |
| 1050 | as input, and provides an option of preserving the input spatial size. |
| 1051 | |
| 1052 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 1053 | for more information. |
| 1054 | |
| 1055 | Args: |
| 1056 | zoom: The zoom factor along the spatial axes. |
| 1057 | If a float, zoom is the same for each spatial axis. |
| 1058 | If a sequence, zoom should contain one value for each spatial axis. |
| 1059 | mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``} |
| 1060 | The interpolation mode. Defaults to ``"area"``. |
| 1061 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html |
| 1062 | padding_mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, |
| 1063 | ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} |
| 1064 | available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. |
| 1065 | One of the listed string values or a user supplied function. Defaults to ``"edge"``. |
| 1066 | The mode to pad data after zooming. |
| 1067 | See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html |
| 1068 | https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html |
| 1069 | align_corners: This only has an effect when mode is |
| 1070 | 'linear', 'bilinear', 'bicubic' or 'trilinear'. Default: None. |
| 1071 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html |
| 1072 | dtype: data type for resampling computation. Defaults to ``float32``. |
| 1073 | If None, use the data type of input data. |
| 1074 | keep_size: Should keep original size (padding/slicing if needed), default is True. |
| 1075 | lazy: a flag to indicate whether this transform should execute lazily or not. |
| 1076 | Defaults to False |
| 1077 | kwargs: other arguments for the `np.pad` or `torch.pad` function. |
| 1078 | note that `np.pad` treats channel dimension as the first dimension. |
| 1079 | """ |
| 1080 | |
| 1081 | backend = [TransformBackends.TORCH] |
| 1082 | |
| 1083 | def __init__( |
| 1084 | self, |
| 1085 | zoom: Sequence[float] | float, |
| 1086 | mode: str = InterpolateMode.AREA, |
| 1087 | padding_mode: str = NumpyPadMode.EDGE, |
| 1088 | align_corners: bool | None = None, |
| 1089 | dtype: DtypeLike | torch.dtype = torch.float32, |
| 1090 | keep_size: bool = True, |
| 1091 | lazy: bool = False, |
| 1092 | **kwargs, |
| 1093 | ) -> None: |
| 1094 | LazyTransform.__init__(self, lazy=lazy) |
| 1095 | self.zoom = zoom |
| 1096 | self.mode = mode |
| 1097 | self.padding_mode = padding_mode |
| 1098 | self.align_corners = align_corners |
| 1099 | self.dtype = dtype |
| 1100 | self.keep_size = keep_size |
| 1101 | self.kwargs = kwargs |
no outgoing calls
searching dependent graphs…