def __init__( self, keys, pixdim, diagonal=False, mode="nearest", cval=0, interp_order=3, dtype=None, meta_key_format="{}.{}" ): """ Args: pixdim (sequence of floats): output voxel spacing. diagonal (bool): whether to resample the input to have a diagonal affine matrix. If True, the input data is resampled to the following affine:: np.diag((pixdim_0, pixdim_1, pixdim_2, 1)) This effectively resets the volume to the world coordinate system (RAS+ in nibabel). The original orientation, rotation, shearing are not preserved. If False, the axes orientation, orthogonal rotation and translations components from the original affine will be preserved in the target affine. This option will not flip/swap axes against the original ones. mode (`reflect|constant|nearest|mirror|wrap`): The mode parameter determines how the input array is extended beyond its boundaries. Default is 'nearest'. cval (scalar): Value to fill past edges of input if mode is "constant". Default is 0.0. interp_order (int or sequence of ints): int: the same interpolation order for all data indexed by `self.keys`; sequence of ints, should correspond to an interpolation order for each data item indexed by `self.keys` respectively. dtype (None or np.dtype): output array data type, defaults to None to use input data's dtype. meta_key_format (str): key format to read/write affine matrices to the data dictionary. """ super().__init__(keys) self.spacing_transform = Spacing(pixdim, diagonal=diagonal, mode=mode, cval=cval, dtype=dtype) interp_order = ensure_tuple(interp_order) self.interp_order = interp_order if len(interp_order) == len(self.keys) else interp_order * len(self.keys) self.meta_key_format = meta_key_format
def __init__( self, keys: KeysCollection, pixdim: Sequence[float], diagonal: bool = False, mode: GridSampleModeSequence = GridSampleMode.BILINEAR, padding_mode: GridSamplePadModeSequence = GridSamplePadMode.BORDER, align_corners: Union[Sequence[bool], bool] = False, dtype: Optional[Union[Sequence[np.dtype], np.dtype]] = np.float64, meta_key_postfix: str = "meta_dict", ) -> None: """ Args: pixdim: output voxel spacing. diagonal: whether to resample the input to have a diagonal affine matrix. If True, the input data is resampled to the following affine:: np.diag((pixdim_0, pixdim_1, pixdim_2, 1)) This effectively resets the volume to the world coordinate system (RAS+ in nibabel). The original orientation, rotation, shearing are not preserved. If False, the axes orientation, orthogonal rotation and translations components from the original affine will be preserved in the target affine. This option will not flip/swap axes against the original ones. 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 ``"border"``. 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``. align_corners: Geometrically, we consider the pixels of the input as squares rather than points. See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample It also can be a sequence of bool, each element corresponds to a key in ``keys``. dtype: data type for resampling computation. Defaults to ``np.float64`` for best precision. If None, use the data type of input data. To be compatible with other modules, the output data type is always ``np.float32``. It also can be a sequence of np.dtype, each element corresponds to a key in ``keys``. meta_key_postfix: use `key_{postfix}` to to fetch the meta data according to the key data, default is `meta_dict`, the meta data is a dictionary object. For example, to handle key `image`, read/write affine matrices from the metadata `image_meta_dict` dictionary's `affine` field. Raises: TypeError: When ``meta_key_postfix`` is not a ``str``. """ super().__init__(keys) self.spacing_transform = Spacing(pixdim, diagonal=diagonal) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.padding_mode = ensure_tuple_rep(padding_mode, len(self.keys)) self.align_corners = ensure_tuple_rep(align_corners, len(self.keys)) self.dtype = ensure_tuple_rep(dtype, len(self.keys)) if not isinstance(meta_key_postfix, str): raise TypeError(f"meta_key_postfix must be a str but is {type(meta_key_postfix).__name__}.") self.meta_key_postfix = meta_key_postfix
def __init__( self, keys: KeysCollection, pixdim, diagonal: bool = False, mode: GridSampleModeSequence = GridSampleMode.BILINEAR, padding_mode: GridSamplePadModeSequence = GridSamplePadMode.BORDER, dtype: Optional[Union[Sequence[np.dtype], np.dtype]] = None, meta_key_postfix: str = "meta_dict", ): """ Args: pixdim (sequence of floats): output voxel spacing. diagonal: whether to resample the input to have a diagonal affine matrix. If True, the input data is resampled to the following affine:: np.diag((pixdim_0, pixdim_1, pixdim_2, 1)) This effectively resets the volume to the world coordinate system (RAS+ in nibabel). The original orientation, rotation, shearing are not preserved. If False, the axes orientation, orthogonal rotation and translations components from the original affine will be preserved in the target affine. This option will not flip/swap axes against the original ones. 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 ``"border"``. 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``. dtype (None or np.dtype or sequence of np.dtype): output array data type. Defaults to None to use input data's dtype. It also can be a sequence of np.dtype, each element corresponds to a key in ``keys``. meta_key_postfix: use `key_{postfix}` to to fetch the meta data according to the key data, default is `meta_dict`, the meta data is a dictionary object. For example, to handle key `image`, read/write affine matrices from the metadata `image_meta_dict` dictionary's `affine` field. Raises: ValueError: meta_key_postfix must be a string. """ super().__init__(keys) self.spacing_transform = Spacing(pixdim, diagonal=diagonal) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.padding_mode = ensure_tuple_rep(padding_mode, len(self.keys)) self.dtype = ensure_tuple_rep(dtype, len(self.keys)) if not isinstance(meta_key_postfix, str): raise ValueError("meta_key_postfix must be a string.") self.meta_key_postfix = meta_key_postfix
def __init__( self, keys: KeysCollection, pixdim, diagonal: bool = False, interp_order: str = "bilinear", mode: str = "border", dtype: Optional[np.dtype] = None, meta_key_postfix: str = "meta_dict", ): """ Args: pixdim (sequence of floats): output voxel spacing. diagonal: whether to resample the input to have a diagonal affine matrix. If True, the input data is resampled to the following affine:: np.diag((pixdim_0, pixdim_1, pixdim_2, 1)) This effectively resets the volume to the world coordinate system (RAS+ in nibabel). The original orientation, rotation, shearing are not preserved. If False, the axes orientation, orthogonal rotation and translations components from the original affine will be preserved in the target affine. This option will not flip/swap axes against the original ones. interp_order (`nearest|bilinear` or a sequence of str): str: the same interpolation order for all data indexed by `self.keys`; sequence of str, should correspond to an interpolation order for each data item indexed by `self.keys` respectively. Defaults to `bilinear`. mode (str or sequence of str): Available options are `zeros|border|reflection`. The mode parameter determines how the input array is extended beyond its boundaries. Default is 'border'. dtype (None or np.dtype or sequence of np.dtype): output array data type. Defaults to None to use input data's dtype. meta_key_postfix: use `key_{postfix}` to to fetch the meta data according to the key data, default is `meta_dict`, the meta data is a dictionary object. For example, to handle key `image`, read/write affine matrices from the metadata `image_meta_dict` dictionary's `affine` field. """ super().__init__(keys) self.spacing_transform = Spacing(pixdim, diagonal=diagonal) self.interp_order = ensure_tuple_rep(interp_order, len(self.keys)) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.dtype = ensure_tuple_rep(dtype, len(self.keys)) if not isinstance(meta_key_postfix, str): raise ValueError("meta_key_postfix must be a string.") self.meta_key_postfix = meta_key_postfix
def __init__( self, keys: Hashable, pixdim, diagonal: bool = False, interp_order: str = "bilinear", mode: str = "border", dtype: Optional[np.dtype] = None, meta_key_format: str = "{}.{}", ): """ Args: pixdim (sequence of floats): output voxel spacing. diagonal (bool): whether to resample the input to have a diagonal affine matrix. If True, the input data is resampled to the following affine:: np.diag((pixdim_0, pixdim_1, pixdim_2, 1)) This effectively resets the volume to the world coordinate system (RAS+ in nibabel). The original orientation, rotation, shearing are not preserved. If False, the axes orientation, orthogonal rotation and translations components from the original affine will be preserved in the target affine. This option will not flip/swap axes against the original ones. interp_order (`nearest|bilinear` or a squence of str): str: the same interpolation order for all data indexed by `self.keys`; sequence of str, should correspond to an interpolation order for each data item indexed by `self.keys` respectively. Defaults to `bilinear`. mode (str or sequence of str): Available options are `zeros|border|reflection`. The mode parameter determines how the input array is extended beyond its boundaries. Default is 'border'. dtype (None or np.dtype or sequence of np.dtype): output array data type. Defaults to None to use input data's dtype. meta_key_format (str): key format to read/write affine matrices to the data dictionary. """ super().__init__(keys) self.spacing_transform = Spacing(pixdim, diagonal=diagonal) self.interp_order = ensure_tuple_rep(interp_order, len(self.keys)) self.mode = ensure_tuple_rep(mode, len(self.keys)) self.dtype = ensure_tuple_rep(dtype, len(self.keys)) self.meta_key_format = meta_key_format