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

Method __init__

monai/transforms/spatial/array.py:2397–2490  ·  view source on GitHub ↗

Args: prob: probability of returning a randomized affine grid. defaults to 0.1, with 10% chance returns a randomized grid. rotate_range: angle range in radians. If element `i` is a pair of (min, max) values, then `uniform[rotate_range[

(
        self,
        prob: float = 0.1,
        rotate_range: RandRange = None,
        shear_range: RandRange = None,
        translate_range: RandRange = None,
        scale_range: RandRange = None,
        spatial_size: Sequence[int] | int | None = None,
        mode: str | int = GridSampleMode.BILINEAR,
        padding_mode: str = GridSamplePadMode.REFLECTION,
        cache_grid: bool = False,
        device: torch.device | None = None,
        lazy: bool = False,
    )

Source from the content-addressed store, hash-verified

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).
2444 Interpolation mode to calculate output values. Defaults to ``bilinear``.
2445 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2446 When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used
2447 and the value represents the order of the spline interpolation.
2448 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2449 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
2450 Padding mode for outside grid values. Defaults to ``reflection``.
2451 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2452 When `mode` is an integer, using numpy/cupy backends, this argument accepts
2453 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
2454 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html

Callers

nothing calls this directly

Calls 4

_init_identity_cacheMethod · 0.95
RandAffineGridClass · 0.85
ResampleClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected