Args: img: shape must be (num_channels, H, W[, D]), spatial_size: output image spatial size. if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, the transform will use the spatial size of `img`.
(
self,
img: torch.Tensor,
spatial_size: Sequence[int] | int | None = None,
mode: str | int | None = None,
padding_mode: str | None = None,
lazy: bool | None = None,
)
| 2285 | self._lazy = val |
| 2286 | |
| 2287 | def __call__( |
| 2288 | self, |
| 2289 | img: torch.Tensor, |
| 2290 | spatial_size: Sequence[int] | int | None = None, |
| 2291 | mode: str | int | None = None, |
| 2292 | padding_mode: str | None = None, |
| 2293 | lazy: bool | None = None, |
| 2294 | ) -> torch.Tensor | tuple[torch.Tensor, NdarrayOrTensor]: |
| 2295 | """ |
| 2296 | Args: |
| 2297 | img: shape must be (num_channels, H, W[, D]), |
| 2298 | spatial_size: output image spatial size. |
| 2299 | if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, |
| 2300 | the transform will use the spatial size of `img`. |
| 2301 | if `img` has two spatial dimensions, `spatial_size` should have 2 elements [h, w]. |
| 2302 | if `img` has three spatial dimensions, `spatial_size` should have 3 elements [h, w, d]. |
| 2303 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
| 2304 | Interpolation mode to calculate output values. Defaults to ``self.mode``. |
| 2305 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 2306 | When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used |
| 2307 | and the value represents the order of the spline interpolation. |
| 2308 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 2309 | padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} |
| 2310 | Padding mode for outside grid values. Defaults to ``self.padding_mode``. |
| 2311 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 2312 | When `mode` is an integer, using numpy/cupy backends, this argument accepts |
| 2313 | {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}. |
| 2314 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 2315 | lazy: a flag to indicate whether this transform should execute lazily or not |
| 2316 | during this call. Setting this to False or True overrides the ``lazy`` flag set |
| 2317 | during initialization for this call. Defaults to None. |
| 2318 | """ |
| 2319 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 2320 | img_size = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:] |
| 2321 | sp_size = fall_back_tuple(self.spatial_size if spatial_size is None else spatial_size, img_size) |
| 2322 | lazy_ = self.lazy if lazy is None else lazy |
| 2323 | _mode = mode if mode is not None else self.mode |
| 2324 | _padding_mode = padding_mode if padding_mode is not None else self.padding_mode |
| 2325 | grid, affine = self.affine_grid(spatial_size=sp_size, lazy=lazy_) |
| 2326 | |
| 2327 | return affine_func( # type: ignore |
| 2328 | img, |
| 2329 | affine, |
| 2330 | grid, |
| 2331 | self.resampler, |
| 2332 | sp_size, |
| 2333 | _mode, |
| 2334 | _padding_mode, |
| 2335 | True, |
| 2336 | self.image_only, |
| 2337 | lazy=lazy_, |
| 2338 | transform_info=self.get_transform_info(), |
| 2339 | ) |
| 2340 | |
| 2341 | @classmethod |
| 2342 | def compute_w_affine(cls, spatial_rank, mat, img_size, sp_size, align_corners: bool = False): |
nothing calls this directly
no test coverage detected