code: def test_transform_centers_of_mass_3d():
      shape = (64, 64, 64)
      rm = 8
      sph = vf.create_sphere(
          shape[0] // 2, shape[1] // 2, shape[2] // 2, rm
      )
      moving = np.zeros(shape)
      # The center of mass will be (16, 16, 16), in image coordinates
      moving[: shape[0] // 2, : shape[1] // 2, : shape[2] // 2] = sph[
          ...
      ]
  
      rs = 16
      # The center of mass will be (32, 32, 32), in image coordinates
      static = vf.create_sphere(shape[0], shape[1], shape[2], rs)
  
      # Create arbitrary image-to-space transforms
      axis = np.array([0.5, 2.0, 1.5])
      t = 0.15  # translation factor
      trans = np.array(
          [
              [1, 0, 0, -t * shape[0]],
              [0, 1, 0, -t * shape[1]],
              [0, 0, 1, -t * shape[2]],
              [0, 0, 0, 1],
          ]
      )
      trans_inv = npl.inv(trans)
  
      for rotation_angle in [-1 * np.pi / 6.0, 0.0, np.pi / 5.0]:
          for scale_factor in [0.83, 1.3, 2.07]:  # scale
              rot = np.zeros(shape=(4, 4))
              rot[:3, :3] = geometry.rodrigues_axis_rotation(
                  axis, rotation_angle
              )
              rot[3, 3] = 1.0
              scale = np.array(
                  [
                      [1 * scale_factor, 0, 0, 0],
                      [0, 1 * scale_factor, 0, 0],
                      [0, 0, 1 * scale_factor, 0],
                      [0, 0, 0, 1],
                  ]
              )
  
              static_grid2world = trans_inv.dot(
                  scale.dot(rot.dot(trans))
              )
              moving_grid2world = npl.inv(static_grid2world)
  
              # Expected translation
              c_static = static_grid2world.dot((32, 32, 32, 1))[:3]
              c_moving = moving_grid2world.dot((16, 16, 16, 1))[:3]
              expected = np.eye(4)
              expected[:3, 3] = c_moving - c_static
  
              # Implementation under test
              actual = imaffine.transform_centers_of_mass(
                  static, static_grid2world, moving, moving_grid2world
              )
              assert_array_almost_equal(actual.affine, expected)
  
file_path: dipy/dipy/align/tests/test_imaffine.py
imports: import numpy
  import numpy.linalg
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises, assert_warns
  from dipy.core import geometry
  from dipy.align import vector_fields
  from dipy.align import imaffine
  from dipy.align.imaffine import AffineInversionError, AffineInvalidValuesError, AffineMap, _number_dim_affine_matrix
  from dipy.align.transforms import regtransforms
  from dipy.align.tests.test_parzenhist import setup_random_transform
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 1 for calling a global function with example usage: test_transform_centers_of_mass_3d() without return types