def __init__( self, keys: KeysCollection, spatial_size, spacing, magnitude_range, prob: float = 0.1, rotate_range=None, shear_range=None, translate_range=None, scale_range=None, mode: GridSampleModeSequence = GridSampleMode.BILINEAR, padding_mode: GridSamplePadModeSequence = GridSamplePadMode.REFLECTION, as_tensor_output: bool = False, device: Optional[torch.device] = None, ): """ Args: keys: keys of the corresponding items to be transformed. spatial_size (2 ints): specifying output image spatial size [h, w]. if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, the transform will use the spatial size of `img`. spacing (2 ints): distance in between the control points. magnitude_range (2 ints): the random offsets will be generated from ``uniform[magnitude[0], magnitude[1])``. prob: probability of returning a randomized affine grid. defaults to 0.1, with 10% chance returns a randomized grid, otherwise returns a ``spatial_size`` centered area extracted from the input image. mode: {``"bilinear"``, ``"nearest"``} Interpolation mode to calculate output values. Defaults to ``"bilinear"``. See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample It also can be a sequence of string, each element corresponds to a key in ``keys``. padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} Padding mode for outside grid values. Defaults to ``"reflection"``. See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample It also can be a sequence of string, each element corresponds to a key in ``keys``. as_tensor_output: the computation is implemented using pytorch tensors, this option specifies whether to convert it back to numpy arrays. device (torch.device): device on which the tensor will be allocated. See also: - :py:class:`RandAffineGrid` for the random affine parameters configurations. - :py:class:`Affine` for the affine transformation parameters configurations. """ super().__init__(keys) self.rand_2d_elastic = Rand2DElastic( spacing=spacing, magnitude_range=magnitude_range, prob=prob, rotate_range=rotate_range, shear_range=shear_range, translate_range=translate_range, scale_range=scale_range, spatial_size=spatial_size, as_tensor_output=as_tensor_output, device=device, ) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.padding_mode = ensure_tuple_rep(padding_mode, len(self.keys))
def __init__( self, keys, spatial_size, spacing, magnitude_range, prob=0.1, rotate_range=None, shear_range=None, translate_range=None, scale_range=None, mode="bilinear", padding_mode="zeros", as_tensor_output=False, device=None, ): """ Args: keys (Hashable items): keys of the corresponding items to be transformed. spatial_size (2 ints): specifying output image spatial size [h, w]. spacing (2 ints): distance in between the control points. magnitude_range (2 ints): the random offsets will be generated from ``uniform[magnitude[0], magnitude[1])``. prob (float): probability of returning a randomized affine grid. defaults to 0.1, with 10% chance returns a randomized grid, otherwise returns a ``spatial_size`` centered area extracted from the input image. mode ('nearest'|'bilinear'): interpolation order. Defaults to ``'bilinear'``. if mode is a tuple of interpolation mode strings, each string corresponds to a key in ``keys``. this is useful to set different modes for different data items. padding_mode ('zeros'|'border'|'reflection'): mode of handling out of range indices. Defaults to ``'zeros'``. as_tensor_output (bool): the computation is implemented using pytorch tensors, this option specifies whether to convert it back to numpy arrays. device (torch.device): device on which the tensor will be allocated. See also: - :py:class:`RandAffineGrid` for the random affine parameters configurations. - :py:class:`Affine` for the affine transformation parameters configurations. """ super().__init__(keys) default_mode = "bilinear" if isinstance(mode, (tuple, list)) else mode self.rand_2d_elastic = Rand2DElastic( spacing=spacing, magnitude_range=magnitude_range, prob=prob, rotate_range=rotate_range, shear_range=shear_range, translate_range=translate_range, scale_range=scale_range, spatial_size=spatial_size, mode=default_mode, padding_mode=padding_mode, as_tensor_output=as_tensor_output, device=device, ) self.mode = mode
def __init__( self, keys: KeysCollection, spacing: Union[Tuple[float, float], float], magnitude_range: Tuple[float, float], spatial_size: Optional[Union[Sequence[int], int]] = None, prob: float = 0.1, rotate_range: Optional[Union[Sequence[float], float]] = None, shear_range: Optional[Union[Sequence[float], float]] = None, translate_range: Optional[Union[Sequence[float], float]] = None, scale_range: Optional[Union[Sequence[float], float]] = None, mode: GridSampleModeSequence = GridSampleMode.BILINEAR, padding_mode: GridSamplePadModeSequence = GridSamplePadMode.REFLECTION, as_tensor_output: bool = False, device: Optional[torch.device] = None, ) -> None: """ Args: keys: keys of the corresponding items to be transformed. spacing: distance in between the control points. magnitude_range: 2 int numbers, the random offsets will be generated from ``uniform[magnitude[0], magnitude[1])``. spatial_size: specifying output image spatial size [h, w]. if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, the transform will use the spatial size of `img`. if the components of the `spatial_size` are non-positive values, the transform will use the corresponding components of img size. For example, `spatial_size=(32, -1)` will be adapted to `(32, 64)` if the second spatial dimension size of img is `64`. prob: probability of returning a randomized affine grid. defaults to 0.1, with 10% chance returns a randomized grid, otherwise returns a ``spatial_size`` centered area extracted from the input image. rotate_range: angle range in radians. rotate_range[0] with be used to generate the 1st rotation parameter from `uniform[-rotate_range[0], rotate_range[0])`. shear_range: shear_range[0] with be used to generate the 1st shearing parameter from `uniform[-shear_range[0], shear_range[0])`. Similarly, `shear_range[1]` controls the range of the uniform distribution used to generate the 2nd parameter. translate_range : translate_range[0] with be used to generate the 1st shift parameter from `uniform[-translate_range[0], translate_range[0])`. Similarly, `translate_range[1]` controls the range of the uniform distribution used to generate the 2nd parameter. scale_range: scaling_range[0] with be used to generate the 1st scaling factor from `uniform[-scale_range[0], scale_range[0]) + 1.0`. Similarly, `scale_range[1]` controls the range of the uniform distribution used to generate the 2nd parameter. mode: {``"bilinear"``, ``"nearest"``} Interpolation mode to calculate output values. Defaults to ``"bilinear"``. See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample It also can be a sequence of string, each element corresponds to a key in ``keys``. padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} Padding mode for outside grid values. Defaults to ``"reflection"``. See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample It also can be a sequence of string, each element corresponds to a key in ``keys``. as_tensor_output: the computation is implemented using pytorch tensors, this option specifies whether to convert it back to numpy arrays. device: device on which the tensor will be allocated. See also: - :py:class:`RandAffineGrid` for the random affine parameters configurations. - :py:class:`Affine` for the affine transformation parameters configurations. """ super().__init__(keys) self.rand_2d_elastic = Rand2DElastic( spacing=spacing, magnitude_range=magnitude_range, prob=prob, rotate_range=rotate_range, shear_range=shear_range, translate_range=translate_range, scale_range=scale_range, spatial_size=spatial_size, as_tensor_output=as_tensor_output, device=device, ) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.padding_mode = ensure_tuple_rep(padding_mode, len(self.keys))