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 (as image, header pairs)
      images = []
      headers = []
      for image_name in args.images:
          i, h = load(image_name)
          images.append(i)
          headers.append(h)
  
      # loading binary foreground masks if supplied, else create masks from threshold value
      if args.masks:
          masks = [
              load(mask_name)[0].astype(numpy.bool_)
              for mask_name in args.masks
          ]
      else:
          masks = [i > args.threshold for i in images]
  
      # if in application mode, load the supplied model and apply it to the images
      if args.lmodel:
          logger.info("Loading the model and transforming images...")
          with open(args.lmodel, "r") as f:
              trained_model = pickle.load(f)
              if not isinstance(
                  trained_model, IntensityRangeStandardization
              ):
                  raise ArgumentError(
                      "{} does not seem to be a valid pickled instance of an IntensityRangeStandardization object".format(
                          args.lmodel
                      )
                  )
              transformed_images = [
                  trained_model.transform(
                      i[m], surpress_mapping_check=args.ignore
                  )
                  for i, m in zip(images, masks)
              ]
  
      # in in training mode, train the model, apply it to the images and save it
      else:
          logger.info("Training the average intensity model...")
          irs = IntensityRangeStandardization()
          trained_model, transformed_images = irs.train_transform(
              [i[m] for i, m in zip(images, masks)],
              surpress_mapping_check=args.ignore,
          )
          logger.info(
              "Saving the trained model as {}...".format(args.smodel)
          )
          with open(args.smodel, "wb") as f:
              pickle.dump(trained_model, f)
  
      # save the transformed images
      if args.simages:
          logger.info(
              "Saving intensity transformed images to {}...".format(
                  args.simages
              )
          )
          for ti, i, m, h, image_name in zip(
              transformed_images, images, masks, headers, args.images
          ):
              i[m] = ti
              save(
                  i,
                  "{}/{}".format(
                      args.simages, image_name.split("/")[-1]
                  ),
                  h,
                  args.force,
              )
  
      logger.info("Terminated.")
  
file_path: medpy/bin/medpy_intensity_range_standardization.py
imports: import os
  import pickle
  import argparse
  import logging
  import numpy
  from medpy.core import Logger
  from medpy.core.exceptions import ArgumentError
  from medpy.io import load, save
  from medpy.utilities.argparseu import sequenceOfIntegersGeAscendingStrict
  from medpy.filter import IntensityRangeStandardization
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types