code: def _stc_to_label(stc, src, smooth, subjects_dir=None):
      """Compute a label from the non-zero sources in an stc object.
  
      Parameters
      ----------
      stc : SourceEstimate
          The source estimates.
      src : SourceSpaces | str | None
          The source space over which the source estimates are defined.
          If it's a string it should be the subject name (e.g. ``'fsaverage'``').
          Can be None if ``stc.subject`` is not None.
      smooth : int
          Number of smoothing iterations.
      subjects_dir : path-like | None
          Path to ``SUBJECTS_DIR`` if it is not set in the environment.
  
      Returns
      -------
      labels : list of Labels | list of list of Labels
          The generated labels. If connected is False, it returns
          a list of Labels (one per hemisphere). If no Label is available
          in a hemisphere, None is returned. If connected is True,
          it returns for each hemisphere a list of connected labels
          ordered in decreasing order depending of the maximum value in the stc.
          If no Label is available in an hemisphere, an empty list is returned.
      """
      src = stc.subject if src is None else src
  
      if isinstance(src, str):
          subject = src
      else:
          subject = stc.subject
  
      if isinstance(src, str):
          subjects_dir = Path(get_subjects_dir(subjects_dir))
          surf_path_from = subjects_dir / src / "surf"
          rr_lh, tris_lh = read_surface(surf_path_from / "lh.white")
          rr_rh, tris_rh = read_surface(surf_path_from / "rh.white")
          rr = [rr_lh, rr_rh]
          tris = [tris_lh, tris_rh]
      else:
          if not isinstance(src, SourceSpaces):
              raise TypeError(
                  "src must be a string or a set of source spaces"
              )
          if len(src) != 2:
              raise ValueError(
                  "source space should contain the 2 hemispheres"
              )
          rr = [1e3 * src[0]["rr"], 1e3 * src[1]["rr"]]
          tris = [src[0]["tris"], src[1]["tris"]]
  
      labels = []
      cnt = 0
      for hemi_idx, (
          hemi,
          this_vertno,
          this_tris,
          this_rr,
      ) in enumerate(zip(["lh", "rh"], stc.vertices, tris, rr)):
          this_data = stc.data[cnt : cnt + len(this_vertno)]
          e = mesh_edges(this_tris)
          e.data[e.data == 2] = 1
          n_vertices = e.shape[0]
          e = e + sparse.eye(n_vertices, n_vertices)
  
          clusters = [this_vertno[np.any(this_data, axis=1)]]
  
          cnt += len(this_vertno)
  
          clusters = [c for c in clusters if len(c) > 0]
  
          if len(clusters) == 0:
              this_labels = None
          else:
              this_labels = []
              colors = _n_colors(len(clusters))
              for c, color in zip(clusters, colors):
                  idx_use = c
                  for k in range(smooth):
                      e_use = e[:, idx_use]
                      data1 = e_use * np.ones(len(idx_use))
                      idx_use = np.where(data1)[0]
  
                  label = Label(
                      idx_use,
                      this_rr[idx_use],
                      None,
                      hemi,
                      "Label from stc",
                      subject=subject,
                      color=color,
                  )
  
                  this_labels.append(label)
  
              this_labels = this_labels[0]
  
          labels.append(this_labels)
  
      return labels
  
imports: import glob
  import os
  import pickle
  import shutil
  from itertools import product
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  from mne import grow_labels, labels_to_stc, morph_labels, random_parcellation, read_label, read_labels_from_annot, read_source_estimate, read_source_spaces, read_surface, spatial_tris_adjacency, split_label, stc_to_label, write_labels_to_annot
  from mne.datasets import testing
  from mne.label import Label, _blend_colors, _load_vert_pos, _n_colors, _read_annot, _read_annot_cands, label_sign_flip, select_sources
  from mne.source_estimate import mesh_edges
  from mne.source_space import SourceSpaces
  from mne.surface import _mesh_borders
  from mne.utils import _record_warnings, get_subjects_dir
label_desc: Use image node_id 1 for calling a global function with example usage: _stc_to_label(stc, src, smooth, subjects_dir) and returns: labels