code: def ensure_image(
      image: t.Union[pilimage.Image, np.ndarray], copy: bool = True
  ) -> pilimage.Image:
      """Transform to `PIL.Image.Image` if possible.
  
      Parameters
      ----------
      image : Union[PIL.Image.Image, numpy.ndarray]
      copy : bool, default True
          if `image` is an instance of the `PIL.Image.Image` return
          it as it is or copy it.
  
      Returns
      -------
      `PIL.Image.Image`
      """
      if isinstance(image, pilimage.Image):
          return image.copy() if copy is True else image
      if isinstance(image, np.ndarray):
          image = image.squeeze().astype(np.uint8)
          if image.ndim == 3:
              return pilimage.fromarray(image)
          elif image.ndim == 2:
              return pilops.colorize(
                  pilimage.fromarray(image),
                  black="black",
                  white="white",
                  blackpoint=image.min(),
                  whitepoint=image.max(),
              )
          else:
              raise ValueError(
                  f"Do not know how to work with {image.ndim} dimensional images"
              )
      else:
          raise TypeError(
              f"cannot convert {type(image)} to the PIL.Image.Image"
          )
  
imports: import io
  import typing
  from numbers import Number
  from pathlib import Path
  import cv2
  import numpy
  import PIL.Image
  import PIL.ImageDraw
  import PIL.ImageOps
  import plotly.graph_objects
  from PIL import ImageColor, ImageFont
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.utils.html import imagetag
  from deepchecks.vision.vision_data import TaskType
  from deepchecks.vision.vision_data.utils import LabelMap
  from .detection_formatters import convert_bbox
label_desc: Use image node_id 2 for calling a global function with example usage: ensure_image(image, copy) and returns: unknown, pilimage, pilops