code: def _test_simple_2d_images(
      self, interpolation="linear", boundary="replicate"
  ):
      # rotating around the center (8, 8) by 15 degree
      expected = [
          [0.96592583, -0.25881905, 2.34314575],
          [0.25881905, 0.96592583, -1.79795897],
      ]
      expected = np.asarray(expected).flatten()
      test_image, input_shape = get_multiple_2d_images()
      test_target, target_shape = get_multiple_2d_rotated_targets()
  
      identity_affine = [
          [1.0, 0.0, 0.0, 0.0, 1.0, 0.0],
          [1.0, 0.0, 0.0, 0.0, 1.0, 0.0],
          [1.0, 0.0, 0.0, 0.0, 1.0, 0.0],
          [1.0, 0.0, 0.0, 0.0, 1.0, 0.0],
      ]
      affine_var = tf.get_variable(
          "affine", initializer=identity_affine
      )
      grid = AffineGridWarperLayer(
          source_shape=input_shape[1:-1],
          output_shape=target_shape[1:-1],
          constraints=None,
      )
      warp_coords = grid(affine_var)
      resampler = ResamplerLayer(interpolation, boundary=boundary)
      new_image = resampler(
          tf.constant(test_image, dtype=tf.float32), warp_coords
      )
  
      diff = tf.reduce_mean(
          tf.squared_difference(
              new_image, tf.constant(test_target, dtype=tf.float32)
          )
      )
      learning_rate = 0.05
      if (interpolation == "linear") and (boundary == "zero"):
          learning_rate = 0.0003
      optimiser = tf.train.AdagradOptimizer(learning_rate)
      grads = optimiser.compute_gradients(diff)
      opt = optimiser.apply_gradients(grads)
      with self.cached_session() as sess:
          sess.run(tf.global_variables_initializer())
          init_val, affine_val = sess.run([diff, affine_var])
          # compute the MAE between the initial estimated parameters and the expected parameters
          init_var_diff = np.sum(np.abs(affine_val[0] - expected))
          for it in range(500):
              _, diff_val, affine_val = sess.run(
                  [opt, diff, affine_var]
              )
              # print('{} diff: {}, {}'.format(it, diff_val, affine_val[0]))
          # import matplotlib.pyplot as plt
          # plt.figure()
          # plt.imshow(test_target[0])
          # plt.draw()
  
          # plt.figure()
          # plt.imshow(sess.run(new_image).astype(np.uint8)[0])
          # plt.draw()
  
          # plt.show()
          self.assertGreater(init_val, diff_val)
          # compute the MAE between the final estimated parameters and the expected parameters
          var_diff = np.sum(np.abs(affine_val[0] - expected))
          self.assertGreater(init_var_diff, var_diff)
          print(
              "{} {} -- diff {}".format(
                  interpolation, boundary, var_diff
              )
          )
          print("{}".format(affine_val[0]))
  
imports: from __future__ import absolute_import, print_function, division
  import base64
  import numpy
  import tensorflow
  from niftynet.layer.grid_warper import AffineGridWarperLayer
  from niftynet.layer.resampler import ResamplerLayer
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 1 for calling the image_2D_test_converge obj's underlying member method code with example usage: obj._test_simple_2d_images(interpolation, boundary) without return types