code: def monai_to_itk_affine(
      image, affine_matrix, center_of_rotation=None
  ):
      """
      Converts a MONAI affine matrix to an ITK affine matrix (2x2 for 2D or 3x3 for
      3D matrix and translation vector). See also 'itk_to_monai_affine'.
  
      Args:
          image: The ITK image object. This is used to extract the spacing and direction information.
          affine_matrix: The 3x3 for 2D or 4x4 for 3D MONAI affine matrix.
          center_of_rotation: The center of rotation. If provided, the affine
                              matrix will be adjusted to account for the difference
                              between the center of the image and the center of rotation.
  
      Returns:
          The ITK matrix and the translation vector.
      """
      _assert_itk_regions_match_array(image)
  
      # Adjust spacing
      spacing_matrix, inverse_spacing_matrix = _compute_spacing_matrix(
          image
      )
      affine_matrix = (
          spacing_matrix @ affine_matrix @ inverse_spacing_matrix
      )
  
      # Adjust direction
      (
          direction_matrix,
          inverse_direction_matrix,
      ) = _compute_direction_matrix(image)
      affine_matrix = (
          direction_matrix @ affine_matrix @ inverse_direction_matrix
      )
  
      # Adjust offset when center of rotation is different from center of the image
      if center_of_rotation:
          offset_matrix, inverse_offset_matrix = _compute_offset_matrix(
              image, center_of_rotation
          )
          affine_matrix = (
              offset_matrix @ affine_matrix @ inverse_offset_matrix
          )
  
      ndim = image.ndim
      matrix = affine_matrix[:ndim, :ndim].numpy()
      translation = affine_matrix[:ndim, ndim].tolist()
  
      return matrix, translation
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, cast
  import numpy
  import torch
  from monai.config.type_definitions import DtypeLike
  from monai.data import ITKReader, ITKWriter
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import orientation_ras_lps
  from monai.transforms import EnsureChannelFirst
  from monai.utils import MetaKeys, SpaceKeys, convert_to_dst_type, optional_import
label_desc: Use image node_id 4 for calling a global function with example usage: monai_to_itk_affine(image, affine_matrix, center_of_rotation) and returns: matrix,  translation