dgs.utils.image.create_mask_from_polygons¶
- dgs.utils.image.create_mask_from_polygons(img_size: tuple[int, int], polygons_x: list[list[int | float]], polygons_y: list[list[int | float]], device: torch.types.Device | str = 'cpu') torchvision.tv_tensors.Mask [source]¶
Given the x- and y- coordinates of one or multiple polygons, create a
Mask
.- Parameters:
img_size – The size of the (original) image as
(height, width)
. Because the polygon coordinates are given with respect to the original image, the returned mask will have the same shape as the image.polygons_x – A list containing the x-coordinates of
N
polygons. Each of the polygons can have a different number of coordinates / vertices.polygons_y – A list containing the y-coordinates of
N
polygons. Each of the polygons can have a different number of coordinates / vertices.device – The device the resulting mask should be on. Default “cpu”.
- Returns:
mask_tv is a binary mask containing
True
, where the polygons are filled. The Mask has the shape[W x H]
.