code: def connected_label_regions(
      labels_img, min_size=None, connect_diag=True, labels=None
  ):
      """Extract connected regions from a brain atlas image \
      defined by labels (integers).
  
      For each label in a :term:`parcellation`, separates out connected
      components and assigns to each separated region a unique label.
  
      Parameters
      ----------
      labels_img : Nifti-like image
          A 3D image which contains regions denoted as labels. Each region
          is assigned with integers.
  
      min_size : :obj:`float`, optional
          Minimum region size (in mm^3) in volume required
          to keep after extraction.
          Removes small or spurious regions.
  
      connect_diag : :obj:`bool`, default=True
          If 'connect_diag' is True, two voxels are considered in the same region
          if they are connected along the diagonal (26-connectivity). If it is
          False, two voxels are considered connected only if they are within the
          same x, y, or z direction.
  
      labels : 1D :class:`numpy.ndarray` or :obj:`list` of :obj:`str`, optional
          Each string in a list or array denote the name of the brain atlas
          regions given in labels_img input. If provided, same names will be
          re-assigned corresponding to each connected component based extraction
          of regions relabelling. The total number of names should match with the
          number of labels assigned in the image.
  
      Notes
      -----
      The order of the names given in labels should be appropriately matched with
      the unique labels (integers) assigned to each region given in labels_img
      (also excluding 'Background' label).
  
      Returns
      -------
      new_labels_img : :class:`nibabel.nifti1.Nifti1Image`
          A new image comprising of regions extracted on an input labels_img.
  
      new_labels : :obj:`list`, optional
          If labels are provided, new labels assigned to region extracted will
          be returned. Otherwise, only new labels image will be returned.
  
      See Also
      --------
      nilearn.datasets.fetch_atlas_harvard_oxford : For an example of atlas with
          labels.
  
      nilearn.regions.RegionExtractor : A class can be used for region extraction
          on continuous type atlas images.
  
      nilearn.regions.connected_regions : A function used for region extraction
          on continuous type atlas images.
  
      """
      labels_img = check_niimg_3d(labels_img)
      labels_data = safe_get_data(labels_img, ensure_finite=True)
      affine = labels_img.affine
  
      check_unique_labels = np.unique(labels_data)
  
      if min_size is not None and not isinstance(
          min_size, numbers.Number
      ):
          raise ValueError(
              "Expected 'min_size' to be specified as integer. "
              f"You provided {min_size}"
          )
      if not isinstance(connect_diag, bool):
          raise ValueError(
              "'connect_diag' must be specified as True or False. "
              f"You provided {connect_diag}"
          )
      if np.any(check_unique_labels < 0):
          raise ValueError(
              "The 'labels_img' you provided has unknown/negative "
              f"integers as labels {check_unique_labels} assigned to regions. "
              "All regions in an image should have positive "
              "integers assigned as labels."
          )
  
      unique_labels = set(check_unique_labels)
      # check for background label indicated as 0
      if np.any(check_unique_labels == 0):
          unique_labels.remove(0)
  
      if labels is not None:
          if not isinstance(
              labels, collections.abc.Iterable
          ) or isinstance(labels, str):
              labels = [labels]
          if len(unique_labels) != len(labels):
              raise ValueError(
                  f"The number of labels: {len(labels)} provided as input "
                  f"in labels={labels} does not match with the number "
                  f"of unique labels in labels_img: {len(unique_labels)}. "
                  "Please provide appropriate match with unique "
                  "number of labels in labels_img."
              )
          new_names = []
  
      this_labels = (
          [None] * len(unique_labels) if labels is None else labels
      )
  
      new_labels_data = np.zeros(labels_data.shape, dtype=int)
      current_max_label = 0
      for label_id, name in zip(unique_labels, this_labels):
          this_label_mask = labels_data == label_id
          # Extract regions assigned to each label id
          if connect_diag:
              structure = np.ones((3, 3, 3), dtype=int)
              regions, this_n_labels = label(
                  this_label_mask.astype(int), structure=structure
              )
          else:
              regions, this_n_labels = label(
                  this_label_mask.astype(int)
              )
  
          if min_size is not None:
              index = np.arange(this_n_labels + 1)
              regions = _remove_small_regions(
                  regions, index, affine, min_size=min_size
              )
              this_n_labels = regions.max()
  
          cur_regions = regions[regions != 0] + current_max_label
          new_labels_data[regions != 0] = cur_regions
          current_max_label += this_n_labels
          if name is not None:
              new_names.extend([name] * this_n_labels)
  
      new_labels_img = new_img_like(
          labels_img, new_labels_data, affine=affine
      )
  
      return (
          (new_labels_img, new_names)
          if labels is not None
          else new_labels_img
      )
  
imports: import collections.abc
  import numbers
  import numpy
  from joblib import Memory
  from scipy.ndimage import label
  from scipy.stats import scoreatpercentile
  from nilearn.maskers import NiftiMapsMasker
  from ..None import masking
  from .._utils import check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.ndimage import peak_local_max
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import check_same_fov
  from .._utils.segmentation import random_walker
  from ..image import new_img_like, resample_img
  from ..image.image import concat_imgs, smooth_array, threshold_img
label_desc: Use image node_id 4 for calling a global function with example usage: connected_label_regions(labels_img, min_size, connect_diag, labels) and returns: unknown