docstr: Apply affine transformations with a batch of affine matrices.
  
  When `normalized=False` and `reverse_indexing=True`,
  it does the commonly used resampling in the 'pull' direction
  following the ``scipy.ndimage.affine_transform`` convention.
  In this case `theta` is equivalent to (ndim+1, ndim+1) input ``matrix`` of ``scipy.ndimage.affine_transform``,
  operates on homogeneous coordinates.
  See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html
  
  When `normalized=True` and `reverse_indexing=False`,
  it applies `theta` to the normalized coordinates (coords. in the range of [-1, 1]) directly.
  This is often used with `align_corners=False` to achieve resolution-agnostic resampling,
  thus useful as a part of trainable modules such as the spatial transformer networks.
  See also: https://pytorch.org/tutorials/intermediate/spatial_transformer_tutorial.html
  
  Args:
      spatial_size: output spatial shape, the full output shape will be
          `[N, C, *spatial_size]` where N and C are inferred from the `src` input of `self.forward`.
      normalized: indicating whether the provided affine matrix `theta` is defined
          for the normalized coordinates. If `normalized=False`, `theta` will be converted
          to operate on normalized coordinates as pytorch affine_grid works with the normalized
          coordinates.
      mode: {``"bilinear"``, ``"nearest"``}
          Interpolation mode to calculate output values. Defaults to ``"bilinear"``.
          See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
      padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
          Padding mode for outside grid values. Defaults to ``"zeros"``.
          See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
      align_corners: see also https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html.
      reverse_indexing: whether to reverse the spatial indexing of image and coordinates.
          set to `False` if `theta` follows pytorch's default "D, H, W" convention.
          set to `True` if `theta` follows `scipy.ndimage` default "i, j, k" convention.
      zero_centered: whether the affine is applied to coordinates in a zero-centered value range.
          With `zero_centered=True`, for example, the center of rotation will be the
          spatial center of the input; with `zero_centered=False`, the center of rotation will be the
          origin of the input. This option is only available when `normalized=False`,
          where the default behaviour is `False` if unspecified.
          See also: :py:func:`monai.networks.utils.normalize_transform`.
