code: def view_img(
      stat_map_img,
      bg_img="MNI152",
      cut_coords=None,
      colorbar=True,
      title=None,
      threshold=1e-6,
      annotate=True,
      draw_cross=True,
      black_bg="auto",
      cmap=cm.cold_hot,
      symmetric_cmap=True,
      dim="auto",
      vmax=None,
      vmin=None,
      resampling_interpolation="continuous",
      opacity=1,
      **kwargs,
  ):
      """Interactive html viewer of a statistical map, with optional background.
  
      Parameters
      ----------
      stat_map_img : Niimg-like object
          See :ref:`extracting_data`.
          The statistical map image. Can be either a 3D volume or a 4D volume
          with exactly one time point.
      %(bg_img)s
          If nothing is specified, the MNI152 template will be used.
          To turn off background image, just pass "bg_img=False".
          Default='MNI152'.
  
      cut_coords : None, or a tuple of floats
          The :term:`MNI` coordinates of the point where the cut is performed
          as a 3-tuple: (x, y, z). If None is given, the cuts are calculated
          automatically.
  
      colorbar : boolean, default=True
          If True, display a colorbar on top of the plots.
      %(title)s
      threshold : string, number or None, default=1e-6
          If None is given, the image is not thresholded.
          If a string of the form "90%%" is given, use the 90-th percentile of
          the absolute value in the image.
          If a number is given, it is used to threshold the image:
          values below the threshold (in absolute value) are plotted
          as transparent. If auto is given, the threshold is determined
          automatically.
  
      annotate : boolean, default=True
          If annotate is True, current cuts are added to the viewer.
      %(draw_cross)s
      black_bg : boolean or 'auto', default='auto'
          If True, the background of the image is set to be black.
          Otherwise, a white background is used.
          If set to auto, an educated guess is made to find if the background
          is white or black.
      %(cmap)s
          Default=`plt.cm.cold_hot`.
      symmetric_cmap : bool, default=True
          True: make colormap symmetric (ranging from -vmax to vmax).
          False: the colormap will go from the minimum of the volume to vmax.
          Set it to False if you are plotting a positive volume, e.g. an atlas
          or an anatomical image.
      %(dim)s
          Default='auto'.
      vmax : float, or None, optional
          max value for mapping colors.
          If vmax is None and symmetric_cmap is True, vmax is the max
          absolute value of the volume.
          If vmax is None and symmetric_cmap is False, vmax is the max
          value of the volume.
  
      vmin : float, or None, optional
          min value for mapping colors.
          If `symmetric_cmap` is `True`, `vmin` is always equal to `-vmax` and
          cannot be chosen.
          If `symmetric_cmap` is `False`, `vmin` is equal to the min of the
          image, or 0 when a threshold is used.
      %(resampling_interpolation)s
          Default='continuous'.
      opacity : float in [0,1], default=1
          The level of opacity of the overlay (0: transparent, 1: opaque).
  
      Returns
      -------
      html_view : the html viewer object.
          It can be saved as an html page `html_view.save_as_html('test.html')`,
          or opened in a browser `html_view.open_in_browser()`.
          If the output is not requested and the current environment is a Jupyter
          notebook, the viewer will be inserted in the notebook.
  
      See Also
      --------
      nilearn.plotting.plot_stat_map:
          static plot of brain volume, on a single or multiple planes.
      nilearn.plotting.view_connectome:
          interactive 3d view of a connectome.
      nilearn.plotting.view_markers:
          interactive plot of colored markers.
      nilearn.plotting.view_surf, nilearn.plotting.view_img_on_surf:
          interactive view of statistical maps or surface atlases on the cortical
          surface.
  
      """
      # Prepare the color map and thresholding
      mask_img, stat_map_img, data, threshold = _mask_stat_map(
          stat_map_img, threshold
      )
      colors = colorscale(
          cmap,
          data.ravel(),
          threshold=threshold,
          symmetric_cmap=symmetric_cmap,
          vmax=vmax,
          vmin=vmin,
      )
  
      # Prepare the data for the cuts
      bg_img, bg_min, bg_max, black_bg = _load_bg_img(
          stat_map_img, bg_img, black_bg, dim
      )
      stat_map_img, mask_img = _resample_stat_map(
          stat_map_img, bg_img, mask_img, resampling_interpolation
      )
      cut_slices = _get_cut_slices(stat_map_img, cut_coords, threshold)
  
      # Now create a json-like object for the viewer, and converts in html
      json_view = _json_view_data(
          bg_img,
          stat_map_img,
          mask_img,
          bg_min,
          bg_max,
          black_bg,
          colors,
          cmap,
          colorbar,
      )
  
      json_view["params"] = _json_view_params(
          stat_map_img.shape,
          stat_map_img.affine,
          colors["vmin"],
          colors["vmax"],
          cut_slices,
          black_bg,
          opacity,
          draw_cross,
          annotate,
          title,
          colorbar,
          value=False,
      )
  
      html_view = _json_view_to_html(json_view)
  
      return html_view
  
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 15 for calling a global function with example usage: view_img(stat_map_img, bg_img, cut_coords, colorbar, title, threshold, annotate, draw_cross, black_bg, cmap, symmetric_cmap, dim, vmax, vmin, resampling_interpolation, opacity) and returns: html_view