code: def main(args=None):
      if args is None:
          args = sys.argv[1:]
      parser = argparse.ArgumentParser(
          description="Crop images to a region of interest",
          epilog="If a start or stop value is omitted, the start or end of the axis is assumed.",
      )
      parser.add_argument(
          "--version", action="version", version=nb.__version__
      )
      parser.add_argument(
          "-i",
          metavar="I1:I2[:-1]",
          help="Start/stop [flip] along first axis (0-indexed)",
      )
      parser.add_argument(
          "-j",
          metavar="J1:J2[:-1]",
          help="Start/stop [flip] along second axis (0-indexed)",
      )
      parser.add_argument(
          "-k",
          metavar="K1:K2[:-1]",
          help="Start/stop [flip] along third axis (0-indexed)",
      )
      parser.add_argument(
          "-t",
          metavar="T1:T2",
          help="Start/stop along fourth axis (0-indexed)",
      )
      parser.add_argument("in_file", help="Image file to crop")
      parser.add_argument("out_file", help="Output file name")
  
      opts = parser.parse_args(args=sanitize(args))
  
      try:
          islice = parse_slice(opts.i)
          jslice = parse_slice(opts.j)
          kslice = parse_slice(opts.k)
          tslice = parse_slice(opts.t, allow_step=False)
      except ValueError as err:
          print(
              f"Could not parse input arguments. Reason follows.\n{err}"
          )
          return 1
  
      kwargs = {}
      if os.path.realpath(opts.in_file) == os.path.realpath(
          opts.out_file
      ):
          kwargs["mmap"] = False
      img = nb.load(opts.in_file, **kwargs)
  
      slicers = (islice, jslice, kslice, tslice)[: img.ndim]
      expected_shape = nb.fileslice.predict_shape(slicers, img.shape)
      if any(dim == 0 for dim in expected_shape):
          print(
              f"Cannot take zero-length slices. Predicted shape {expected_shape}."
          )
          return 1
  
      try:
          sliced_img = lossless_slice(img, slicers)
      except Exception:
          print("Could not slice image. Full traceback follows.")
          raise
      nb.save(sliced_img, opts.out_file)
      return 0
  
file_path: nibabel/nibabel/cmdline/roi.py
imports: import argparse
  import os
  import sys
  import nibabel
label_desc: Use image node_id 4 for calling a global function with example usage: main(args) and returns: int, int, int