code: def template_image_segmentation(
      image_file, steps, time, dynamic_file_prefix
  ):
      image = read_image(image_file)
      stimulus = rgb2gray(image)
  
      params = hhn_parameters()
      params.deltah = 650
      params.w1 = 0.1
      params.w2 = 9.0
      params.w3 = 5.0
      params.threshold = -10
  
      stimulus = [255.0 - pixel for pixel in stimulus]
      divider = max(stimulus) / 50.0
      stimulus = [int(pixel / divider) for pixel in stimulus]
  
      t, dyn_peripheral, dyn_central = None, None, None
  
      if (
          not os.path.exists(dynamic_file_prefix + "dynamic_time.txt")
          or not os.path.exists(
              dynamic_file_prefix + "dynamic_peripheral.txt"
          )
          or not os.path.exists(
              dynamic_file_prefix + "dynamic_dyn_central.txt"
          )
      ):
          print(
              "File with output dynamic is not found - simulation will be performed - it may take some time, be patient."
          )
  
          net = hhn_network(len(stimulus), stimulus, params, ccore=True)
  
          (t, dyn_peripheral, dyn_central) = net.simulate(steps, time)
  
          print("Store dynamic to save time for simulation next time.")
  
          with open(
              dynamic_file_prefix + "dynamic_time.txt", "wb"
          ) as file_descriptor:
              pickle.dump(t, file_descriptor)
  
          with open(
              dynamic_file_prefix + "dynamic_peripheral.txt", "wb"
          ) as file_descriptor:
              pickle.dump(dyn_peripheral, file_descriptor)
  
          with open(
              dynamic_file_prefix + "dynamic_dyn_central.txt", "wb"
          ) as file_descriptor:
              pickle.dump(dyn_central, file_descriptor)
      else:
          print("Load output dynamic from file.")
  
          with open(
              dynamic_file_prefix + "dynamic_time.txt", "rb"
          ) as file_descriptor:
              t = pickle.load(file_descriptor)
  
          with open(
              dynamic_file_prefix + "dynamic_peripheral.txt", "rb"
          ) as file_descriptor:
              dyn_peripheral = pickle.load(file_descriptor)
  
          with open(
              dynamic_file_prefix + "dynamic_dyn_central.txt", "rb"
          ) as file_descriptor:
              dyn_central = pickle.load(file_descriptor)
  
      animate_segmentation(t, dyn_peripheral, image_file, 200)
  
      # just for checking correctness of results - let's use classical algorithm
      if False:
          dbscan_instance = dbscan(image, 3, 4, True)
          dbscan_instance.process()
          trustable_clusters = dbscan_instance.get_clusters()
  
          amount_canvases = len(trustable_clusters) + 2
          visualizer = dynamic_visualizer(
              amount_canvases,
              x_title="Time",
              y_title="V",
              y_labels=False,
          )
          visualizer.append_dynamics(
              t, dyn_peripheral, 0, trustable_clusters
          )
          visualizer.append_dynamics(
              t, dyn_central, amount_canvases - 2, True
          )
          visualizer.show()
  
file_path: pyclustering/pyclustering/nnet/examples/hhn_segmentation.py
imports: import numpy
  import os.path
  import pickle
  from PIL import Image
  import matplotlib.pyplot
  import matplotlib.animation
  from pyclustering.cluster.dbscan import dbscan
  from pyclustering.nnet.dynamic_visualizer import dynamic_visualizer
  from pyclustering.nnet.hhn import hhn_network, hhn_parameters
  from pyclustering.samples.definitions import IMAGE_SIMPLE_SAMPLES
  from pyclustering.utils import read_image, rgb2gray
label_desc: Use image node_id 2 for calling a global function with example usage: template_image_segmentation(image_file, steps, time, dynamic_file_prefix) without return types