code: def load_anat(anat_img=MNI152TEMPLATE, dim="auto", black_bg="auto"):
      """Load anatomy, for optional diming."""
      vmin = None
      vmax = None
      if anat_img is False or anat_img is None:
          if black_bg == "auto":
              # No anatomy given: no need to turn black_bg on
              black_bg = False
          return anat_img, black_bg, vmin, vmax
  
      if anat_img is MNI152TEMPLATE:
          anat_img.load()
          # We special-case the 'canonical anat', as we don't need
          # to do a few transforms to it.
          vmin = 0
          vmax = anat_img.vmax
          if black_bg == "auto":
              black_bg = False
      else:
          anat_img = _utils.check_niimg_3d(anat_img)
          # Clean anat_img for non-finite values to avoid computing unnecessary
          # border data values.
          data = safe_get_data(anat_img, ensure_finite=True)
          anat_img = new_img_like(
              anat_img, data, affine=anat_img.affine
          )
          if dim or black_bg == "auto":
              # We need to inspect the values of the image
              vmin = np.nanmin(data)
              vmax = np.nanmax(data)
          if black_bg == "auto":
              # Guess if the background is rather black or light based on
              # the values of voxels near the border
              background = np.median(get_border_data(data, 2))
              if background > 0.5 * (vmin + vmax):
                  black_bg = False
              else:
                  black_bg = True
      if dim:
          if dim != "auto" and not isinstance(dim, numbers.Number):
              raise ValueError(
                  "The input given for 'dim' needs to be a float. "
                  f"You provided dim={dim} in {type(dim)}."
              )
          vmean = 0.5 * (vmin + vmax)
          ptp = 0.5 * (vmax - vmin)
          if black_bg:
              if not isinstance(dim, numbers.Number):
                  dim = 0.8
              vmax = vmean + (1 + dim) * ptp
          else:
              if not isinstance(dim, numbers.Number):
                  dim = 0.6
              vmin = 0.5 * (2 - dim) * vmean - (1 + dim) * ptp
      return anat_img, black_bg, vmin, vmax
  
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 6 for calling a global function with example usage: load_anat(anat_img, dim, black_bg) and returns: anat_img,  black_bg,  vmin,  vmax, anat_img,  black_bg,  vmin,  vmax