def _clip_bboxes(xyxy, h, w):
    """Clip bboxes coordinates that are outside image dimensions."""
    x1, y1, x2, y2 = xyxy
    if w >= h:
        pad = (w - h) // 2
        h1 = pad
        h2 = w - pad
        return (x1, max(y1, h1), x2, min(y2, h2))
    else:
        pad = (h - w) // 2
        w1 = pad
        w2 = h - pad
        return (max(x1, w1), y1, min(x2, w2), y2)