code: def augment(
      boxes,
      augmenter: imgaug.augmenters.meta.Augmenter,
      image=None,
      boxes_format="boxes",
      image_shape=None,
      area_threshold=0.5,
      min_area=None,
  ):
      """Augment an image and associated boxes together.
  
      Args:
          image: The image which we wish to apply the augmentation.
          boxes: The boxes that will be augmented together with the image
          boxes_format: The format for the boxes. See the `drawBoxes` function
              for an explanation on the options.
          image_shape: The shape of the input image if no image will be provided.
          area_threshold: Fraction of bounding box that we require to be
              in augmented image to include it.
          min_area: The minimum area for a character to be included.
      """
      if image is None and image_shape is None:
          raise ValueError(
              'One of "image" or "image_shape" must be provided.'
          )
      augmenter = augmenter.to_deterministic()
  
      if image is not None:
          image_augmented = augmenter(image=image)
          image_shape = image.shape[:2]
          image_augmented_shape = image_augmented.shape[:2]
      else:
          image_augmented = None
          (
              width_augmented,
              height_augmented,
          ) = augmenter.augment_keypoints(
              imgaug.KeypointsOnImage.from_xy_array(
                  xy=[[image_shape[1], image_shape[0]]],
                  shape=image_shape,
              )
          ).to_xy_array()[
              0
          ]
          image_augmented_shape = (height_augmented, width_augmented)
  
      def box_inside_image(box):
          area_before = cv2.contourArea(
              np.array(box, dtype="int32")[:, np.newaxis, :]
          )
          if area_before == 0:
              return False, box
          clipped = box.copy()
          clipped[:, 0] = clipped[:, 0].clip(
              0, image_augmented_shape[1]
          )
          clipped[:, 1] = clipped[:, 1].clip(
              0, image_augmented_shape[0]
          )
          area_after = cv2.contourArea(
              np.array(clipped, dtype="int32")[:, np.newaxis, :]
          )
          return ((area_after / area_before) >= area_threshold) and (
              min_area is None or area_after > min_area
          ), clipped
  
      def augment_box(box):
          return augmenter.augment_keypoints(
              imgaug.KeypointsOnImage.from_xy_array(
                  box, shape=image_shape
              )
          ).to_xy_array()
  
      if boxes_format == "boxes":
          boxes_augmented = [
              box
              for inside, box in [
                  box_inside_image(box)
                  for box in map(augment_box, boxes)
              ]
              if inside
          ]
      elif boxes_format == "lines":
          boxes_augmented = [
              [(augment_box(box), character) for box, character in line]
              for line in boxes
          ]
          boxes_augmented = [
              [
                  (box, character)
                  for (inside, box), character in [
                      (box_inside_image(box), character)
                      for box, character in line
                  ]
                  if inside
              ]
              for line in boxes_augmented
          ]
          # Sometimes all the characters in a line are removed.
          boxes_augmented = [line for line in boxes_augmented if line]
      elif boxes_format == "predictions":
          boxes_augmented = [
              (word, augment_box(box)) for word, box in boxes
          ]
          boxes_augmented = [
              (word, box)
              for word, (inside, box) in [
                  (word, box_inside_image(box))
                  for word, box in boxes_augmented
              ]
              if inside
          ]
      else:
          raise NotImplementedError(
              f"Unsupported boxes format: {boxes_format}"
          )
      return image_augmented, boxes_augmented
  
imports: import os
  import io
  import typing
  import hashlib
  import urllib.request
  import urllib.parse
  import cv2
  import imgaug
  import numpy
  import validators
  import typing_extensions
  import matplotlib.pyplot
  from shapely import geometry
  from scipy import spatial
label_desc: Use image node_id 9 for calling a global function with example usage: augment(boxes, augmenter, image, boxes_format, image_shape, area_threshold, min_area) and returns: image_augmented,  boxes_augmented, unknown,  clipped, augmenter, False,  box