code: def index_img(imgs, index):
      """Indexes into a 4D Niimg-like object in the fourth dimension.
  
      Common use cases include extracting a 3D image out of `img` or
      creating a 4D image whose data is a subset of `img` data.
  
      Parameters
      ----------
      imgs : 4D Niimg-like object
          See :ref:`extracting_data`.
  
      index : Any type compatible with numpy array indexing
          Used for indexing the 4D data array in the fourth dimension.
  
      Returns
      -------
      :class:`~nibabel.nifti1.Nifti1Image`
          Indexed image.
  
      See Also
      --------
      nilearn.image.concat_imgs
      nilearn.image.iter_img
  
      Examples
      --------
      First we concatenate two MNI152 images to create a 4D-image::
  
       >>> from nilearn import datasets
       >>> from nilearn.image import concat_imgs, index_img
       >>> joint_mni_image = concat_imgs([datasets.load_mni152_template(),
       ...                                datasets.load_mni152_template()])
       >>> print(joint_mni_image.shape)
       (197, 233, 189, 2)
  
      We can now select one slice from the last dimension of this 4D-image::
  
       >>> single_mni_image = index_img(joint_mni_image, 1)
       >>> print(single_mni_image.shape)
       (197, 233, 189)
  
      We can also select multiple frames using the `slice` constructor::
  
       >>> five_mni_images = concat_imgs([datasets.load_mni152_template()] * 5)
       >>> print(five_mni_images.shape)
       (197, 233, 189, 5)
  
       >>> first_three_images = index_img(five_mni_images,
       ...                                slice(0, 3))
       >>> print(first_three_images.shape)
       (197, 233, 189, 3)
  
      """
      imgs = check_niimg_4d(imgs)
      # duck-type for pandas arrays, and select the 'values' attr
      if hasattr(index, "values") and hasattr(index, "iloc"):
          index = index.values.flatten()
      return _index_img(imgs, index)
  
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 12 for calling a global function with example usage: index_img(imgs, index) and returns: _index_img