code: def extract_clusters_from_diam(T, XYZ, th, diam, k=18):
      """
      Extract clusters from a statistical map
      under diameter constraint
      and above given threshold
      In:  T      (p)     statistical map
           XYZ    (3,p)   voxels coordinates
           th     <float> minimum threshold
           diam   <int>   maximal diameter (in voxels)
           k      <int>   the number of neighbours considered. (6,18 or 26)
      Out: labels (p)     cluster labels
  
      Comment by alexis-roche, September 15th 2012: this function was
      originally developed by Merlin Keller in an attempt to generalize
      classical cluster-level analysis by subdividing clusters in blobs
      with limited diameter (at least, this is my understanding). This
      piece of code seems to have remained very experimental and its
      usefulness in real-world neuroimaging image studies is still to be
      demonstrated.
      """
      CClabels = extract_clusters_from_thresh(T, XYZ, th, k)
      nCC = CClabels.max() + 1
      labels = -np.ones(len(CClabels), int)
      # Calls _extract_clusters_from_diam, a recursive function, and
      # catches an exception if maximum recursion depth is reached
      try:
          labels = _extract_clusters_from_diam(
              labels, T, XYZ, th, diam, k, nCC, CClabels
          )
      except RuntimeError:
          warnings.warn("_extract_clusters_from_diam did not converge")
      return labels
  
imports: import numpy
  import warnings
  from nipy.algorithms.graph import wgraph_from_3d_grid
  from nipy.algorithms.graph.field import Field, field_from_graph_and_data
  from ..utils import zscore
  from .onesample import stat
  from .onesample import stat_mfx
  from .twosample import stat
  from .twosample import stat_mfx
label_desc: Use image node_id 3 for calling a global function with example usage: extract_clusters_from_diam(T, XYZ, th, diam, k) and returns: labels