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

Class AffineGrid

monai/transforms/spatial/array.py:1704–1827  ·  view source on GitHub ↗

Affine transforms on the coordinates. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information. Args: rotate_params: a rotation angle in radians, a scalar for 2D image, a tuple of 3 floats for 3D. D

Source from the content-addressed store, hash-verified

1702
1703
1704class AffineGrid(LazyTransform):
1705 """
1706 Affine transforms on the coordinates.
1707
1708 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
1709 for more information.
1710
1711 Args:
1712 rotate_params: a rotation angle in radians, a scalar for 2D image, a tuple of 3 floats for 3D.
1713 Defaults to no rotation.
1714 shear_params: shearing factors for affine matrix, take a 3D affine as example::
1715
1716 [
1717 [1.0, params[0], params[1], 0.0],
1718 [params[2], 1.0, params[3], 0.0],
1719 [params[4], params[5], 1.0, 0.0],
1720 [0.0, 0.0, 0.0, 1.0],
1721 ]
1722
1723 a tuple of 2 floats for 2D, a tuple of 6 floats for 3D. Defaults to no shearing.
1724 translate_params: a tuple of 2 floats for 2D, a tuple of 3 floats for 3D. Translation is in
1725 pixel/voxel relative to the center of the input image. Defaults to no translation.
1726 scale_params: scale factor for every spatial dims. a tuple of 2 floats for 2D,
1727 a tuple of 3 floats for 3D. Defaults to `1.0`.
1728 dtype: data type for the grid computation. Defaults to ``float32``.
1729 If ``None``, use the data type of input data (if `grid` is provided).
1730 device: device on which the tensor will be allocated, if a new grid is generated.
1731 align_corners: Defaults to False.
1732 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
1733 affine: If applied, ignore the params (`rotate_params`, etc.) and use the
1734 supplied matrix. Should be square with each side = num of image spatial
1735 dimensions + 1.
1736 lazy: a flag to indicate whether this transform should execute lazily or not.
1737 Defaults to False
1738 """
1739
1740 backend = [TransformBackends.TORCH]
1741
1742 def __init__(
1743 self,
1744 rotate_params: Sequence[float] | float | None = None,
1745 shear_params: Sequence[float] | float | None = None,
1746 translate_params: Sequence[float] | float | None = None,
1747 scale_params: Sequence[float] | float | None = None,
1748 device: torch.device | None = None,
1749 dtype: DtypeLike = np.float32,
1750 align_corners: bool = False,
1751 affine: NdarrayOrTensor | None = None,
1752 lazy: bool = False,
1753 ) -> None:
1754 LazyTransform.__init__(self, lazy=lazy)
1755 self.rotate_params = rotate_params
1756 self.shear_params = shear_params
1757 self.translate_params = translate_params
1758 self.scale_params = scale_params
1759 self.device = device
1760 _dtype = get_equivalent_dtype(dtype, torch.Tensor)
1761 self.dtype = _dtype if _dtype in (torch.float16, torch.float64, None) else torch.float32

Callers 5

test_affine_gridMethod · 0.90
__call__Method · 0.85
__init__Method · 0.85
inverseMethod · 0.85
inverseMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_affine_gridMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…