otx.core.utils.mask_util#
Utility functions for mask operations.
Functions
|
Crop and resize masks to the target size. |
|
Crop and resize polygons to the target size. |
|
Encodes a mask into RLE format. |
|
Convert a list of polygons to a bitmap mask. |
|
Convert a list of polygons to a list of RLE masks. |
- otx.core.utils.mask_util.crop_and_resize_masks(annos: tv_tensors.Mask, bboxes: np.ndarray, out_shape: tuple, inds: np.ndarray, device: str = 'cpu') torch.Tensor [source]#
Crop and resize masks to the target size.
- otx.core.utils.mask_util.crop_and_resize_polygons(annos: list[Polygon], bboxes: ndarray, out_shape: tuple, inds: ndarray, device: str = 'cpu') Tensor [source]#
Crop and resize polygons to the target size.
- otx.core.utils.mask_util.encode_rle(mask: Tensor) dict [source]#
Encodes a mask into RLE format.
Rewrite of cocodataset/cocoapi
Example
Given M=[0 0 1 1 1 0 1] the RLE counts is [2 3 1 1]. Or for M=[1 1 1 1 1 1 0] the RLE counts is [0 6 1].
- Parameters:
mask (torch.Tensor) – A binary mask (0 or 1) of shape (H, W).
- Returns:
A dictionary with keys “counts” and “size”.
- Return type:
- otx.core.utils.mask_util.polygon_to_bitmap(polygons: list[Polygon], height: int, width: int) ndarray [source]#
Convert a list of polygons to a bitmap mask.