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)
  
      # loading input images
      b0img, b0hdr = load(args.b0image)
      bximg, bxhdr = load(args.bximage)
  
      # convert to float
      b0img = b0img.astype(float)
      bximg = bximg.astype(float)
  
      # check if image are compatible
      if not b0img.shape == bximg.shape:
          raise ArgumentError(
              "The input images shapes differ i.e. {} != {}.".format(
                  b0img.shape, bximg.shape
              )
          )
      if not header.get_pixel_spacing(
          b0hdr
      ) == header.get_pixel_spacing(bxhdr):
          raise ArgumentError(
              "The input images voxel spacing differs i.e. {} != {}.".format(
                  header.get_pixel_spacing(b0hdr),
                  header.get_pixel_spacing(bxhdr),
              )
          )
  
      # check if supplied threshold value as well as the b value is above 0
      if args.threshold is not None and not args.threshold >= 0:
          raise ArgumentError(
              "The supplied threshold value must be greater than 0, otherwise a division through 0 might occur."
          )
      if not args.b > 0:
          raise ArgumentError(
              "The supplied b-value must be greater than 0."
          )
  
      # compute threshold value if not supplied
      if args.threshold is None:
          b0thr = (
              otsu(b0img, 32) / 4.0
          )  # divide by 4 to decrease impact
          bxthr = otsu(bximg, 32) / 4.0
          if 0 >= b0thr:
              raise ArgumentError(
                  "The supplied b0image seems to contain negative values."
              )
          if 0 >= bxthr:
              raise ArgumentError(
                  "The supplied bximage seems to contain negative values."
              )
      else:
          b0thr = bxthr = args.threshold
  
      logger.debug(
          "thresholds={}/{}, b-value={}".format(b0thr, bxthr, args.b)
      )
  
      # threshold b0 + bx DW image to obtain a mask
      # b0 mask avoid division through 0, bx mask avoids a zero in the ln(x) computation
      mask = binary_fill_holes(b0img > b0thr) & binary_fill_holes(
          bximg > bxthr
      )
  
      # perform a number of binary morphology steps to select the brain only
      mask = binary_erosion(mask, iterations=1)
      mask = largest_connected_component(mask)
      mask = binary_dilation(mask, iterations=1)
  
      logger.debug(
          "excluding {} of {} voxels from the computation and setting them to zero".format(
              numpy.count_nonzero(mask), numpy.prod(mask.shape)
          )
      )
  
      # compute the ADC
      adc = numpy.zeros(b0img.shape, b0img.dtype)
      adc[mask] = -1.0 * args.b * numpy.log(bximg[mask] / b0img[mask])
      adc[adc < 0] = 0
  
      # saving the resulting image
      save(adc, args.output, b0hdr, args.force)
  
file_path: medpy/bin/medpy_apparent_diffusion_coefficient.py
imports: import argparse
  import logging
  import numpy
  from scipy.ndimage import binary_fill_holes, binary_dilation, binary_erosion
  from medpy.core import Logger
  from medpy.io import load, save, header
  from medpy.filter import otsu
  from medpy.core.exceptions import ArgumentError
  from medpy.filter.binary import largest_connected_component
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types