import torch


def extents_to_centers(boxes):
    """
  Convert boxes from [x0, y0, x1, y1] format to [xc, yc, w, h] format

  Input:
  - boxes: Input boxes of shape (N, 4) in [x0, y0, x1, y1] format

  Returns:
  - boxes: Output boxes of shape (N, 4) in [xc, yc, w, h] format
  """
    x0, y0 = boxes[:, 0], boxes[:, 1]
    x1, y1 = boxes[:, 2], boxes[:, 3]

    xc = 0.5 * (x0 + x1)
    yc = 0.5 * (y0 + y1)
    w = x1 - x0
    h = y1 - y0

    boxes_out = torch.stack([xc, yc, w, h], dim=1)
    return boxes_out