code: def convert_coordinates_to_bbox(
      coordinates: np.ndarray,
      input_format: BBoxFormatType = "YXYX",
      img_shape=None,
      normalize: bool = True,
  ) -> BBox:
      """Converts four coordinates to a BBox using the YXYX format.
  
      Args:
        coordinates: np.array with the four coordinates expressing a bounding box.
        input_format: the format of the coordinates, e.g. 'XYXY' or 'XYWH'. See
          https://keras.io/api/keras_cv/bounding_box/formats/ for a list of popular
            bounding boxes formats.
        img_shape: 2-dimensions np.ndarray or iterable with (img_heigth, img_width).
        normalize: Whether to normalize the axes. If True, it will normalize the x
          coordinates using the image width, and the y coordinates using the image
          height. Defaults to True.
  
      Returns:
        A BBox in the correct format.
  
      Raises:
        ValueError if input_format is unknown, or if the
      """
      if len(coordinates) != 4:
          raise ValueError(
              f"Expected 4 coordinates, got {coordinates}."
          )
  
      coordinates = coordinates.astype(np.float64)
  
      try:
          if isinstance(input_format, str):
              input_format = BBoxFormat(input_format)
      except ValueError as e:
          raise ValueError(
              f"Unsupported bbox format: {format}. Currently supported bounding box"
              f" formats are: {[format.value for format in BBoxFormat]}"
          ) from e
  
      if input_format == BBoxFormat.YXYX:
          bbox = BBox(
              ymin=coordinates[0],
              xmin=coordinates[1],
              ymax=coordinates[2],
              xmax=coordinates[3],
          )
      elif input_format == BBoxFormat.XYXY:
          bbox = BBox(
              ymin=coordinates[1],
              xmin=coordinates[0],
              ymax=coordinates[3],
              xmax=coordinates[2],
          )
      elif input_format == BBoxFormat.XYWH:
          x, y, width, height = coordinates
          bbox = BBox(
              ymin=y, xmin=x, ymax=(y + height), xmax=(x + width)
          )
      else:
          raise ValueError(
              f"Unsupported bbox format: {format}. Currently supported bounding box"
              f" formats are: {[format.value for format in BBoxFormat]}"
          )
  
      if normalize:
          bbox = normalize_bbox(bbox, img_shape)
  
      return bbox
  
file_path: datasets/tensorflow_datasets/core/features/bounding_boxes_utils.py
imports: import collections
  from collections.abc import Sequence
  import enum
  from typing import Union
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: convert_coordinates_to_bbox(coordinates, input_format, img_shape, normalize) and returns: bbox