code: def th_affine2d(x, matrix, mode="bilinear", center=True):
      """
      2D Affine image transform on th.Tensor
  
      Arguments
      ---------
      x : th.Tensor of size (C, H, W)
          image tensor to be transformed
  
      matrix : th.Tensor of size (3, 3) or (2, 3)
          transformation matrix
  
      mode : string in {'nearest', 'bilinear'}
          interpolation scheme to use
  
      center : boolean
          whether to alter the bias of the transform
          so the transform is applied about the center
          of the image rather than the origin
  
      Example
      -------
      >>> import torch
      >>> from pywick.utils import *
      >>> x = th.zeros(2,1000,1000)
      >>> x[:,100:1500,100:500] = 10
      >>> matrix = th.FloatTensor([[1.,0,-50],
      ...                             [0,1.,-50]])
      >>> xn = th_affine2d(x, matrix, mode='nearest')
      >>> xb = th_affine2d(x, matrix, mode='bilinear')
      """
  
      if matrix.dim() == 2:
          matrix = matrix[:2, :]
          matrix = matrix.unsqueeze(0)
      elif matrix.dim() == 3:
          if matrix.size()[1:] == (3, 3):
              matrix = matrix[:, :2, :]
  
      A_batch = matrix[:, :, :2]
      if A_batch.size(0) != x.size(0):
          A_batch = A_batch.repeat(x.size(0), 1, 1)
      b_batch = matrix[:, :, 2].unsqueeze(1)
  
      # make a meshgrid of normal coordinates
      _coords = th_iterproduct(x.size(1), x.size(2))
      coords = _coords.unsqueeze(0).repeat(x.size(0), 1, 1).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)
      # apply the coordinate transformation
      new_coords = coords.bmm(
          A_batch.transpose(1, 2)
      ) + b_batch.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
          )
  
      # map new coordinates using bilinear interpolation
      if mode == "nearest":
          x_transformed = th_nearest_interp2d(
              x.contiguous(), new_coords
          )
      elif mode == "bilinear":
          x_transformed = th_bilinear_interp2d(
              x.contiguous(), 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 12 for calling a global function with example usage: th_affine2d(x, matrix, mode, center) and returns: x_transformed