import math


def transform(anchor_coords, reg_targets):
    """
    Applies the bounding box regression transformation to an anchor box.
    :param anchor_coords: numpy array of the anchor coordinates: [x1, y1, x2, y2]
    :param reg_targets: numpy array of the bounding box regression parameters: [tx, ty, tw, th]
    :return: numpy array with the coordinates of the transformed box: [x1, y1, x2, y2]
    """
    x1, y1, x2, y2 = anchor_coords
    cxa, cya = (x1 + x2) / 2, (y1 + y2) / 2
    wa, ha = x2 - x1, y2 - y1
    tx, ty, tw, th = reg_targets

    cx = tx * wa + cxa
    cy = ty * ha + cya
    w = math.exp(tw) * wa
    h = math.exp(th) * ha
    x = cx - w/2
    y = cy - h/2

    return x, y, x+w, y+h