code: def template_segmentation_image(
      source,
      color_radius,
      color_neighbors,
      object_radius,
      object_neighbors,
      noise_size,
  ):
      data = read_image(source)
  
      dbscan_instance = dbscan(
          data, color_radius, color_neighbors, True
      )
      print("Segmentation: '", source, "', Dimensions:", len(data[0]))
      dbscan_instance.process()
  
      clusters = dbscan_instance.get_clusters()
  
      real_clusters = [
          cluster for cluster in clusters if len(cluster) > noise_size
      ]
  
      print(
          "Draw allocated color segments (back mask representation)..."
      )
      draw_image_mask_segments(source, real_clusters)
  
      print(
          "Draw allocated color segments (color segment representation)..."
      )
      draw_image_color_segments(source, real_clusters)
  
      if object_radius is None:
          return
  
      # continue analysis
      pointer_image = Image.open(source)
      image_size = pointer_image.size
  
      object_colored_clusters = []
  
      for cluster in clusters:
          coordinates = []
          for index in cluster:
              y = int(floor(index / image_size[0]))
              x = index - y * image_size[0]
  
              coordinates.append([x, y])
  
          # perform clustering analysis of the colored objects
          if len(coordinates) < noise_size:
              continue
  
          dbscan_instance = dbscan(
              coordinates, object_radius, object_neighbors, True
          )
          dbscan_instance.process()
  
          object_clusters = dbscan_instance.get_clusters()
  
          # decode it
          real_description_clusters = []
          for object_cluster in object_clusters:
              real_description = []
              for index_object in object_cluster:
                  real_description.append(cluster[index_object])
  
              real_description_clusters.append(real_description)
  
              if len(real_description) > noise_size:
                  object_colored_clusters.append(real_description)
  
      print(
          "Draw allocated object segments (back mask representation)..."
      )
      draw_image_mask_segments(source, object_colored_clusters)
  
      print(
          "Draw allocated object segments (color segment representation)..."
      )
      draw_image_color_segments(source, object_colored_clusters)
  
imports: from math import floor
  from PIL import Image
  from pyclustering.utils import draw_image_mask_segments, draw_image_color_segments, read_image
  from pyclustering.samples.definitions import IMAGE_SIMPLE_SAMPLES, IMAGE_MAP_SAMPLES, IMAGE_REAL_SAMPLES
  from pyclustering.cluster.dbscan import dbscan
label_desc: Use image node_id 1 for calling a global function with example usage: template_segmentation_image(source, color_radius, color_neighbors, object_radius, object_neighbors, noise_size) without return types