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 (will also be performed before saving, but as the watershed might be very time intensity, a initial check can save frustration)
      if not args.force:
          if os.path.exists(args.output):
              raise ArgumentError(
                  "The output image {} already exists.".format(
                      args.output
                  )
              )
  
      # loading images
      data_input, header_input = load(args.input)
      if args.mask:
          mask = load(args.mask)[0].astype(numpy.bool_)
      else:
          mask = None
  
      # extract local minima and convert to markers
      logger.info(
          "Extract local minima with minimum distance of {}...".format(
              args.mindist
          )
      )
      lm, _ = local_minima(data_input, args.mindist)
      lm_indices = tuple([numpy.asarray(x) for x in lm.T])
      minima_labels = numpy.zeros(data_input.shape, dtype=numpy.uint64)
      minima_labels[lm_indices] = 1
      if not None == mask:
          minima_labels[~mask] = 0
      minima_labels, _ = label(minima_labels)
  
      # apply the watershed
      logger.info("Watershedding...")
      data_output = watershed(data_input, minima_labels, mask=mask)
  
      # save file
      save(data_output, args.output, header_input, args.force)
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_watershed.py
imports: import argparse
  import logging
  import os
  import numpy
  from scipy.ndimage import label
  from skimage.morphology import watershed
  from medpy.io import load, save
  from medpy.core import Logger, ArgumentError
  from medpy.filter import local_minima
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types