code: def resample4d(im4d, transforms, time_interp=True):
      """
      Resample a 4D image according to the specified sequence of spatial
      transforms, using either 4D interpolation if `time_interp` is True
      and 3D interpolation otherwise.
      """
      r = Realign4dAlgorithm(
          im4d, transforms=transforms, time_interp=time_interp
      )
      res = r.resample_full_data()
      im4d.free_data()
      return res
  
imports: import os
  import warnings
  import numpy
  from nibabel import io_orientation
  from nibabel.affines import apply_affine
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ...io.nibcompat import get_header
  from ..slicetiming import timefuncs
  from ._registration import _cspline_sample3d, _cspline_sample4d, _cspline_transform
  from .affine import Affine, Rigid
  from .optimizer import configure_optimizer, use_derivatives
  from .type_check import check_type, check_type_and_shape
label_desc: Use image node_id 6 for calling a global function with example usage: resample4d(im4d, transforms, time_interp) and returns: res