Transform ``img`` given the affine parameters. A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information.
| 2177 | |
| 2178 | |
| 2179 | class Affine(InvertibleTransform, LazyTransform): |
| 2180 | """ |
| 2181 | Transform ``img`` given the affine parameters. |
| 2182 | A tutorial is available: https://github.com/Project-MONAI/tutorials/blob/0.6.0/modules/transforms_demo_2d.ipynb. |
| 2183 | |
| 2184 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 2185 | for more information. |
| 2186 | """ |
| 2187 | |
| 2188 | backend = list(set(AffineGrid.backend) & set(Resample.backend)) |
| 2189 | |
| 2190 | def __init__( |
| 2191 | self, |
| 2192 | rotate_params: Sequence[float] | float | None = None, |
| 2193 | shear_params: Sequence[float] | float | None = None, |
| 2194 | translate_params: Sequence[float] | float | None = None, |
| 2195 | scale_params: Sequence[float] | float | None = None, |
| 2196 | affine: NdarrayOrTensor | None = None, |
| 2197 | spatial_size: Sequence[int] | int | None = None, |
| 2198 | mode: str | int = GridSampleMode.BILINEAR, |
| 2199 | padding_mode: str = GridSamplePadMode.REFLECTION, |
| 2200 | normalized: bool = False, |
| 2201 | device: torch.device | None = None, |
| 2202 | dtype: DtypeLike = np.float32, |
| 2203 | align_corners: bool = False, |
| 2204 | image_only: bool = False, |
| 2205 | lazy: bool = False, |
| 2206 | ) -> None: |
| 2207 | """ |
| 2208 | The affine transformations are applied in rotate, shear, translate, scale order. |
| 2209 | |
| 2210 | Args: |
| 2211 | rotate_params: a rotation angle in radians, a scalar for 2D image, a tuple of 3 floats for 3D. |
| 2212 | Defaults to no rotation. |
| 2213 | shear_params: shearing factors for affine matrix, take a 3D affine as example:: |
| 2214 | |
| 2215 | [ |
| 2216 | [1.0, params[0], params[1], 0.0], |
| 2217 | [params[2], 1.0, params[3], 0.0], |
| 2218 | [params[4], params[5], 1.0, 0.0], |
| 2219 | [0.0, 0.0, 0.0, 1.0], |
| 2220 | ] |
| 2221 | |
| 2222 | a tuple of 2 floats for 2D, a tuple of 6 floats for 3D. Defaults to no shearing. |
| 2223 | translate_params: a tuple of 2 floats for 2D, a tuple of 3 floats for 3D. Translation is in |
| 2224 | pixel/voxel relative to the center of the input image. Defaults to no translation. |
| 2225 | scale_params: scale factor for every spatial dims. a tuple of 2 floats for 2D, |
| 2226 | a tuple of 3 floats for 3D. Defaults to `1.0`. |
| 2227 | affine: If applied, ignore the params (`rotate_params`, etc.) and use the |
| 2228 | supplied matrix. Should be square with each side = num of image spatial |
| 2229 | dimensions + 1. |
| 2230 | spatial_size: output image spatial size. |
| 2231 | if `spatial_size` and `self.spatial_size` are not defined, or smaller than 1, |
| 2232 | the transform will use the spatial size of `img`. |
| 2233 | if some components of the `spatial_size` are non-positive values, the transform will use the |
| 2234 | corresponding components of img size. For example, `spatial_size=(32, -1)` will be adapted |
| 2235 | to `(32, 64)` if the second spatial dimension size of img is `64`. |
| 2236 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
no outgoing calls
no test coverage detected
searching dependent graphs…