Args: img: input image to be resampled. It currently supports channel-first arrays with at most three spatial dimensions. dst_affine: destination affine matrix. Defaults to ``None``, which means the same as `img.affine`. the shape shou
(
self,
img: torch.Tensor,
dst_affine: torch.Tensor | None = None,
spatial_size: Sequence[int] | torch.Tensor | int | None = None,
mode: str | int | None = None,
padding_mode: str | None = None,
align_corners: bool | None = None,
dtype: DtypeLike = None,
lazy: bool | None = None,
)
| 171 | self.dtype = dtype |
| 172 | |
| 173 | def __call__( |
| 174 | self, |
| 175 | img: torch.Tensor, |
| 176 | dst_affine: torch.Tensor | None = None, |
| 177 | spatial_size: Sequence[int] | torch.Tensor | int | None = None, |
| 178 | mode: str | int | None = None, |
| 179 | padding_mode: str | None = None, |
| 180 | align_corners: bool | None = None, |
| 181 | dtype: DtypeLike = None, |
| 182 | lazy: bool | None = None, |
| 183 | ) -> torch.Tensor: |
| 184 | """ |
| 185 | Args: |
| 186 | img: input image to be resampled. It currently supports channel-first arrays with |
| 187 | at most three spatial dimensions. |
| 188 | dst_affine: destination affine matrix. Defaults to ``None``, which means the same as `img.affine`. |
| 189 | the shape should be `(r+1, r+1)` where `r` is the spatial rank of ``img``. |
| 190 | when `dst_affine` and `spatial_size` are None, the input will be returned without resampling, |
| 191 | but the data type will be `float32`. |
| 192 | spatial_size: output image spatial size. |
| 193 | if `spatial_size` and `self.spatial_size` are not defined, |
| 194 | the transform will compute a spatial size automatically containing the previous field of view. |
| 195 | if `spatial_size` is ``-1`` are the transform will use the corresponding input img size. |
| 196 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
| 197 | Interpolation mode to calculate output values. Defaults to ``self.mode``. |
| 198 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 199 | When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used |
| 200 | and the value represents the order of the spline interpolation. |
| 201 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 202 | padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} |
| 203 | Padding mode for outside grid values. Defaults to ``self.padding_mode``. |
| 204 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 205 | When `mode` is an integer, using numpy/cupy backends, this argument accepts |
| 206 | {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}. |
| 207 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 208 | align_corners: Geometrically, we consider the pixels of the input as squares rather than points. |
| 209 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 210 | Defaults to ``None``, effectively using the value of `self.align_corners`. |
| 211 | dtype: data type for resampling computation. Defaults to ``self.dtype`` or |
| 212 | ``np.float64`` (for best precision). If ``None``, use the data type of input data. |
| 213 | To be compatible with other modules, the output data type is always `float32`. |
| 214 | lazy: a flag to indicate whether this transform should execute lazily or not |
| 215 | during this call. Setting this to False or True overrides the ``lazy`` flag set |
| 216 | during initialization for this call. Defaults to None. |
| 217 | The spatial rank is determined by the smallest among ``img.ndim -1``, ``len(src_affine) - 1``, and ``3``. |
| 218 | |
| 219 | When both ``monai.config.USE_COMPILED`` and ``align_corners`` are set to ``True``, |
| 220 | MONAI's resampling implementation will be used. |
| 221 | Set `dst_affine` and `spatial_size` to `None` to turn off the resampling step. |
| 222 | """ |
| 223 | # get dtype as torch (e.g., torch.float64) |
| 224 | dtype_pt = get_equivalent_dtype(dtype or self.dtype or img.dtype, torch.Tensor) |
| 225 | align_corners = align_corners if align_corners is not None else self.align_corners |
| 226 | mode = mode if mode is not None else self.mode |
| 227 | padding_mode = padding_mode if padding_mode is not None else self.padding_mode |
| 228 | lazy_ = self.lazy if lazy is None else lazy |
| 229 | return spatial_resample( |
| 230 | img, |
nothing calls this directly
no test coverage detected