code: def __skeleton_base(
      graph, image, boundary_term, neighbourhood_function, spacing
  ):
      """
      Base of the skeleton for voxel based boundary term calculation.
  
      This function holds the low level procedures shared by nearly all boundary terms.
  
      @param graph An initialized graph.GCGraph object
      @type graph.GCGraph
      @param image The image containing the voxel intensity values
      @type image numpy.ndarray
      @param boundary_term A function to compute the boundary term over an array of
                             absolute intensity differences
      @type boundary_term function
      @param neighbourhood_function A function that takes two arrays of neighbouring pixels
                                    and computes an intensity term from them that is
                                    returned as a single array of the same shape
      @type neighbourhood_function function
      @param spacing A sequence containing the slice spacing used for weighting the
                     computed neighbourhood weight value for different dimensions. If
                     False, no distance based weighting of the graph edges is performed.
      @param spacing sequence | False
      """
      image = scipy.asarray(image)
      image = image.astype(scipy.float_)
  
      # iterate over the image dimensions and for each create the appropriate edges and compute the associated weights
      for dim in range(image.ndim):
          # construct slice-objects for the current dimension
          slices_exclude_last = [slice(None)] * image.ndim
          slices_exclude_last[dim] = slice(-1)
          slices_exclude_first = [slice(None)] * image.ndim
          slices_exclude_first[dim] = slice(1, None)
          # compute difference between all layers in the current dimensions direction
          neighbourhood_intensity_term = neighbourhood_function(
              image[slices_exclude_last], image[slices_exclude_first]
          )
          # apply boundary term
          neighbourhood_intensity_term = boundary_term(
              neighbourhood_intensity_term
          )
          # compute key offset for relative key difference
          offset_key = [1 if i == dim else 0 for i in range(image.ndim)]
          offset = __flatten_index(offset_key, image.shape)
          # generate index offset function for index dependent offset
          idx_offset_divider = (image.shape[dim] - 1) * offset
          idx_offset = lambda x: int(x / idx_offset_divider) * offset
  
          # weight the computed distanced in dimension dim by the corresponding slice spacing provided
          if spacing:
              neighbourhood_intensity_term /= spacing[dim]
  
          for key, value in enumerate(
              neighbourhood_intensity_term.ravel()
          ):
              # apply index dependent offset
              key += idx_offset(key)
              # add edges and set the weight
              graph.set_nweight(key, key + offset, value, value)
  
file_path: medpy/medpy/graphcut/energy_voxel.py
imports: import sys
  import numpy
  import scipy
  import math
label_desc: Use image node_id 12 for calling a global function with example usage: __skeleton_base(graph, image, boundary_term, neighbourhood_function, spacing) without return types