code: def to_ndarray(t_img: Image, dtype=None) -> np.ndarray:
      """
      Convert a towhee.types.Image into ndarray.
  
      The mode is same as `towhee_img`, use `towhee_img.mode` to get the information.
  
      Args:
          t_img (`towhee.types.Image`):
              A towhee image.
          dtype:
              The type of the narray.
  
      Returns:
          (`np.ndarray`)
              The ndarray of the image, the mode is same as the `towhee_img`.
      """
      shape = t_img.shape
      dtype = np.uint8 if not dtype else dtype
  
      arr = np.ndarray(shape, dtype, t_img)
  
      return arr
  
file_path: towhee/towhee/utils/ndarray_utils.py
imports: import glob
  from pathlib import Path, PosixPath
  from typing import Union
  import numpy
  from io import BytesIO
  from zipfile import ZipFile
  from urllib.request import urlopen
  from towhee.types import Image
  from towhee.utils.repo_normalize import RepoNormalize
  from towhee.utils.cv2_utils import cv2
label_desc: Use image node_id 4 for calling a global function with example usage: to_ndarray(t_img, dtype) and returns: arr