code: def reg_img_stack(images, coords, target_coords):
      """Registration for stacked images
  
      Args:
          images (list): Input data, where each sample in shape (n_phases, dim1, dim2).
          coords (array-like): Coordinates for registration, shape (n_samples, n_landmarks * 2).
          target_coords (array-like): Target coordinates for registration.
  
      Returns:
          list: Registered images, each sample in the list in shape (n_phases, dim1, dim2).
          array-like: Maximum distance of transformed source coordinates to destination coordinates, shape (n_samples,)
      """
      n_samples = len(images)
      if n_samples != coords.shape[0]:
          error_msg = "The sample size of images and coordinates does not match."
          logging.error(error_msg)
          raise ValueError(error_msg)
      n_landmarks = int(coords.shape[1] / 2)
  
      target_coords = target_coords.reshape((n_landmarks, 2))
      max_dist = np.zeros(n_samples)
      for i in range(n_samples):
          src_coord = coords[i, :]
          src_coord = src_coord.reshape((n_landmarks, 2))
          idx_valid = np.isnan(src_coord[:, 0])
          tform = estimate_transform(
              ttype="similarity",
              src=src_coord[~idx_valid, :],
              dst=target_coords[~idx_valid, :],
          )
          # forward transform used here, inverse transform used for warp
          src_tform = tform(src_coord[~idx_valid, :])
          dists = np.linalg.norm(
              src_tform - target_coords[~idx_valid, :], axis=1
          )
          max_dist[i] = np.max(dists)
          n_phases = images[i].shape[0]
          for j in range(n_phases):
              src_img = images[i][j, ...].copy()
              warped = warp(
                  src_img,
                  inverse_map=tform.inverse,
                  preserve_range=True,
              )
              images[i][j, ...] = warped
  
      return images, max_dist
  
file_path: pykale/kale/prepdata/image_transform.py
imports: import logging
  import numpy
  import torchvision.transforms
  from skimage.transform import estimate_transform, rescale, warp
label_desc: Use image node_id 2 for calling a global function with example usage: reg_img_stack(images, coords, target_coords) and returns: images,  max_dist