Resample input image from the orientation/spacing defined by ``src_affine`` affine matrix into the ones specified by ``dst_affine`` affine matrix. Internally this transform computes the affine transform matrix from ``src_affine`` to ``dst_affine``, by ``xform = linalg.solve(src_aff
| 123 | |
| 124 | |
| 125 | class SpatialResample(InvertibleTransform, LazyTransform): |
| 126 | """ |
| 127 | Resample input image from the orientation/spacing defined by ``src_affine`` affine matrix into |
| 128 | the ones specified by ``dst_affine`` affine matrix. |
| 129 | |
| 130 | Internally this transform computes the affine transform matrix from ``src_affine`` to ``dst_affine``, |
| 131 | by ``xform = linalg.solve(src_affine, dst_affine)``, and call ``monai.transforms.Affine`` with ``xform``. |
| 132 | |
| 133 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 134 | for more information. |
| 135 | """ |
| 136 | |
| 137 | backend = [TransformBackends.TORCH, TransformBackends.NUMPY, TransformBackends.CUPY] |
| 138 | |
| 139 | def __init__( |
| 140 | self, |
| 141 | mode: str | int = GridSampleMode.BILINEAR, |
| 142 | padding_mode: str = GridSamplePadMode.BORDER, |
| 143 | align_corners: bool = False, |
| 144 | dtype: DtypeLike = np.float64, |
| 145 | lazy: bool = False, |
| 146 | ): |
| 147 | """ |
| 148 | Args: |
| 149 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
| 150 | Interpolation mode to calculate output values. Defaults to ``"bilinear"``. |
| 151 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 152 | When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used |
| 153 | and the value represents the order of the spline interpolation. |
| 154 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 155 | padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} |
| 156 | Padding mode for outside grid values. Defaults to ``"border"``. |
| 157 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 158 | When `mode` is an integer, using numpy/cupy backends, this argument accepts |
| 159 | {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}. |
| 160 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 161 | dtype: data type for resampling computation. Defaults to ``float64`` for best precision. |
| 162 | If ``None``, use the data type of input data. To be compatible with other modules, |
| 163 | the output data type is always ``float32``. |
| 164 | lazy: a flag to indicate whether this transform should execute lazily or not. |
| 165 | Defaults to False |
| 166 | """ |
| 167 | LazyTransform.__init__(self, lazy=lazy) |
| 168 | self.mode = mode |
| 169 | self.padding_mode = padding_mode |
| 170 | self.align_corners = align_corners |
| 171 | self.dtype = dtype |
| 172 | |
| 173 | def __call__( |
| 174 | self, |
| 175 | img: torch.Tensor, |
| 176 | dst_affine: torch.Tensor | None = None, |
| 177 | spatial_size: Sequence[int] | torch.Tensor | int | None = None, |
| 178 | mode: str | int | None = None, |
| 179 | padding_mode: str | None = None, |
| 180 | align_corners: bool | None = None, |
| 181 | dtype: DtypeLike = None, |
| 182 | lazy: bool | None = None, |
no outgoing calls
searching dependent graphs…