code: def default_preprocess(
      data,
      image_shape: Optional[Tuple[int, int]] = None,
      rescale: bool = True,
      expand_dims: bool = True,
  ) -> np.ndarray:
      from chitra.image import Chitra
  
      """
      Supports image resize, rescaling and dimension expansion along 0th index
      Args:
          data: Image File buffer or numpy array
          image_shape: Target image size
          rescale: If true then image will be rescaled as [-1, 1]
          expand_dims:
  
      Returns:
          preprocessed numpy array image
      """
      if isinstance(data, str):
          image = Image.open(BytesIO(data)).convert("RGB")
      elif isinstance(data, np.ndarray):
          image = Chitra(data).image
      else:
          raise UserWarning(
              f"preprocessing not implemented for this data type -> {data}"
          )
  
      if image_shape:
          image = image.resize(image_shape)
  
      image = np.asarray(image).astype(np.float32)
      if rescale:
          image = image / 127.5 - 1.0
      if expand_dims:
          image = np.expand_dims(image, 0)
      return image
  
file_path: chitra/chitra/data_processing/default/vision.py
imports: from io import BytesIO
  from typing import List, Optional, Tuple
  import numpy
  from PIL import Image
  from ..processor import DataProcessor
label_desc: Use image node_id 1 for calling a global function with example usage: default_preprocess(data, image_shape, rescale, expand_dims) and returns: image