MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / Rand2DElastic

Class Rand2DElastic

monai/transforms/spatial/array.py:2655–2818  ·  view source on GitHub ↗

Random elastic deformation and affine in 2D. A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb.

Source from the content-addressed store, hash-verified

2653
2654
2655class Rand2DElastic(RandomizableTransform):
2656 """
2657 Random elastic deformation and affine in 2D.
2658 A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb.
2659
2660 """
2661
2662 backend = Resample.backend
2663
2664 def __init__(
2665 self,
2666 spacing: tuple[float, float] | float,
2667 magnitude_range: tuple[float, float],
2668 prob: float = 0.1,
2669 rotate_range: RandRange = None,
2670 shear_range: RandRange = None,
2671 translate_range: RandRange = None,
2672 scale_range: RandRange = None,
2673 spatial_size: tuple[int, int] | int | None = None,
2674 mode: str | int = GridSampleMode.BILINEAR,
2675 padding_mode: str = GridSamplePadMode.REFLECTION,
2676 device: torch.device | None = None,
2677 ) -> None:
2678 """
2679 Args:
2680 spacing : distance in between the control points.
2681 magnitude_range: the random offsets will be generated from ``uniform[magnitude[0], magnitude[1])``.
2682 prob: probability of returning a randomized elastic transform.
2683 defaults to 0.1, with 10% chance returns a randomized elastic transform,
2684 otherwise returns a ``spatial_size`` centered area extracted from the input image.
2685 rotate_range: angle range in radians. If element `i` is a pair of (min, max) values, then
2686 `uniform[rotate_range[i][0], rotate_range[i][1])` will be used to generate the rotation parameter
2687 for the `i`th spatial dimension. If not, `uniform[-rotate_range[i], rotate_range[i])` will be used.
2688 This can be altered on a per-dimension basis. E.g., `((0,3), 1, ...)`: for dim0, rotation will be
2689 in range `[0, 3]`, and for dim1 `[-1, 1]` will be used. Setting a single value will use `[-x, x]`
2690 for dim0 and nothing for the remaining dimensions.
2691 shear_range: shear range with format matching `rotate_range`, it defines the range to randomly select
2692 shearing factors(a tuple of 2 floats for 2D) for affine matrix, take a 2D affine as example::
2693
2694 [
2695 [1.0, params[0], 0.0],
2696 [params[1], 1.0, 0.0],
2697 [0.0, 0.0, 1.0],
2698 ]
2699
2700 translate_range: translate range with format matching `rotate_range`, it defines the range to randomly
2701 select pixel to translate for every spatial dims.
2702 scale_range: scaling range with format matching `rotate_range`. it defines the range to randomly select
2703 the scale factor to translate for every spatial dims. A value of 1.0 is added to the result.
2704 This allows 0 to correspond to no change (i.e., a scaling of 1.0).
2705 spatial_size: specifying output image spatial size [h, w].
2706 if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1,
2707 the transform will use the spatial size of `img`.
2708 if some components of the `spatial_size` are non-positive values, the transform will use the
2709 corresponding components of img size. For example, `spatial_size=(32, -1)` will be adapted
2710 to `(32, 64)` if the second spatial dimension size of img is `64`.
2711 mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
2712 Interpolation mode to calculate output values. Defaults to ``"bilinear"``.

Callers 2

__init__Method · 0.90
test_rand_2d_elasticMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_rand_2d_elasticMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…