code: def load_mask_img(mask_img, allow_empty=False):
      """Check that a mask is valid, ie with two values including 0 and load it.
  
      Parameters
      ----------
      mask_img : Niimg-like object
          See :ref:`extracting_data`.
          The mask to check.
  
      allow_empty : :obj:`bool`, default=False
          Allow loading an empty mask (full of 0 values).
  
      Returns
      -------
      mask : :class:`numpy.ndarray`
          Boolean version of the mask.
  
      mask_affine: None or (4,4) array-like
          Affine of the mask.
      """
      mask_img = _utils.check_niimg_3d(mask_img)
      mask = safe_get_data(mask_img, ensure_finite=True)
      values = np.unique(mask)
  
      if len(values) == 1:
          # We accept a single value if it is not 0 (full true mask).
          if values[0] == 0 and not allow_empty:
              raise ValueError(
                  "The mask is invalid as it is empty: it masks all data."
              )
      elif len(values) == 2:
          # If there are 2 different values, one of them must be 0 (background)
          if 0 not in values:
              raise ValueError(
                  "Background of the mask must be represented with 0. "
                  f"Given mask contains: {values}."
              )
      else:
          # If there are more than 2 values, the mask is invalid
          raise ValueError(
              f"Given mask is not made of 2 values: {values}. "
              "Cannot interpret as true or false."
          )
  
      mask = _utils.as_ndarray(mask, dtype=bool)
      return mask, mask_img.affine
  
imports: import numbers
  import warnings
  import numpy
  from joblib import Parallel, delayed
  from scipy.ndimage import binary_dilation, binary_erosion
  from .None import _utils
  from ._utils import fill_doc
  from ._utils.cache_mixin import cache
  from ._utils.ndimage import get_border_data, largest_connected_component
  from ._utils.niimg import safe_get_data
  from .datasets import load_mni152_gm_template, load_mni152_template, load_mni152_wm_template
  from .image import get_data, new_img_like, resampling
label_desc: Use image node_id 1 for calling a global function with example usage: load_mask_img(mask_img, allow_empty) and returns: mask,  mask_img