def boxes_to_anomaly_maps(boxes: torch.Tensor, scores: torch.Tensor, image_size: tuple[int, int]) -> torch.Tensor:
    """Convert bounding boxes and scores to anomaly heatmaps.

    Args:
        boxes: List of length ``B`` where each element is tensor of shape ``(N, 4)``
            containing bounding box coordinates in ``xyxy`` format
        scores: List of length ``B`` where each element is 1D tensor of length ``N``
            containing anomaly scores for each box
        image_size: Output heatmap size as ``(H, W)``

    Returns:
        Anomaly heatmaps of shape ``(B, H, W)``. Pixels within each box are set to
        that box's anomaly score. For overlapping boxes, the highest score is used.

    Examples:
        >>> boxes = [torch.tensor([[10, 15, 20, 25]])]  # One box
        >>> scores = [torch.tensor([0.9])]  # Score for the box
        >>> maps = boxes_to_anomaly_maps(boxes, scores, (32, 32))
        >>> maps[0, 20, 15]  # Point inside box
        tensor(0.9000)
    """
    anomaly_maps = torch.zeros((len(boxes), *image_size)).to(boxes[0].device)
    for im_idx, (im_boxes, im_scores) in enumerate(zip(boxes, scores, strict=False)):
        im_map = torch.zeros((im_boxes.shape[0], *image_size))
        for box_idx, (box, score) in enumerate(zip(im_boxes, im_scores, strict=True)):
            x_1, y_1, x_2, y_2 = box.int()
            im_map[box_idx, y_1 : y_2 + 1, x_1 : x_2 + 1] = score
            anomaly_maps[im_idx], _ = im_map.max(dim=0)
    return anomaly_maps
Convert bounding boxes and scores to anomaly heatmaps.

    Args:
        boxes: List of length ``B`` where each element is tensor of shape ``(N, 4)``
            containing bounding box coordinates in ``xyxy`` format
        scores: List of length ``B`` where each element is 1D tensor of length ``N``
            containing anomaly scores for each box
        image_size: Output heatmap size as ``(H, W)``

    Returns:
        Anomaly heatmaps of shape ``(B, H, W)``. Pixels within each box are set to
        that box's anomaly score. For overlapping boxes, the highest score is used.

    Examples:
        >>> boxes = [torch.tensor([[10, 15, 20, 25]])]  # One box
        >>> scores = [torch.tensor([0.9])]  # Score for the box
        >>> maps = boxes_to_anomaly_maps(boxes, scores, (32, 32))
        >>> maps[0, 20, 15]  # Point inside box
        tensor(0.9000)
    
src/anomalib/data/utils/boxes.py