Random affine transform. A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information.
| 2384 | |
| 2385 | |
| 2386 | class RandAffine(RandomizableTransform, InvertibleTransform, LazyTransform): |
| 2387 | """ |
| 2388 | Random affine transform. |
| 2389 | A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb. |
| 2390 | |
| 2391 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 2392 | for more information. |
| 2393 | """ |
| 2394 | |
| 2395 | backend = Affine.backend |
| 2396 | |
| 2397 | def __init__( |
| 2398 | self, |
| 2399 | prob: float = 0.1, |
| 2400 | rotate_range: RandRange = None, |
| 2401 | shear_range: RandRange = None, |
| 2402 | translate_range: RandRange = None, |
| 2403 | scale_range: RandRange = None, |
| 2404 | spatial_size: Sequence[int] | int | None = None, |
| 2405 | mode: str | int = GridSampleMode.BILINEAR, |
| 2406 | padding_mode: str = GridSamplePadMode.REFLECTION, |
| 2407 | cache_grid: bool = False, |
| 2408 | device: torch.device | None = None, |
| 2409 | lazy: bool = False, |
| 2410 | ) -> None: |
| 2411 | """ |
| 2412 | Args: |
| 2413 | prob: probability of returning a randomized affine grid. |
| 2414 | defaults to 0.1, with 10% chance returns a randomized grid. |
| 2415 | rotate_range: angle range in radians. If element `i` is a pair of (min, max) values, then |
| 2416 | `uniform[rotate_range[i][0], rotate_range[i][1])` will be used to generate the rotation parameter |
| 2417 | for the `i`th spatial dimension. If not, `uniform[-rotate_range[i], rotate_range[i])` will be used. |
| 2418 | This can be altered on a per-dimension basis. E.g., `((0,3), 1, ...)`: for dim0, rotation will be |
| 2419 | in range `[0, 3]`, and for dim1 `[-1, 1]` will be used. Setting a single value will use `[-x, x]` |
| 2420 | for dim0 and nothing for the remaining dimensions. |
| 2421 | shear_range: shear range with format matching `rotate_range`, it defines the range to randomly select |
| 2422 | shearing factors(a tuple of 2 floats for 2D, a tuple of 6 floats for 3D) for affine matrix, |
| 2423 | take a 3D affine as example:: |
| 2424 | |
| 2425 | [ |
| 2426 | [1.0, params[0], params[1], 0.0], |
| 2427 | [params[2], 1.0, params[3], 0.0], |
| 2428 | [params[4], params[5], 1.0, 0.0], |
| 2429 | [0.0, 0.0, 0.0, 1.0], |
| 2430 | ] |
| 2431 | |
| 2432 | translate_range: translate range with format matching `rotate_range`, it defines the range to randomly |
| 2433 | select pixel/voxel to translate for every spatial dims. |
| 2434 | scale_range: scaling range with format matching `rotate_range`. it defines the range to randomly select |
| 2435 | the scale factor to translate for every spatial dims. A value of 1.0 is added to the result. |
| 2436 | This allows 0 to correspond to no change (i.e., a scaling of 1.0). |
| 2437 | spatial_size: output image spatial size. |
| 2438 | if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, |
| 2439 | the transform will use the spatial size of `img`. |
| 2440 | if some components of the `spatial_size` are non-positive values, the transform will use the |
| 2441 | corresponding components of img size. For example, `spatial_size=(32, -1)` will be adapted |
| 2442 | to `(32, 64)` if the second spatial dimension size of img is `64`. |
| 2443 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
no outgoing calls
searching dependent graphs…