@@ -2166,6 +2166,13 @@ class Affine(InvertibleTransform, LazyTransform):
21662166
21672167 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
21682168 for more information.
2169+
2170+ Note:
2171+ This transform assumes that the origin of the coordinate system is at the spatial center
2172+ of the image. When applying transformations (rotation, scaling, etc.), they are performed
2173+ relative to this center point. If you need transformations around a different origin,
2174+ you may need to compose this transform with translation operations or adjust your affine
2175+ matrix accordingly.
21692176 """
21702177
21712178 backend = list (set (AffineGrid .backend ) & set (Resample .backend ))
@@ -2228,10 +2235,12 @@ def __init__(
22282235 When `mode` is an integer, using numpy/cupy backends, this argument accepts
22292236 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
22302237 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2231- normalized: indicating whether the provided `affine` is defined to include a normalization
2232- transform converting the coordinates from `[-(size-1)/2, (size-1)/2]` (defined in ``create_grid``) to
2233- `[0, size - 1]` or `[-1, 1]` in order to be compatible with the underlying resampling API.
2234- If `normalized=False`, additional coordinate normalization will be applied before resampling.
2238+ normalized: indicates whether the provided `affine` matrix already includes coordinate
2239+ normalization. Set to ``True`` if your affine matrix is designed to work with normalized
2240+ coordinates (e.g., from image processing libraries that use normalized coordinate systems).
2241+ Set to ``False`` (default) if your affine matrix works with pixel/voxel coordinates centered
2242+ at the image center. When ``False``, MONAI will automatically apply the necessary coordinate
2243+ transformations. Most users should use the default ``False``.
22352244 See also: :py:func:`monai.networks.utils.normalize_transform`.
22362245 device: device on which the tensor will be allocated.
22372246 dtype: data type for resampling computation. Defaults to ``float32``.
@@ -2323,6 +2332,24 @@ def __call__(
23232332
23242333 @classmethod
23252334 def compute_w_affine (cls , spatial_rank , mat , img_size , sp_size ):
2335+ """
2336+ Compute the affine matrix for transforming image coordinates, accounting for
2337+ center-based coordinate system.
2338+
2339+ This function adjusts the provided affine transformation matrix to work with images
2340+ where transformations are applied relative to the image center rather than the origin.
2341+ It composes the input matrix with translation operations that shift between
2342+ corner-based and center-based coordinate systems.
2343+
2344+ Args:
2345+ spatial_rank: number of spatial dimensions (e.g., 2 for 2D, 3 for 3D).
2346+ mat: the base affine transformation matrix to be adjusted.
2347+ img_size: spatial dimensions of the input image.
2348+ sp_size: spatial dimensions of the output (transformed) image.
2349+
2350+ Returns:
2351+ The adjusted affine matrix that can be applied to image coordinates.
2352+ """
23262353 r = int (spatial_rank )
23272354 mat = to_affine_nd (r , mat )
23282355 shift_1 = create_translate (r , [float (d - 1 ) / 2 for d in img_size [:r ]])
0 commit comments