import copy


def crop(info, bbox):
    """
    Crop a heatmap given its info and a cropping area

    :param info: dict, heatmaps info
    :param bbox: tuple(int, int, int, int), bounding box (top left x, top left y, bottom right x, bottom right, y) of the cropping area
    :return: dict, heatmaps info (copy)
    """
    info = copy.deepcopy(info)
    tl_x, tl_y, br_x, br_y = bbox

    info['img_width'] = br_x - tl_x
    info['img_height'] = br_y - tl_y
    for cwh in info['cwh_list']:
        c_x, c_y = cwh['center']
        cwh['center'] = (c_x - tl_x, c_y - tl_y)

    info['cwh_list'] = [cwh for cwh in info['cwh_list'] \
                        if 0 <= cwh['center'][0] <= info['img_width'] and 0 <= cwh['center'][1] <= info['img_height']]

    return info