def boxes_to_masks(boxes: list[torch.Tensor], image_size: tuple[int, int]) -> torch.Tensor:
    """Convert bounding boxes to segmentation masks.

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

    Returns:
        Binary masks of shape ``(B, H, W)`` where pixels contained within boxes
        are set to 1

    Examples:
        >>> boxes = [torch.tensor([[10, 15, 20, 25]])]  # One box in first image
        >>> masks = boxes_to_masks(boxes, (32, 32))
        >>> masks.shape
        torch.Size([1, 32, 32])
    """
    masks = torch.zeros((len(boxes), *image_size)).to(boxes[0].device)
    for im_idx, im_boxes in enumerate(boxes):
        for box in im_boxes:
            x_1, y_1, x_2, y_2 = box.int()
            masks[im_idx, y_1 : y_2 + 1, x_1 : x_2 + 1] = 1
    return masks
Convert bounding boxes to segmentation masks.

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

    Returns:
        Binary masks of shape ``(B, H, W)`` where pixels contained within boxes
        are set to 1

    Examples:
        >>> boxes = [torch.tensor([[10, 15, 20, 25]])]  # One box in first image
        >>> masks = boxes_to_masks(boxes, (32, 32))
        >>> masks.shape
        torch.Size([1, 32, 32])
    
src/anomalib/data/utils/boxes.py