code: def boundary_difference_linear(graph, xxx_todo_changeme2):
      r"""
      Boundary term processing adjacent voxels difference value using a linear relationship.
  
      An implementation of a regional term, suitable to be used with the
      `~medpy.graphcut.generate.graph_from_voxels` function.
  
      Finds all edges between all neighbours of the image and uses their normalized
      difference in intensity values as edge weight.
  
      The weights are linearly normalized using the maximum possible intensity difference
      of the image. Formally, this value is computed as:
  
      .. math::
  
          \sigma = |max I - \min I|
  
      , where :math:`\min I` constitutes the lowest intensity value in the image, while
      :math:`\max I` constitutes the highest.
  
      The weights between two neighbouring voxels :math:`(p, q)` is then computed as:
  
      .. math::
  
          w(p,q) = 1 - \frac{|I_p - I_q|}{\sigma} + \epsilon
  
      , where :math:`\epsilon` is a infinitively small number and for which
      :math:`w(p, q) \in (0, 1]` holds true.
  
      When the created edge weights should be weighted according to the slice distance,
      provide the list of slice thicknesses via the ``spacing`` parameter. Then all weights
      computed for the corresponding direction are divided by the respective slice
      thickness. Set this parameter to `False` for equally weighted edges.
  
      Parameters
      ----------
      graph : GCGraph
          The graph to add the weights to.
      original_image : ndarray
          The original image.
      spacing : sequence of float or False
          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.
  
      Notes
      -----
      This function requires the original image to be passed along. That means that
      `~medpy.graphcut.generate.graph_from_voxels` has to be called with ``boundary_term_args`` set to the
      original image.
      """
      (original_image, spacing) = xxx_todo_changeme2
      original_image = scipy.asarray(original_image)
  
      # compute maximum (possible) intensity difference
      max_intensity_difference = float(
          abs(original_image.max() - original_image.min())
      )
  
      def boundary_term_linear(intensities):
          """
          Implementation of a linear boundary term computation over an array.
          """
          # normalize the intensity distances to the interval (0, 1]
          intensities /= max_intensity_difference
          # difference_to_neighbour[difference_to_neighbour > 1] = 1 # this line should not be required, but might be due to rounding errors
          intensities = (
              1.0 - intensities
          )  # reverse weights such that high intensity difference lead to small weights and hence more likely to a cut at this edge
          intensities[
              intensities == 0.0
          ] = sys.float_info.min  # required to avoid zero values
          return intensities
  
      __skeleton_difference(
          graph, original_image, boundary_term_linear, spacing
      )
  
file_path: medpy/medpy/graphcut/energy_voxel.py
imports: import sys
  import numpy
  import scipy
  import math
label_desc: Use image node_id 3 for calling a global function with example usage: boundary_difference_linear(graph, xxx_todo_changeme2) and returns: intensities