code: def graphcut_split(
      graphcut_function,
      regions,
      gradient,
      foreground,
      background,
      minimal_edge_length=100,
      overlap=10,
      processes=None,
  ):
      """
      Executes a graph cut by splitting the original volume into a number of sub-volumes of
      a minimal edge length. These are then processed in subprocesses.
  
      This can be significantly faster than the traditional graph cuts, but should be
      used with, as it can lead to different results. To minimize this effect, the overlap
      parameter allows control over how much the respective sub-volumes should overlap.
  
      Parameters
      ----------
      graphcut_function : function
          The graph cut to use (e.g. `graphcut_stawiaski`).
      regions : ndarray
          The regions image / label map.
      gradient : ndarray
          The gradient image.
      foreground : ndarray
          The foreground markers.
      background : ndarray
          The background markers.
      minimal_edge_length : integer
          The minimal edge length of the sub-volumes in voxels.
      overlap : integer
          The overlap (in voxels) between the generated sub-volumes.
      processes : integer or None
          The number of processes to run simultaneously, if not supplied, will be the same
          as the number of processors.
  
      Returns
      -------
      segmentation : ndarray
          The graph-cut segmentation result as boolean array.
      """
      # initialize logger
      logger = Logger.getInstance()
  
      # ensure that input images are scipy arrays
      img_region = scipy.asarray(regions)
      img_gradient = scipy.asarray(gradient)
      img_fg = scipy.asarray(foreground, dtype=scipy.bool_)
      img_bg = scipy.asarray(background, dtype=scipy.bool_)
  
      # ensure correctness of supplied images
      if not (
          img_region.shape
          == img_gradient.shape
          == img_fg.shape
          == img_bg.shape
      ):
          raise ArgumentError(
              "All supplied images must be of the same shape."
          )
  
      # check and eventually enhance input parameters
      if minimal_edge_length < 10:
          raise ArgumentError(
              "A minimal edge length smaller than 10 is not supported."
          )
      if overlap < 0:
          raise ArgumentError("A negative overlap is not supported.")
      if overlap >= minimal_edge_length:
          raise ArgumentError(
              "The overlap is not allowed to exceed the minimal edge length."
          )
  
      # compute how to split the volumes into sub-volumes i.e. determine step-size for each image dimension
      shape = list(img_region.shape)
      steps = [x // minimal_edge_length for x in shape]
      steps = [
          1 if 0 == x else x for x in steps
      ]  # replace zeros by ones
      stepsizes = [math.ceil(x / y) for x, y in zip(shape, steps)]
      logger.debug(
          "Using a minimal edge length of {}, a sub-volume size of {} was determined from the shape {}, which means {} sub-volumes.".format(
              minimal_edge_length,
              stepsizes,
              shape,
              reduce(lambda x, y: x * y, steps),
          )
      )
  
      # control step-sizes to definitely cover the whole image
      covered_shape = [x * y for x, y in zip(steps, stepsizes)]
      for c, o in zip(covered_shape, shape):
          if c < o:
              raise Exception(
                  "The computed sub-volumes do not cover the complete image!"
              )
  
      # iterate over the steps and extract subvolumes according to the stepsizes
      slicer_steps = [
          list(range(0, int(step * stepsize), int(stepsize)))
          for step, stepsize in zip(steps, stepsizes)
      ]
      slicers = [
          [
              slice(_from, _from + _offset + overlap)
              for _from, _offset in zip(slicer_step, stepsizes)
          ]
          for slicer_step in itertools.product(*slicer_steps)
      ]
      subvolumes_input = [
          (
              img_region[slicer],
              img_gradient[slicer],
              img_fg[slicer],
              img_bg[slicer],
          )
          for slicer in slicers
      ]
  
      # execute the graph cuts and collect results
      subvolumes_output = graphcut_subprocesses(
          graphcut_function, subvolumes_input, processes
      )
  
      # put back data together
      img_result = scipy.zeros(img_region.shape, dtype=scipy.bool_)
      for slicer, subvolume in zip(slicers, subvolumes_output):
          sslicer_antioverlap = [slice(None)] * img_result.ndim
  
          # treat overlap area using logical-and (&)
          for dim in range(img_result.ndim):
              if 0 == slicer[dim].start:
                  continue
              sslicer_antioverlap[dim] = slice(overlap, None)
              sslicer_overlap = [slice(None)] * img_result.ndim
              sslicer_overlap[dim] = slice(0, overlap)
              img_result[slicer][sslicer_overlap] = scipy.logical_and(
                  img_result[slicer][sslicer_overlap],
                  subvolume[sslicer_overlap],
              )
  
          # treat remainder through assignment
          img_result[slicer][sslicer_antioverlap] = subvolume[
              sslicer_antioverlap
          ]
  
      return img_result.astype(scipy.bool_)
  
file_path: medpy/medpy/graphcut/wrapper.py
imports: import multiprocessing
  import itertools
  import math
  import scipy
  from .energy_label import boundary_stawiaski
  from .generate import graph_from_labels
  from ..core.exceptions import ArgumentError
  from ..core.logger import Logger
  from ..filter import relabel, relabel_map
label_desc: Use image node_id 2 for calling a global function with example usage: graphcut_split(graphcut_function, regions, gradient, foreground, background, minimal_edge_length, overlap, processes) and returns: img_result