code: def _load_bg_img(
      stat_map_img, bg_img="MNI152", black_bg="auto", dim="auto"
  ):
      """Load and resample bg_img in an isotropic resolution, \
      with a positive diagonal affine matrix.
  
      Returns: bg_img, bg_min, bg_max, black_bg
  
      """
      if bg_img is None or bg_img is False:
          if black_bg == "auto":
              black_bg = False
          bg_img = new_img_like(
              stat_map_img, np.ma.masked_all(stat_map_img.shape)
          )
          bg_min, bg_max = 0, 0
      else:
          if isinstance(bg_img, str) and bg_img == "MNI152":
              bg_img = load_mni152_template(resolution=2)
          else:
              bg_img = check_niimg_3d(bg_img)
          masked_data = np.ma.masked_inside(
              safe_get_data(bg_img, ensure_finite=True),
              -1e-6,
              1e-6,
              copy=False,
          )
          bg_img = new_img_like(bg_img, masked_data)
          bg_img, black_bg, bg_min, bg_max = load_anat(
              bg_img, dim=dim, black_bg=black_bg
          )
      bg_img = reorder_img(bg_img, resample="nearest")
      return bg_img, bg_min, bg_max, black_bg
  
imports: import copy
  import json
  import os
  import warnings
  from base64 import b64encode
  from io import BytesIO
  import matplotlib
  import numpy
  from matplotlib.image import imsave
  from nibabel.affines import apply_affine
  from nilearn.plotting.html_document import HTMLDocument
  from .._utils import fill_doc
  from .._utils.extmath import fast_abs_percentile
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import check_niimg_3d
  from .._utils.param_validation import check_threshold
  from ..datasets import load_mni152_template
  from ..image import get_data, new_img_like, reorder_img, resample_to_img
  from ..plotting import cm
  from ..plotting.find_cuts import find_xyz_cut_coords
  from ..plotting.img_plotting import load_anat
  from .js_plotting_utils import colorscale, get_html_template
label_desc: Use image node_id 7 for calling a global function with example usage: _load_bg_img(stat_map_img, bg_img, black_bg, dim) and returns: bg_img,  bg_min,  bg_max,  black_bg