def crop_pad_image(bbox_tight: "torch.Tensor", image: "torch.Tensor") -> tuple[
            "torch.Tensor",
            tuple["torch.Tensor", "torch.Tensor", "torch.Tensor", "torch.Tensor"],
            "torch.Tensor",
            "torch.Tensor",
        ]:
            """
            Around the bounding box, we define an extra context factor of 2, which we will crop from the original image.

            :param bbox_tight: Coordinates of bounding box [x1, y1, x2, y2].
            :param image: Frame to be cropped and padded.
            :return: Cropped and Padded image.
            """
            import math
            import torch

            pad_image_location = compute_crop_pad_image_location(bbox_tight, image)
            # roi_left = min(pad_image_location.x1, (image.shape[1] - 1))
            # roi_bottom = min(pad_image_location.y1, (image.shape[0] - 1))
            roi_left = torch.minimum(pad_image_location[0], torch.tensor(image.shape[1] - 1).to(self.device))
            roi_bottom = torch.minimum(pad_image_location[1], torch.tensor(image.shape[0] - 1).to(self.device))
            # roi_width = min(image.shape[1], max(1.0, math.ceil(pad_image_location.x2 - pad_image_location.x1)))
            # roi_height = min(image.shape[0], max(1.0, math.ceil(pad_image_location.y2 - pad_image_location.y1)))
            roi_width = min(image.shape[1], max(1, math.ceil(pad_image_location[2] - pad_image_location[0])))
            roi_height = min(image.shape[0], max(1, math.ceil(pad_image_location[3] - pad_image_location[1])))

            roi_bottom_int = int(roi_bottom)
            roi_bottom_height_int = roi_bottom_int + roi_height

            roi_left_int = int(roi_left)
            roi_left_width_int = roi_left_int + roi_width

            cropped_image = image[roi_bottom_int:roi_bottom_height_int, roi_left_int:roi_left_width_int]

            # output_width = max(math.ceil(bbox_tight.compute_output_width()), roi_width)
            # output_height = max(math.ceil(bbox_tight.compute_output_height()), roi_height)
            output_width = max(math.ceil(compute_output_width_f(bbox_tight)), roi_width)
            output_height = max(math.ceil(compute_output_height_f(bbox_tight)), roi_height)
            if image.ndim > 2:
                # output_image = np.zeros((int(output_height), int(output_width), image.shape[2]), dtype=image.dtype)
                output_image = torch.zeros((int(output_height), int(output_width), image.shape[2]), dtype=image.dtype)
            else:
                # output_image = np.zeros((int(output_height), int(output_width)), dtype=image.dtype)
                output_image = torch.zeros((int(output_height), int(output_width)), dtype=image.dtype)

            # edge_spacing_x = min(bbox_tight.edge_spacing_x(), (image.shape[1] - 1))
            # edge_spacing_y = min(bbox_tight.edge_spacing_y(), (image.shape[0] - 1))
            edge_spacing_x = torch.minimum(edge_spacing_x_f(bbox_tight), torch.tensor(image.shape[1] - 1))
            edge_spacing_y = torch.minimum(edge_spacing_y_f(bbox_tight), torch.tensor(image.shape[0] - 1))

            # rounding should be done to match the width and height
            output_image[
                int(edge_spacing_y) : int(edge_spacing_y) + cropped_image.shape[0],
                int(edge_spacing_x) : int(edge_spacing_x) + cropped_image.shape[1],
            ] = cropped_image

            return output_image, pad_image_location, edge_spacing_x, edge_spacing_y

            Around the bounding box, we define an extra context factor of 2, which we will crop from the original image.

            :param bbox_tight: Coordinates of bounding box [x1, y1, x2, y2].
            :param image: Frame to be cropped and padded.
            :return: Cropped and Padded image.
            
art/estimators/object_tracking/pytorch_goturn.py