def dm_mask_to_cvat_rle(cls, dm_mask: dm.Mask) -> list[int]:
        "Converts a Datumaro mask to a CVAT RLE"

        # get tight mask
        x, y, w, h = dm_mask.get_bbox()
        top = int(y)
        left = int(x)
        bottom = int(max(y, y + h - 1))
        right = int(max(x, x + w - 1))
        tight_binary_mask = dm_mask.image[top : bottom + 1, left : right + 1]

        # obtain RLE
        cvat_rle = cls.rle(tight_binary_mask.reshape(-1))
        cvat_rle += [left, top, right, bottom]
        return cvat_rle
Converts a Datumaro mask to a CVAT RLE
cvat/apps/dataset_manager/formats/transformations.py