code: def _plot_img_with_bg(
      img,
      bg_img=None,
      cut_coords=None,
      output_file=None,
      display_mode="ortho",
      colorbar=False,
      figure=None,
      axes=None,
      title=None,
      threshold=None,
      annotate=True,
      draw_cross=True,
      black_bg=False,
      vmin=None,
      vmax=None,
      bg_vmin=None,
      bg_vmax=None,
      interpolation="nearest",
      display_factory=get_slicer,
      cbar_vmin=None,
      cbar_vmax=None,
      cbar_tick_format="%.2g",
      brain_color=(0.5, 0.5, 0.5),
      decimals=False,
      radiological=False,
      **kwargs,
  ):
      """Refer to the docstring of plot_img for parameters not listed below.
  
      Parameters
      ----------
      %(img)s
          Image to plot.
  
      bg_vmin : :obj:`float`, optional
          vmin for `bg_img`.
  
      bg_vmax : :obj:`float`, optional
          vmax for `bg_img`.
  
      interpolation : string, default='nearest'
          Passed to the add_overlay calls.
  
      display_factory : function, default=get_slicer
          Takes a display_mode argument and return a display class.
  
      Returns
      -------
      display : :class:`~nilearn.plotting.displays.OrthoSlicer` or \
          :class:`~nilearn.plotting.displays.OrthoProjector` or None
          An instance of the OrthoSlicer or OrthoProjector class depending on the
          function defined in ``display_factory``. If ``output_file`` is defined,
          None is returned.
      """
      show_nan_msg = False
      if vmax is not None and np.isnan(vmax):
          vmax = None
          show_nan_msg = True
      if vmin is not None and np.isnan(vmin):
          vmin = None
          show_nan_msg = True
      if show_nan_msg:
          nan_msg = (
              "NaN is not permitted for the vmax and vmin arguments.\n"
              "Tip: Use np.nanmax() instead of np.max()."
          )
          warnings.warn(nan_msg)
  
      if isinstance(cut_coords, numbers.Number) and display_mode in (
          "ortho",
          "tiled",
      ):
          raise ValueError(
              f"The input given for display_mode='{display_mode}' "
              "needs to be a list of 3d world coordinates in (x, y, z). "
              "You provided single cut, "
              f"cut_coords={cut_coords}"
          )
  
      if img is not False and img is not None:
          img = _utils.check_niimg_3d(img, dtype="auto")
          data = safe_get_data(img, ensure_finite=True)
          affine = img.affine
  
          if np.isnan(np.sum(data)):
              data = np.nan_to_num(data)
  
          # Deal with automatic settings of plot parameters
          if threshold == "auto":
              # Threshold epsilon below a percentile value, to be sure that some
              # voxels pass the threshold
              threshold = fast_abs_percentile(data) - 1e-5
  
          img = new_img_like(img, as_ndarray(data), affine)
  
      display = display_factory(display_mode)(
          img,
          threshold=threshold,
          cut_coords=cut_coords,
          figure=figure,
          axes=axes,
          black_bg=black_bg,
          colorbar=colorbar,
          brain_color=brain_color,
          radiological=radiological,
      )
      if bg_img is not None:
          bg_img = _utils.check_niimg_3d(bg_img)
          display.add_overlay(
              bg_img,
              vmin=bg_vmin,
              vmax=bg_vmax,
              cmap=plt.cm.gray,
              interpolation=interpolation,
          )
  
      if img is not None and img is not False:
          display.add_overlay(
              new_img_like(img, data, affine),
              threshold=threshold,
              interpolation=interpolation,
              colorbar=colorbar,
              vmin=vmin,
              vmax=vmax,
              cbar_vmin=cbar_vmin,
              cbar_vmax=cbar_vmax,
              cbar_tick_format=cbar_tick_format,
              **kwargs,
          )
  
      if annotate:
          display.annotate(decimals=decimals)
      if draw_cross:
          display.draw_cross()
      if title is not None and title != "":
          display.title(title)
      if hasattr(display, "_cbar"):
          cbar = display._cbar
          new_tick_locs = _get_cropped_cbar_ticks(
              cbar.vmin,
              cbar.vmax,
              threshold,
              n_ticks=len(cbar.locator.locs),
          )
          cbar.set_ticks(new_tick_locs)
      if output_file is not None:
          display.savefig(output_file)
          display.close()
          display = None
      return display
  
imports: import collections.abc
  import functools
  import numbers
  import os
  import warnings
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from matplotlib import gridspec
  from matplotlib.colors import LinearSegmentedColormap
  from nibabel.spatialimages import SpatialImage
  from scipy import stats
  from scipy.ndimage import binary_fill_holes
  from nilearn.image.resampling import reorder_img
  from nilearn.maskers import NiftiMasker
  from nilearn.plotting.displays import get_projector, get_slicer
  from nilearn.plotting.displays._slicers import _get_cbar_ticks
  from ..None import _utils
  from .._utils import compare_version, fill_doc
  from .._utils.extmath import fast_abs_percentile
  from .._utils.ndimage import get_border_data
  from .._utils.niimg import safe_get_data
  from .._utils.numpy_conversions import as_ndarray
  from .._utils.param_validation import check_threshold
  from ..datasets import load_mni152_template
  from ..image import get_data, iter_img, math_img, new_img_like, resample_to_img
  from ..masking import apply_mask, compute_epi_mask
  from ..signal import clean
  from .None import cm
label_desc: Use image node_id 3 for calling a global function with example usage: _plot_img_with_bg(img, bg_img, cut_coords, output_file, display_mode, colorbar, figure, axes, title, threshold, annotate, draw_cross, black_bg, vmin, vmax, bg_vmin, bg_vmax, interpolation, display_factory, cbar_vmin, cbar_vmax, cbar_tick_format, brain_color, decimals, radiological) and returns: display