code: def skeletonize_labels(labels):
      '''Skeletonize a labels matrix'''
      #
      # The trick here is to separate touching labels by coloring the
      # labels matrix and then processing each color separately
      #
      colors = color_labels(labels)
      max_color = np.max(colors)
      if max_color == 0:
          return labels
      result = np.zeros(labels.shape, labels.dtype)
      for i in range(1,max_color+1):
          mask = skeletonize(colors==i)
          result[mask] = labels[mask]
      return resulf skeletonize_labels(labels):
      '''Skeletonize a labels matrix'''
      #
      # The trick here is to separate touching labels by coloring the
      # labels matrix and then processing each color separately
      #
      colors = color_labels(labels)
      max_color = np.max(colors)
      if max_color == 0:
          return labels
      result = np.zeros(labels.shape, labels.dtype)
      for i in range(1,max_color+1):
          mask = skeletonize(colors==i)
          result[mask] = labels[mask]
      return result
docs: Skeletonize a labels matrix