docstr_tok: ["Apply","affine","transformations","with","a","batch","of","affine","matrices",".","When","`","normalized=False","`","and","`","reverse_indexing=True","`",",","it","does","the","commonly","used","resampling","in","the","'pull","'","direction","following","the","``","scipy.ndimage.affine_transform","``","convention",".","In","this","case","`","theta","`","is","equivalent","to","(","ndim+1",",","ndim+1",")","input","``","matrix","``","of","``","scipy.ndimage.affine_transform","``",",","operates","on","homogeneous","coordinates",".","See","also",":","https",":","\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.ndimage.affine_transform.html","When","`","normalized=True","`","and","`","reverse_indexing=False","`",",","it","applies","`","theta","`","to","the","normalized","coordinates","(","coords",".","in","the","range","of","[","-1",",","1","]",")","directly",".","This","is","often","used","with","`","align_corners=False","`","to","achieve","resolution-agnostic","resampling",",","thus","useful","as","a","part","of","trainable","modules","such","as","the","spatial","transformer","networks",".","See","also",":","https",":","\/\/pytorch.org\/tutorials\/intermediate\/spatial_transformer_tutorial.html","Args",":","spatial_size",":","output","spatial","shape",",","the","full","output","shape","will","be","`","[","N",",","C",",","*","spatial_size","]","`","where","N","and","C","are","inferred","from","the","`","src","`","input","of","`","self.forward","`",".","normalized",":","indicating","whether","the","provided","affine","matrix","`","theta","`","is","defined","for","the","normalized","coordinates",".","If","`","normalized=False","`",",","`","theta","`","will","be","converted","to","operate","on","normalized","coordinates","as","pytorch","affine_grid","works","with","the","normalized","coordinates",".","mode",":","{","``","``","bilinear","''","``",",","``","``","nearest","''","``","}","Interpolation","mode","to","calculate","output","values",".","Defaults","to","``","``","bilinear","''","``",".","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.functional.grid_sample.html","padding_mode",":","{","``","``","zeros","''","``",",","``","``","border","''","``",",","``","``","reflection","''","``","}","Padding","mode","for","outside","grid","values",".","Defaults","to","``","``","zeros","''","``",".","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.functional.grid_sample.html","align_corners",":","see","also","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.functional.grid_sample.html",".","reverse_indexing",":","whether","to","reverse","the","spatial","indexing","of","image","and","coordinates",".","set","to","`","False","`","if","`","theta","`","follows","pytorch","'s","default","``","D",",","H",",","W","''","convention",".","set","to","`","True","`","if","`","theta","`","follows","`","scipy.ndimage","`","default","``","i",",","j",",","k","''","convention",".","zero_centered",":","whether","the","affine","is","applied","to","coordinates","in","a","zero-centered","value","range",".","With","`","zero_centered=True","`",",","for","example",",","the","center","of","rotation","will","be","the","spatial","center","of","the","input",";","with","`","zero_centered=False","`",",","the","center","of","rotation","will","be","the","origin","of","the","input",".","This","option","is","only","available","when","`","normalized=False","`",",","where","the","default","behaviour","is","`","False","`","if","unspecified",".","See","also",":",":","py",":","func",":","`","monai.networks.utils.normalize_transform","`","."]
code: def __init__(
      self,
      spatial_size: Sequence[int] | int | None = None,
      normalized: bool = False,
      mode: str = GridSampleMode.BILINEAR,
      padding_mode: str = GridSamplePadMode.ZEROS,
      align_corners: bool = True,
      reverse_indexing: bool = True,
      zero_centered: bool | None = None,
  ) -> None:
      """
      Apply affine transformations with a batch of affine matrices.
  
      When `normalized=False` and `reverse_indexing=True`,
      it does the commonly used resampling in the 'pull' direction
      following the ``scipy.ndimage.affine_transform`` convention.
      In this case `theta` is equivalent to (ndim+1, ndim+1) input ``matrix`` of ``scipy.ndimage.affine_transform``,
      operates on homogeneous coordinates.
      See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html
  
      When `normalized=True` and `reverse_indexing=False`,
      it applies `theta` to the normalized coordinates (coords. in the range of [-1, 1]) directly.
      This is often used with `align_corners=False` to achieve resolution-agnostic resampling,
      thus useful as a part of trainable modules such as the spatial transformer networks.
      See also: https://pytorch.org/tutorials/intermediate/spatial_transformer_tutorial.html
  
      Args:
          spatial_size: output spatial shape, the full output shape will be
              `[N, C, *spatial_size]` where N and C are inferred from the `src` input of `self.forward`.
          normalized: indicating whether the provided affine matrix `theta` is defined
              for the normalized coordinates. If `normalized=False`, `theta` will be converted
              to operate on normalized coordinates as pytorch affine_grid works with the normalized
              coordinates.
          mode: {``"bilinear"``, ``"nearest"``}
              Interpolation mode to calculate output values. Defaults to ``"bilinear"``.
              See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
          padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
              Padding mode for outside grid values. Defaults to ``"zeros"``.
              See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
          align_corners: see also https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html.
          reverse_indexing: whether to reverse the spatial indexing of image and coordinates.
              set to `False` if `theta` follows pytorch's default "D, H, W" convention.
              set to `True` if `theta` follows `scipy.ndimage` default "i, j, k" convention.
          zero_centered: whether the affine is applied to coordinates in a zero-centered value range.
              With `zero_centered=True`, for example, the center of rotation will be the
              spatial center of the input; with `zero_centered=False`, the center of rotation will be the
              origin of the input. This option is only available when `normalized=False`,
              where the default behaviour is `False` if unspecified.
              See also: :py:func:`monai.networks.utils.normalize_transform`.
      """
      super().__init__()
      self.spatial_size = (
          ensure_tuple(spatial_size)
          if spatial_size is not None
          else None
      )
      self.normalized = normalized
      self.mode: str = look_up_option(mode, GridSampleMode)
      self.padding_mode: str = look_up_option(
          padding_mode, GridSamplePadMode
      )
      self.align_corners = align_corners
      self.reverse_indexing = reverse_indexing
      if zero_centered is not None and self.normalized:
          raise ValueError(
              "`normalized=True` is not compatible with the `zero_centered` option."
          )
      self.zero_centered = (
          zero_centered if zero_centered is not None else False
      )
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  import torch
  import torch.nn
  import monai
  from monai.networks import to_norm_affine
  from monai.utils import GridSampleMode, GridSamplePadMode, convert_to_dst_type, ensure_tuple, look_up_option, optional_import
label_desc: Use image node_id 1 to create a new AffineTransform object from inherited base classes: nn with example: obj = AffineTransform(spatial_size, normalized, mode, padding_mode, align_corners, reverse_indexing, zero_centered)