code: def intersect_masks(
      input_masks, output_filename=None, threshold=0.5, cc=True
  ):
      """
      Given a list of input mask images, generate the output image which
      is the the threshold-level intersection of the inputs
  
      Parameters
      ----------
      input_masks: list of strings or ndarrays
          paths of the input images nsubj set as len(input_mask_files), or
          individual masks.
      output_filename, string:
          Path of the output image, if None no file is saved.
      threshold: float within [0, 1[, optional
          gives the level of the intersection.
          threshold=1 corresponds to keeping the intersection of all
          masks, whereas threshold=0 is the union of all masks.
      cc: bool, optional
          If true, extract the main connected component
  
      Returns
      -------
      grp_mask, boolean array of shape the image shape
      """
      grp_mask = None
      if threshold > 1:
          raise ValueError("The threshold should be < 1")
      if threshold < 0:
          raise ValueError("The threshold should be > 0")
      threshold = min(threshold, 1 - 1.0e-7)
  
      for this_mask in input_masks:
          if isinstance(this_mask, str):
              # We have a filename
              this_mask = load(this_mask).get_fdata()
          if grp_mask is None:
              grp_mask = this_mask.copy().astype(np.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 = grp_mask + this_mask
  
      grp_mask = grp_mask > (threshold * len(list(input_masks)))
  
      if np.any(grp_mask > 0) and cc:
          grp_mask = largest_cc(grp_mask)
  
      if output_filename is not None:
          if isinstance(input_masks[0], str):
              nim = load(input_masks[0])
              header = get_header(nim)
              affine = get_affine(nim)
          else:
              header = {}
              affine = np.eye(4)
          header["descrip"] = "mask image"
          output_image = nifti1.Nifti1Image(
              grp_mask.astype(np.uint8),
              affine=affine,
              header=header,
          )
          save(output_image, output_filename)
  
      return grp_mask > 0
  
file_path: nipy/nipy/labs/mask.py
imports: import math
  import numpy
  from nibabel import load, nifti1, save
  from scipy import ndimage
  from ..io.nibcompat import get_affine, get_header, get_unscaled_data
label_desc: Use image node_id 6 for calling a global function with example usage: intersect_masks(input_masks, output_filename, threshold, cc) and returns: unknown