import torch


def wh2xy(bboxes):
    """
    :param bboxes: (x_ctr, y_ctr, w, h) (n, 4)
    :return: out_bboxes: (xmin, ymin, xmax, ymax) (n, 4)
    """
    num_boxes = bboxes.size(0)

    xmins = bboxes[..., 0] - (bboxes[..., 2] - 1) / 2.0
    ymins = bboxes[..., 1] - (bboxes[..., 3] - 1) / 2.0
    xmaxs = bboxes[..., 0] + (bboxes[..., 2] - 1) / 2.0
    ymaxs = bboxes[..., 1] + (bboxes[..., 3] - 1) / 2.0

    return torch.cat((xmins.unsqueeze(1), ymins.unsqueeze(1), xmaxs.unsqueeze(1), ymaxs.unsqueeze(1)), 1)