code: def test_bspline(self):
      loss_fn = GlobalMutualInformationLoss(
          kernel_type="b-spline", num_bins=32, sigma_ratio=0.015
      )
  
      transform_params_dict = {
          "xyz_translation": [(i, i, i) for i in range(10)],
          "xyz_rotation": [
              (np.pi / 100 * i, np.pi / 100 * i, np.pi / 100 * i)
              for i in range(10)
          ],
      }
  
      def transformation(
          translate_params=(0.0, 0.0, 0.0),
          rotate_params=(0.0, 0.0, 0.0),
      ):
          """
          Read and transform Prostate_T2W_AX_1.nii
          Args:
              translate_params: a tuple of 3 floats, translation is in pixel/voxel relative to the center of the input
                      image. Defaults to no translation.
              rotate_params: a rotation angle in radians, a tuple of 3 floats for 3D.
                      Defaults to no rotation.
          Returns:
              numpy array of shape HWD
          """
          transform_list = [
              transforms.LoadImaged(keys="img", image_only=True),
              transforms.Affined(
                  keys="img",
                  translate_params=translate_params,
                  rotate_params=rotate_params,
                  device=None,
                  padding_mode="border",
              ),
              transforms.NormalizeIntensityd(keys=["img"]),
          ]
          transformation = transforms.Compose(transform_list)
          return transformation({"img": FILE_PATH})["img"]
  
      a1 = transformation()
      a1 = a1.clone().unsqueeze(0).unsqueeze(0).to(device)
  
      for mode in transform_params_dict:
          transform_params_list = transform_params_dict[mode]
          expected_value_list = EXPECTED_VALUE[mode]
          for transform_params, expected_value in zip(
              transform_params_list, expected_value_list
          ):
              a2 = transformation(
                  translate_params=transform_params
                  if "translation" in mode
                  else (0.0, 0.0, 0.0),
                  rotate_params=transform_params
                  if "rotation" in mode
                  else (0.0, 0.0, 0.0),
              )
              a2 = a2.clone().unsqueeze(0).unsqueeze(0).to(device)
              result = loss_fn(a2, a1).detach().cpu().numpy()
              np.testing.assert_allclose(
                  result, expected_value, rtol=0.08, atol=0.05
              )
  
file_path: MONAI/tests/test_global_mutual_information_loss.py
imports: from __future__ import annotations
  import os
  import unittest
  import numpy
  import torch
  from monai import transforms
  from monai.losses.image_dissimilarity import GlobalMutualInformationLoss
  from tests.utils import SkipIfBeforePyTorchVersion, download_url_or_skip_test, skip_if_quick, testing_data_config
label_desc: Use image node_id 2 for calling the TestGlobalMutualInformationLoss obj's underlying member method code with example usage: obj.test_bspline() and returns: transformation