code: def intersect_masks(mask_imgs, threshold=0.5, connected=True):
      """Compute intersection of several masks.
  
      Given a list of input mask images, generate the output image which
      is the threshold-level intersection of the inputs.
  
      Parameters
      ----------
      mask_imgs : :obj:`list` of Niimg-like objects
          See :ref:`extracting_data`.
          3D individual masks with same shape and affine.
  
      threshold : :obj:`float`, default=0.5
          Gives the level of the intersection, must be within [0, 1].
          threshold=1 corresponds to keeping the intersection of all
          masks, whereas threshold=0 is the union of all masks.
      %(connected)s
          Default=True.
  
      Returns
      -------
      grp_mask : 3D :class:`nibabel.nifti1.Nifti1Image`
          Intersection of all masks.
      """
      if len(mask_imgs) == 0:
          raise ValueError("No mask provided for intersection")
      grp_mask = None
      first_mask, ref_affine = load_mask_img(
          mask_imgs[0], allow_empty=True
      )
      ref_shape = first_mask.shape
      if threshold > 1:
          raise ValueError("The threshold should be smaller than 1")
      if threshold < 0:
          raise ValueError("The threshold should be greater than 0")
      threshold = min(threshold, 1 - 1.0e-7)
  
      for this_mask in mask_imgs:
          mask, affine = load_mask_img(this_mask, allow_empty=True)
          if np.any(affine != ref_affine):
              raise ValueError("All masks should have the same affine")
          if np.any(mask.shape != ref_shape):
              raise ValueError("All masks should have the same shape")
  
          if grp_mask is None:
              # We use int here because there may be a lot of masks to merge
              grp_mask = _utils.as_ndarray(mask, dtype=int)
          else:
              # If this_mask is floating point and grp_mask is integer, numpy 2
              # casting rules raise an error for in-place addition. Hence we do
              # it long-hand.
              # XXX should the masks be coerced to int before addition?
              grp_mask += mask
  
      grp_mask = grp_mask > (threshold * len(list(mask_imgs)))
  
      if np.any(grp_mask > 0) and connected:
          grp_mask = largest_connected_component(grp_mask)
      grp_mask = _utils.as_ndarray(grp_mask, dtype=np.int8)
      return new_img_like(
          _utils.check_niimg_3d(mask_imgs[0]), grp_mask, ref_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 3 for calling a global function with example usage: intersect_masks(mask_imgs, threshold, connected) and returns: new_img_like