code: def iter_check_niimg(
      niimgs,
      ensure_ndim=None,
      atleast_4d=False,
      target_fov=None,
      dtype=None,
      memory=Memory(location=None),
      memory_level=0,
      verbose=0,
  ):
      """Iterate over a list of niimgs and do sanity checks and resampling.
  
      Parameters
      ----------
      niimgs : list of niimg or glob pattern
          Image to iterate over.
  
      ensure_ndim : integer, optional
          If specified, an error is raised if the data does not have the
          required dimension.
  
      atleast_4d : boolean, default=False
          If True, any 3D image is converted to a 4D single scan.
  
      target_fov : tuple of affine and shape, optional
         If specified, images are resampled to this field of view.
  
      dtype : {dtype, "auto"}, optional
          Data type toward which the data should be converted. If "auto", the
          data will be converted to int32 if dtype is discrete and float32 if it
          is continuous.
  
      memory : instance of joblib.Memory or string, default=Memory(location=None)
          Used to cache the masking process.
          By default, no caching is done. If a string is given, it is the
          path to the caching directory.
  
      memory_level : integer, default=0
          Rough estimator of the amount of memory used by caching. Higher value
          means more memory for caching.
  
      verbose : integer, default=0
          Indicate the level of verbosity. By default, nothing is printed.
  
      See Also
      --------
          check_niimg, check_niimg_3d, check_niimg_4d
  
      """
      # If niimgs is a string, use glob to expand it to the matching filenames.
      niimgs = resolve_globbing(niimgs)
  
      ref_fov = None
      resample_to_first_img = False
      ndim_minus_one = (
          ensure_ndim - 1 if ensure_ndim is not None else None
      )
      if target_fov is not None and target_fov != "first":
          ref_fov = target_fov
      i = -1
      for i, niimg in enumerate(niimgs):
          try:
              niimg = check_niimg(
                  niimg,
                  ensure_ndim=ndim_minus_one,
                  atleast_4d=atleast_4d,
                  dtype=dtype,
              )
              if i == 0:
                  ndim_minus_one = len(niimg.shape)
                  if ref_fov is None:
                      ref_fov = (niimg.affine, niimg.shape[:3])
                      resample_to_first_img = True
  
              if not _check_fov(niimg, ref_fov[0], ref_fov[1]):
                  if target_fov is not None:
                      from nilearn import (
                          image,
                      )  # we avoid a circular import
  
                      if resample_to_first_img:
                          warnings.warn(
                              "Affine is different across subjects."
                              " Realignement on first subject "
                              "affine forced"
                          )
                      niimg = cache(
                          image.resample_img,
                          memory,
                          func_memory_level=2,
                          memory_level=memory_level,
                      )(
                          niimg,
                          target_affine=ref_fov[0],
                          target_shape=ref_fov[1],
                      )
                  else:
                      raise ValueError(
                          "Field of view of image #%d is different from "
                          "reference FOV.\n"
                          "Reference affine:\n%r\nImage affine:\n%r\n"
                          "Reference shape:\n%r\nImage shape:\n%r\n"
                          % (
                              i,
                              ref_fov[0],
                              niimg.affine,
                              ref_fov[1],
                              niimg.shape,
                          )
                      )
              yield niimg
          except DimensionError as exc:
              # Keep track of the additional dimension in the error
              exc.increment_stack_counter()
              raise
          except TypeError as exc:
              img_name = ""
              if isinstance(niimg, str):
                  img_name = f" ({niimg}) "
  
              exc.args = (
                  f"Error encountered while loading image #{i}{img_name}",
              ) + exc.args
              raise
  
      # Raising an error if input generator is empty.
      if i == -1:
          raise ValueError("Input niimgs list is empty.")
  
file_path: nilearn/nilearn/_utils/niimg_conversions.py
imports: import glob
  import itertools
  import os.path
  import warnings
  import numpy
  from joblib import Memory
  import nilearn
  from .cache_mixin import cache
  from .exceptions import DimensionError
  from .helpers import stringify_path
  from .niimg import _get_data, load_niimg, safe_get_data
  from .path_finding import resolve_globbing
label_desc: Use image node_id 4 for calling a global function with example usage: iter_check_niimg(niimgs, ensure_ndim, atleast_4d, target_fov, dtype, memory, memory_level, verbose) without return types