code: def main():
      # parse cmd arguments
      parser = getParser()
      parser.parse_args()
      args = getArguments(parser)
  
      # prepare logger
      logger = Logger.getInstance()
      if args.debug:
          logger.setLevel(logging.DEBUG)
      elif args.verbose:
          logger.setLevel(logging.INFO)
  
      # check if output image exists
      if not args.force:
          if os.path.exists(args.output):
              logger.warning(
                  "The output image {} already exists. Exiting.".format(
                      args.output
                  )
              )
              exit(-1)
  
      # select boundary term
      if args.boundary == "stawiaski":
          boundary_term = graphcut.energy_label.boundary_stawiaski
          logger.info("Selected boundary term: stawiaski")
      else:
          boundary_term = (
              graphcut.energy_label.boundary_difference_of_means
          )
          logger.info("Selected boundary term: difference of means")
  
      # load input images
      region_image_data, reference_header = load(args.region)
      badditional_image_data, _ = load(args.badditional)
      markers_image_data, _ = load(args.markers)
  
      # split marker image into fg and bg images
      fgmarkers_image_data, bgmarkers_image_data = split_marker(
          markers_image_data
      )
  
      # check if all images dimensions are the same
      if not (
          badditional_image_data.shape
          == region_image_data.shape
          == fgmarkers_image_data.shape
          == bgmarkers_image_data.shape
      ):
          logger.critical(
              "Not all of the supplied images are of the same shape."
          )
          raise ArgumentError(
              "Not all of the supplied images are of the same shape."
          )
  
      # recompute the label ids to start from id = 1
      logger.info("Relabel input image...")
      region_image_data = filter.relabel(region_image_data)
  
      # generate graph
      logger.info("Preparing graph...")
      gcgraph = graphcut.graph_from_labels(
          region_image_data,
          fgmarkers_image_data,
          bgmarkers_image_data,
          boundary_term=boundary_term,
          boundary_term_args=(badditional_image_data),
      )  # second is directedness of graph , 0)
  
      logger.info(
          "Removing images that are not longer required from memory..."
      )
      del fgmarkers_image_data
      del bgmarkers_image_data
      del badditional_image_data
  
      # execute min-cut
      logger.info("Executing min-cut...")
      maxflow = gcgraph.maxflow()
      logger.debug("Maxflow is {}".format(maxflow))
  
      # apply results to the region image
      logger.info("Applying results...")
      mapping = [
          0
      ]  # no regions with id 1 exists in mapping, entry used as padding
      mapping.extend(
          [
              0
              if gcgraph.termtype.SINK
              == gcgraph.what_segment(int(x) - 1)
              else 1
              for x in scipy.unique(region_image_data)
          ]
      )
      region_image_data = filter.relabel_map(region_image_data, mapping)
  
      # save resulting mask
      save(
          region_image_data.astype(scipy.bool_),
          args.output,
          reference_header,
          args.force,
      )
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_graphcut_label.py
imports: from argparse import RawTextHelpFormatter
  import argparse
  import logging
  import os
  import scipy
  from medpy.core import ArgumentError, Logger
  from medpy.io import load, save
  from medpy import graphcut
  from medpy import filter
  from medpy.graphcut.wrapper import split_marker
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types