otx.core.utils.mask_util#

Utility functions for mask operations.

Functions

crop_and_resize_masks(annos, bboxes, ...[, ...])

Crop and resize masks to the target size.

crop_and_resize_polygons(annos, bboxes, ...)

Crop and resize polygons to the target size.

encode_rle(mask)

Encodes a mask into RLE format.

polygon_to_bitmap(polygons, height, width)

Convert a list of polygons to a bitmap mask.

polygon_to_rle(polygons, height, width)

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:

dict

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.

Parameters:
  • polygons (list[Polygon]) – List of Datumaro Polygon objects.

  • height (int) – bitmap height

  • width (int) – bitmap width

Returns:

bitmap masks

Return type:

np.ndarray

otx.core.utils.mask_util.polygon_to_rle(polygons: list[Polygon], height: int, width: int) list[dict][source]#

Convert a list of polygons to a list of RLE masks.

Parameters:
  • polygons (list[Polygon]) – List of Datumaro Polygon objects.

  • height (int) – bitmap height

  • width (int) – bitmap width

Returns:

List of RLE masks.

Return type:

list[dict]