code: def generate_random_anomaly_image(
      image_width: int,
      image_height: int,
      shapes: List[str] = ["triangle", "rectangle"],
      max_shapes: Optional[int] = 5,
      generate_mask: Optional[bool] = False,
  ) -> Dict:
      """Generate a random image with the corresponding shape entities.
  
      Args:
          image_width (int): Width of the image
          image_height (int): Height of the image
          shapes (List[str]): List of shapes to draw in the image. Make sure these are different from `anomalous_shapes`
          max_shapes (int): Maximum shapes of a kind in the image. Defaults to 5.
          max_size (Optional[int], optional): Maximum size of the test shapes. Defaults to 10.
          generate_mask (bool): Toggle between train/test split. Train images are restricted to first quadrant.
                      Also generates the mask for the image. Defaults to False.
      Returns:
          Tuple: image if `train` is False. Else return image, mask
      """
  
      image: np.ndarray = np.full(
          (image_height, image_width, 3), 255, dtype=np.uint8
      )
  
      input_region = [0, 0, image_width - 1, image_height - 1]
  
      for shape in shapes:
          shape_image = random_shapes(
              input_region,
              (image_height, image_width),
              max_shapes=max_shapes,
              shape=shape,
          )
          image = np.minimum(image, shape_image)  # since white is 255
  
      result = {"image": image}
  
      if generate_mask:
          mask = np.zeros((image_height, image_width), dtype=np.uint8)
          # if color exists in any channel turn the mask bit white.
          # not sure if there is a better way to do this.
          mask[image[..., 0] < 255] = 255
          mask[image[..., 1] < 255] = 255
          mask[image[..., 2] < 255] = 255
          result["mask"] = mask
  
      return result
  
imports: import os
  import shutil
  from contextlib import ContextDecorator
  from functools import wraps
  from pathlib import Path
  from tempfile import mkdtemp
  from typing import Dict, List, Optional, Union
  import numpy
  from skimage.io import imsave
  from .shapes import random_shapes
label_desc: Use image node_id 2 for calling a global function with example usage: generate_random_anomaly_image(image_width, image_height, shapes, max_shapes, generate_mask) and returns: result