def resize_image_and_bbox(image, bbox: torch.Tensor, target_size=(800, 800)):
    """Resize the image and convert bbox.

    Resize the image to target_size,
    while converting the bounding box from (x, y, w, h) to a normalized (cx, cy, w, h) format.
    """
    original_w, original_h = image.size
    target_w, target_h = target_size
    scale_w = target_w / original_w
    scale_h = target_h / original_h

    image = image.resize(target_size, Image.Resampling.LANCZOS)

    x, y, w, h = bbox
    x_new = x * scale_w
    y_new = y * scale_h
    w_new = w * scale_w
    h_new = h * scale_h
    cx = (x_new + w_new / 2) / target_w
    cy = (y_new + h_new / 2) / target_h
    w_new /= target_w
    h_new /= target_h
    bbox = torch.tensor([cx, cy, w_new, h_new])

    return image, bbox
Resize the image and convert bbox.

    Resize the image to target_size,
    while converting the bounding box from (x, y, w, h) to a normalized (cx, cy, w, h) format.
    
examples/table_transformer_detection/ttd.py