code: def th_affine3d(x, matrix, mode="trilinear", center=True):
      """
      3D Affine image transform on th.Tensor
      """
      A = matrix[:3, :3]
      b = matrix[:3, 3]
  
      # make a meshgrid of normal coordinates
      coords = th_iterproduct(x.size(1), x.size(2), x.size(3)).float()
  
      if center:
          # shift the coordinates so center is the origin
          coords[:, 0] = coords[:, 0] - (x.size(1) / 2.0 - 0.5)
          coords[:, 1] = coords[:, 1] - (x.size(2) / 2.0 - 0.5)
          coords[:, 2] = coords[:, 2] - (x.size(3) / 2.0 - 0.5)
  
      # apply the coordinate transformation
      new_coords = coords.mm(A.t().contiguous()) + b.expand_as(coords)
  
      if center:
          # shift the coordinates back so origin is origin
          new_coords[:, 0] = new_coords[:, 0] + (x.size(1) / 2.0 - 0.5)
          new_coords[:, 1] = new_coords[:, 1] + (x.size(2) / 2.0 - 0.5)
          new_coords[:, 2] = new_coords[:, 2] + (x.size(3) / 2.0 - 0.5)
  
      # map new coordinates using bilinear interpolation
      if mode == "nearest":
          x_transformed = th_nearest_interp3d(x, new_coords)
      elif mode == "trilinear":
          x_transformed = th_trilinear_interp3d(x, new_coords)
      else:
          x_transformed = th_trilinear_interp3d(x, new_coords)
  
      return x_transformed
  
imports: import pickle
  import random
  from .optimizers import *
  from .callbacks import *
  import torch
  from pywick.callbacks import *
label_desc: Use image node_id 15 for calling a global function with example usage: th_affine3d(x, matrix, mode, center) and returns: x_transformed