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

Class Resample

monai/transforms/spatial/array.py:2006–2176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2004
2005
2006class Resample(Transform):
2007 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
2008
2009 def __init__(
2010 self,
2011 mode: str | int = GridSampleMode.BILINEAR,
2012 padding_mode: str = GridSamplePadMode.BORDER,
2013 norm_coords: bool = True,
2014 device: torch.device | None = None,
2015 align_corners: bool = False,
2016 dtype: DtypeLike = np.float64,
2017 ) -> None:
2018 """
2019 computes output image using values from `img`, locations from `grid` using pytorch.
2020 supports spatially 2D or 3D (num_channels, H, W[, D]).
2021
2022 Args:
2023 mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
2024 Interpolation mode to calculate output values. Defaults to ``"bilinear"``.
2025 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2026 When `USE_COMPILED` is `True`, this argument uses
2027 ``"nearest"``, ``"bilinear"``, ``"bicubic"`` to indicate 0, 1, 3 order interpolations.
2028 See also: https://monai.readthedocs.io/en/stable/networks.html#grid-pull (experimental).
2029 When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used
2030 and the value represents the order of the spline interpolation.
2031 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2032 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
2033 Padding mode for outside grid values. Defaults to ``"border"``.
2034 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2035 When `USE_COMPILED` is `True`, this argument uses an integer to represent the padding mode.
2036 See also: https://monai.readthedocs.io/en/stable/networks.html#grid-pull (experimental).
2037 When `mode` is an integer, using numpy/cupy backends, this argument accepts
2038 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
2039 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2040 norm_coords: whether to normalize the coordinates from `[-(size-1)/2, (size-1)/2]` to
2041 `[0, size - 1]` (for ``monai/csrc`` implementation) or
2042 `[-1, 1]` (for torch ``grid_sample`` implementation) to be compatible with the underlying
2043 resampling API.
2044 device: device on which the tensor will be allocated.
2045 align_corners: Defaults to False.
2046 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2047 dtype: data type for resampling computation. Defaults to ``float64`` for best precision.
2048 If ``None``, use the data type of input data. To be compatible with other modules,
2049 the output data type is always `float32`.
2050
2051 """
2052 self.mode = mode
2053 self.padding_mode = padding_mode
2054 self.norm_coords = norm_coords
2055 self.device = device
2056 self.align_corners = align_corners
2057 self.dtype = dtype
2058
2059 def __call__(
2060 self,
2061 img: torch.Tensor,
2062 grid: torch.Tensor | None = None,
2063 mode: str | int | None = None,

Callers 7

test_resampleMethod · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_resampleMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…