code: def main():
      args = getArguments(getParser())
  
      # prepare logger
      logger = Logger.getInstance()
      if args.debug:
          logger.setLevel(logging.DEBUG)
      elif args.verbose:
          logger.setLevel(logging.INFO)
  
      # load input image
      data_input, header_input = load(args.input)
  
      # treat as binary
      data_input = data_input.astype(numpy.bool_)
  
      # check dimension argument
      if args.dimension and (
          not args.dimension >= 0
          or not args.dimension < data_input.ndim
      ):
          argparse.ArgumentError(
              args.dimension,
              "Invalid dimension of {} supplied. Image has only {} dimensions.".format(
                  args.dimension, data_input.ndim
              ),
          )
  
      # compute erosion and dilation steps
      erosions = int(math.ceil(args.width / 2.0))
      dilations = int(math.floor(args.width / 2.0))
      logger.debug(
          "Performing {} erosions and {} dilations to achieve a contour of width {}.".format(
              erosions, dilations, args.width
          )
      )
  
      # erode, dilate and compute contour
      if not args.dimension:
          eroded = (
              binary_erosion(data_input, iterations=erosions)
              if not 0 == erosions
              else data_input
          )
          dilated = (
              binary_dilation(data_input, iterations=dilations)
              if not 0 == dilations
              else data_input
          )
          data_output = dilated - eroded
      else:
          slicer = [slice(None)] * data_input.ndim
          bs_slicer = [slice(None)] * data_input.ndim
          data_output = numpy.zeros_like(data_input)
          for sl in range(data_input.shape[args.dimension]):
              slicer[args.dimension] = slice(sl, sl + 1)
              bs_slicer[args.dimension] = slice(1, 2)
              bs = generate_binary_structure(data_input.ndim, 1)
  
              eroded = (
                  binary_erosion(
                      data_input[slicer],
                      structure=bs[bs_slicer],
                      iterations=erosions,
                  )
                  if not 0 == erosions
                  else data_input[slicer]
              )
              dilated = (
                  binary_dilation(
                      data_input[slicer],
                      structure=bs[bs_slicer],
                      iterations=dilations,
                  )
                  if not 0 == dilations
                  else data_input[slicer]
              )
              data_output[slicer] = dilated - eroded
      logger.debug(
          "Contour image contains {} contour voxels.".format(
              numpy.count_nonzero(data_output)
          )
      )
  
      # save resulting volume
      save(data_output, args.output, header_input, args.force)
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_extract_contour.py
imports: import argparse
  import logging
  import math
  import numpy
  from scipy.ndimage import binary_erosion, binary_dilation, generate_binary_structure
  from medpy.core import Logger
  from medpy.io import load, save
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types