code: def bbox_affine(
      bbox: BoxInternalType,
      matrix: skimage.transform.ProjectiveTransform,
      rotate_method: str,
      rows: int,
      cols: int,
      output_shape: Sequence[int],
  ) -> BoxInternalType:
      if _is_identity_matrix(matrix):
          return bbox
      x_min, y_min, x_max, y_max = denormalize_bbox(bbox, rows, cols)[
          :4
      ]
      if rotate_method == "largest_box":
          points = np.array(
              [
                  [x_min, y_min],
                  [x_max, y_min],
                  [x_max, y_max],
                  [x_min, y_max],
              ]
          )
      elif rotate_method == "ellipse":
          w = (x_max - x_min) / 2
          h = (y_max - y_min) / 2
          data = np.arange(0, 360, dtype=np.float32)
          x = w * np.sin(np.radians(data)) + (w + x_min - 0.5)
          y = h * np.cos(np.radians(data)) + (h + y_min - 0.5)
          points = np.hstack([x.reshape(-1, 1), y.reshape(-1, 1)])
      else:
          raise ValueError(
              f"Method {rotate_method} is not a valid rotation method."
          )
      points = skimage.transform.matrix_transform(points, matrix.params)
      x_min = np.min(points[:, 0])
      x_max = np.max(points[:, 0])
      y_min = np.min(points[:, 1])
      y_max = np.max(points[:, 1])
  
      return normalize_bbox(
          (x_min, y_min, x_max, y_max), output_shape[0], output_shape[1]
      )
  
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import skimage.transform
  from scipy.ndimage import gaussian_filter
  from albumentations.augmentations.utils import _maybe_process_in_chunks, angle_2pi_range, clipped, preserve_channel_dim, preserve_shape
  from ...None import random_utils
  from ...core.bbox_utils import denormalize_bbox, normalize_bbox
  from ...core.transforms_interface import BoxInternalType, FillValueType, ImageColorType, KeypointInternalType
label_desc: Use image node_id 24 for calling a global function with example usage: bbox_affine(bbox, matrix, rotate_method, rows, cols, output_shape) and returns: normalize_bbox, bbox