code: def compute_mask_sessions(
      session_images,
      m=0.2,
      M=0.9,
      cc=1,
      threshold=0.5,
      exclude_zeros=False,
      return_mean=False,
      opening=2,
  ):
      """Compute a common mask for several sessions of fMRI data.
  
          Uses the mask-finding algorithms to extract masks for each
          session, and then keep only the main connected component of the
          a given fraction of the intersection of all the masks.
  
  
      Parameters
      ----------
      session_images : list of (list of strings) or nipy image objects
          A list of images/list of nifti filenames. Each inner list/image
          represents a session.
      m : float, optional
          lower fraction of the histogram to be discarded.
      M: float, optional
          upper fraction of the histogram to be discarded.
      cc: boolean, optional
          if cc is True, only the largest connect component is kept.
      threshold : float, optional
          the inter-session threshold: the fraction of the
          total number of session in for which a voxel must be in the
          mask to be kept in the common mask.
          threshold=1 corresponds to keeping the intersection of all
          masks, whereas threshold=0 is the union of all masks.
      exclude_zeros: boolean, optional
          Consider zeros as missing values for the computation of the
          threshold. This option is useful if the images have been
          resliced with a large padding of zeros.
      return_mean: boolean, optional
          if return_mean is True, the mean image across subjects is
          returned.
      opening: int, optional,
               size of  the morphological opening
  
      Returns
      -------
      mask : 3D boolean ndarray
          The brain mask
      mean : 3D float array
          The mean image
      """
      mask, mean = None, None
      for index, session in enumerate(session_images):
          if hasattr(session, "get_fdata"):
              mean = session.get_fdata()
              if mean.ndim > 3:
                  mean = mean.mean(-1)
              this_mask = compute_mask(
                  mean,
                  None,
                  m=m,
                  M=M,
                  cc=cc,
                  opening=opening,
                  exclude_zeros=exclude_zeros,
              )
              if return_mean:
                  this_mask = this_mask, mean
          else:
              this_mask = compute_mask_files(
                  session,
                  m=m,
                  M=M,
                  cc=cc,
                  exclude_zeros=exclude_zeros,
                  return_mean=return_mean,
                  opening=opening,
              )
          if return_mean:
              this_mask, this_mean = this_mask
              if mean is None:
                  mean = this_mean.astype(np.float64)
              else:
                  mean += this_mean
          this_mask = this_mask.astype(np.int8)
          if mask is None:
              mask = this_mask
          else:
              mask += this_mask
          # Free memory early
          del this_mask
  
      # Take the "half-intersection", i.e. all the voxels that fall within
      # 50% of the individual masks.
      mask = mask > threshold * len(list(session_images))
  
      if cc:
          # Select the largest connected component (each mask is
          # connect, but the half-interesection may not be):
          mask = largest_cc(mask)
      mask = mask.astype(np.bool_)
  
      if return_mean:
          # Divide by the number of sessions
          mean /= len(session_images)
          return mask, mean
  
      return mask
  
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 5 for calling a global function with example usage: compute_mask_sessions(session_images, m, M, cc, threshold, exclude_zeros, return_mean, opening) and returns: mask, mask,  mean