code: def test_affreg_defaults(rng):
      # Test all default arguments with an arbitrary transform
      # Select an arbitrary transform (all of them are already tested
      # in test_affreg_all_transforms)
      transform_name = "TRANSLATION"
      dim = 2
      ttype = (transform_name, dim)
      aff_options = [
          "mass",
          "voxel-origin",
          "centers",
          None,
          np.eye(dim + 1),
      ]
  
      for starting_affine in aff_options:
          if dim == 2:
              nslices = 1
          else:
              nslices = 45
          factor = factors[ttype][0]
          transform = regtransforms[ttype]
          (
              static,
              moving,
              static_grid2world,
              moving_grid2world,
              smask,
              mmask,
              T,
          ) = setup_random_transform(
              transform, factor, nslices, 1.0, rng=rng
          )
          # Sum of absolute differences
          start_sad = np.abs(static - moving).sum()
  
          metric = None
          x0 = None
          sigmas = None
          scale_factors = None
          level_iters = None
          static_grid2world = None
          moving_grid2world = None
          smask = None
          mmask = None
          for ss_sigma_factor in [1.0, None]:
              affreg = imaffine.AffineRegistration(
                  metric,
                  level_iters,
                  sigmas,
                  scale_factors,
                  "L-BFGS-B",
                  ss_sigma_factor,
                  options=None,
              )
              affine_map = affreg.optimize(
                  static,
                  moving,
                  transform,
                  x0,
                  static_grid2world,
                  moving_grid2world,
                  starting_affine,
                  None,
                  smask,
                  mmask,
              )
              transformed = affine_map.transform(moving)
              # Sum of absolute differences
              end_sad = np.abs(static - transformed).sum()
              reduction = 1 - end_sad / start_sad
              print("%s>>%f" % (ttype, reduction))
              assert reduction > 0.9
  
              transformed_inv = affine_map.transform_inverse(static)
              # Sum of absolute differences
              end_sad = np.abs(moving - transformed_inv).sum()
              reduction = 1 - end_sad / start_sad
              print("%s>>%f" % (ttype, reduction))
              assert reduction > 0.89
  
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 5 for calling a global function with example usage: test_affreg_defaults(rng) without return types