code: def largest_cc(mask):
      """Return the largest connected component of a 3D mask array.
  
      Parameters
      -----------
      mask: 3D boolean array
            3D array indicating a mask.
  
      Returns
      --------
      mask: 3D boolean array
            3D array indicating a mask, with only one connected component.
      """
      # We use asarray to be able to work with masked arrays.
      mask = np.asarray(mask)
      labels, label_nb = ndimage.label(mask)
      if not label_nb:
          raise ValueError(
              "No non-zero values: no connected components"
          )
      if label_nb == 1:
          return mask.astype(np.bool_)
      label_count = np.bincount(labels.ravel().astype(np.int_))
      # discard 0 the 0 label
      label_count[0] = 0
      return labels == label_count.argmax()
  
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 1 for calling a global function with example usage: largest_cc(mask) and returns: unknown, mask