code: def _compute_mean(
      imgs, target_affine=None, target_shape=None, smooth=False
  ):
      from . import resampling
  
      input_repr = _repr_niimgs(imgs, shorten=True)
  
      imgs = check_niimg(imgs)
      mean_data = safe_get_data(imgs)
      affine = imgs.affine
      # Free memory ASAP
      del imgs
      if mean_data.ndim not in (3, 4):
          raise ValueError(
              "Computation expects 3D or 4D images, "
              f"but {mean_data.ndim} dimensions were given ({input_repr})"
          )
      if mean_data.ndim == 4:
          mean_data = mean_data.mean(axis=-1)
      else:
          mean_data = mean_data.copy()
      mean_data = resampling.resample_img(
          nibabel.Nifti1Image(mean_data, affine),
          target_affine=target_affine,
          target_shape=target_shape,
          copy=False,
      )
      affine = mean_data.affine
      mean_data = get_data(mean_data)
  
      if smooth:
          nan_mask = np.isnan(mean_data)
          mean_data = smooth_array(
              mean_data,
              affine=np.eye(4),
              fwhm=smooth,
              ensure_finite=True,
              copy=False,
          )
          mean_data[nan_mask] = np.nan
  
      return mean_data, 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 9 for calling a global function with example usage: _compute_mean(imgs, target_affine, target_shape, smooth) and returns: mean_data,  affine