code: def convert_image_to(
      read_path, extension: str = "jpg", grayscale: bool = False
  ):
      """
      Reads image from path and saves as given extension.
      """
      image = cv2.imread(read_path)
      pre, ext = os.path.splitext(read_path)
      if grayscale:
          image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
          pre = pre + "_gray"
      save_path = pre + "." + extension
      cv2.imwrite(save_path, image)
  
imports: import copy
  import os
  import random
  import time
  from typing import List, Optional, Union
  import cv2
  import numpy
  import requests
  from PIL import Image
  from sahi.utils.file import Path
label_desc: Use image node_id 2 for calling a global function with example usage: convert_image_to(read_path, extension, grayscale) without return types