code: def template_segmentation_image(
      image_file, parameters, steps, time, ccore_flag=True
  ):
      image = read_image(image_file)
      stimulus = rgb2gray(image)
  
      for pixel_index in range(len(stimulus)):
          if stimulus[pixel_index] < 235:
              stimulus[pixel_index] = 1
          else:
              stimulus[pixel_index] = 0
  
      if parameters is None:
          parameters = legion_parameters()
  
      net = legion_network(
          len(stimulus),
          parameters,
          conn_type.GRID_FOUR,
          ccore=ccore_flag,
      )
      output_dynamic = net.simulate(steps, time, stimulus)
  
      ensembles = output_dynamic.allocate_sync_ensembles()
  
      draw_image_mask_segments(image_file, ensembles)
      # draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)", separate = ensembles);
  
      # just for checking correctness of results - let's use classical algorithm
      dbscan_instance = dbscan(image, 3, 4, True)
      dbscan_instance.process()
      trustable_clusters = dbscan_instance.get_clusters()
  
      draw_dynamics(
          output_dynamic.time,
          output_dynamic.output,
          x_title="Time",
          y_title="x(t)",
          separate=trustable_clusters,
      )
  
file_path: pyclustering/pyclustering/nnet/examples/legion_segmentation.py
imports: from PIL import Image
  from pyclustering.utils import draw_dynamics
  from pyclustering.utils import read_image, rgb2gray, draw_image_mask_segments
  from pyclustering.nnet.legion import legion_network, legion_parameters
  from pyclustering.nnet import *
  from pyclustering.samples.definitions import IMAGE_SIMPLE_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(image_file, parameters, steps, time, ccore_flag) without return types