Args: img: channel first array, must have shape 2D: (nchannels, H, W), or 3D: (nchannels, H, W, D). mode: {``"bilinear"``, ``"nearest"``} Interpolation mode to calculate output values. Defaults to ``self.mode``. See also: https://pytor
(
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,
)
| 1380 | self.z = self.R.uniform(low=self.range_z[0], high=self.range_z[1]) |
| 1381 | |
| 1382 | def __call__( |
| 1383 | self, |
| 1384 | img: torch.Tensor, |
| 1385 | mode: str | None = None, |
| 1386 | padding_mode: str | None = None, |
| 1387 | align_corners: bool | None = None, |
| 1388 | dtype: DtypeLike | torch.dtype = None, |
| 1389 | randomize: bool = True, |
| 1390 | lazy: bool | None = None, |
| 1391 | ): |
| 1392 | """ |
| 1393 | Args: |
| 1394 | img: channel first array, must have shape 2D: (nchannels, H, W), or 3D: (nchannels, H, W, D). |
| 1395 | mode: {``"bilinear"``, ``"nearest"``} |
| 1396 | Interpolation mode to calculate output values. Defaults to ``self.mode``. |
| 1397 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 1398 | padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} |
| 1399 | Padding mode for outside grid values. Defaults to ``self.padding_mode``. |
| 1400 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 1401 | align_corners: Defaults to ``self.align_corners``. |
| 1402 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 1403 | dtype: data type for resampling computation. Defaults to ``self.dtype``. |
| 1404 | If None, use the data type of input data. To be compatible with other modules, |
| 1405 | the output data type is always ``float32``. |
| 1406 | randomize: whether to execute `randomize()` function first, default to True. |
| 1407 | lazy: a flag to indicate whether this transform should execute lazily or not |
| 1408 | during this call. Setting this to False or True overrides the ``lazy`` flag set |
| 1409 | during initialization for this call. Defaults to None. |
| 1410 | """ |
| 1411 | if randomize: |
| 1412 | self.randomize() |
| 1413 | |
| 1414 | lazy_ = self.lazy if lazy is None else lazy |
| 1415 | if self._do_transform: |
| 1416 | ndim = len(img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:]) |
| 1417 | rotator = Rotate( |
| 1418 | angle=self.x if ndim == 2 else (self.x, self.y, self.z), |
| 1419 | keep_size=self.keep_size, |
| 1420 | mode=mode or self.mode, |
| 1421 | padding_mode=padding_mode or self.padding_mode, |
| 1422 | align_corners=self.align_corners if align_corners is None else align_corners, |
| 1423 | dtype=dtype or self.dtype or img.dtype, |
| 1424 | lazy=lazy_, |
| 1425 | ) |
| 1426 | out = rotator(img) |
| 1427 | else: |
| 1428 | out = convert_to_tensor(img, track_meta=get_track_meta(), dtype=torch.float32) |
| 1429 | self.push_transform(out, replace=True, lazy=lazy_) |
| 1430 | return out |
| 1431 | |
| 1432 | def inverse(self, data: torch.Tensor) -> torch.Tensor: |
| 1433 | xform_info = self.pop_transform(data) |
nothing calls this directly
no test coverage detected