code: def mean_img(
      imgs, target_affine=None, target_shape=None, verbose=0, n_jobs=1
  ):
      """Compute the mean of the images over time or the 4th dimension.
  
      Note that if list of 4D images are given, the mean of each 4D image is
      computed separately, and the resulting mean is computed after.
  
      Parameters
      ----------
      imgs : Niimg-like object or iterable of Niimg-like objects
          Images to be averaged over time (see :ref:`extracting_data`
          for a detailed description of the valid input types).
  
      target_affine : :class:`numpy.ndarray`, optional
          If specified, the image is resampled corresponding to this new affine.
          target_affine can be a 3x3 or a 4x4 matrix.
  
      target_shape : :obj:`tuple` or :obj:`list`, optional
          If specified, the image will be resized to match this new shape.
          len(target_shape) must be equal to 3.
          A target_affine has to be specified jointly with target_shape.
  
      verbose : :obj:`int`, default=0
          Controls the amount of verbosity: higher numbers give more messages
          (0 means no messages).
  
      n_jobs : :obj:`int`, default=1
          The number of CPUs to use to do the computation (-1 means
          'all CPUs').
  
      Returns
      -------
      :class:`~nibabel.nifti1.Nifti1Image`
          Mean image.
  
      See Also
      --------
      nilearn.image.math_img : For more general operations on images.
  
      """
      imgs = stringify_path(imgs)
      is_str = isinstance(imgs, str)
      is_iterable = isinstance(imgs, collections.abc.Iterable)
      if is_str or not is_iterable:
          imgs = [
              imgs,
          ]
  
      imgs_iter = iter(imgs)
      first_img = check_niimg(next(imgs_iter))
  
      # Compute the first mean to retrieve the reference
      # target_affine and target_shape if_needed
      n_imgs = 1
      running_mean, first_affine = _compute_mean(
          first_img,
          target_affine=target_affine,
          target_shape=target_shape,
      )
  
      if target_affine is None or target_shape is None:
          target_affine = first_affine
          target_shape = running_mean.shape[:3]
  
      for this_mean in Parallel(n_jobs=n_jobs, verbose=verbose)(
          delayed(_compute_mean)(
              n, target_affine=target_affine, target_shape=target_shape
          )
          for n in imgs_iter
      ):
          n_imgs += 1
          # _compute_mean returns (mean_img, affine)
          this_mean = this_mean[0]
          running_mean += this_mean
  
      running_mean = running_mean / float(n_imgs)
      return new_img_like(first_img, running_mean, target_affine)
  
imports: import collections.abc
  import copy
  import itertools
  import warnings
  import nibabel
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy.ndimage import gaussian_filter1d, generate_binary_structure, label
  from scipy.stats import scoreatpercentile
  from ..None import signal
  from .._utils import _repr_niimgs, as_ndarray, check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.exceptions import DimensionError
  from .._utils.helpers import rename_parameters, stringify_path
  from .._utils.niimg import _get_data, safe_get_data
  from .._utils.niimg_conversions import _index_img, check_same_fov, iter_check_niimg
  from .._utils.param_validation import check_threshold
  from .._utils.path_finding import resolve_globbing
label_desc: Use image node_id 10 for calling a global function with example usage: mean_img(imgs, target_affine, target_shape, verbose, n_jobs) and returns: new_img_like