code: def mask_parcellation(
      mask_images, nb_parcel, threshold=0, output_image=None
  ):
      """Performs the parcellation of a certain mask
  
      Parameters
      ----------
      mask_images: string or Nifti1Image or list of strings/Nifti1Images,
                   paths of mask image(s) that define(s) the common space.
      nb_parcel: int,
                 number of desired parcels
      threshold: float, optional,
                 level of intersection of the masks
      output_image: string, optional
                    path of the output image
  
      Returns
      -------
      wim: Nifti1Imagine instance,  representing the resulting parcellation
      """
      if isinstance(mask_images, str):
          mask = mask_images
      elif isinstance(mask_images, Nifti1Image):
          mask = mask_images
      else:
          # mask_images should be a list
          mask_data = intersect_masks(mask_images, threshold=0) > 0
          mask = Nifti1Image(
              mask_data.astype("u1"), get_affine(load(mask_images[0]))
          )
  
      domain = grid_domain_from_image(mask)
      cent, labels, J = kmeans(domain.coord, nb_parcel)
      sub_dom = SubDomains(domain, labels)
      # get id (or labels) image
      wim = sub_dom.to_image(fid="id", roi=True)
      return wim
  
file_path: nipy/nipy/labs/spatial_models/parcel_io.py
imports: import os.path
  from warnings import warn
  import numpy
  from nibabel import Nifti1Image, load, save
  from nipy.algorithms.clustering.utils import kmeans
  from nipy.io.nibcompat import get_affine, get_header
  from ..mask import intersect_masks
  from .discrete_domain import grid_domain_from_image
  from .mroi import SubDomains
label_desc: Use image node_id 1 for calling a global function with example usage: mask_parcellation(mask_images, nb_parcel, threshold, output_image) and returns: wim