davisinteractive.third_party.mask_api.mask

Interface for manipulating masks stored in RLE format.

This code interfaces with the implementation of the COCOAPI to encode and decode binary masks. Original code is available here.

Copyright © 2014, Piotr Dollar and Tsung-Yi Lin All rights reserved.

encode_mask

encode_mask(mask, nb_objects=None)
Encode a mask.

It accepts multiple indexes on the mask. The mask for every index will be encoded in a different RLE.

Arguments

  • bimask: Numpy Array. Mask array with the index of every pixel. The shape must be (H, W) and all the values are supposed to be integers.
  • nb_objects: Integer. Number of objects in the mask. If not given the value will be infered. If given, the computation will be faster.

Return

Dictionary: Dictionary with the RLE of the mask.

decode_mask

decode_mask(encoding)
Decode a mask.

Decode a multi index mask and return its mask as a Numpy Array.

Arguments

  • encoding: Dictionary. Mask encoded object.

Returns

Numpy Array: Mask decoded with shape (H, W).

encode_batch_masks

encode_batch_masks(masks, nb_objects=None)
Encode a batch of masks.

It accepts multiple indexes on the mask. The mask for every index will be encoded in a different RLE.

Arguments

  • bimask: Numpy Array. Mask array with the index of every pixel. The shape must be (B, H, W) and all the values are supposed to be integers.
  • nb_objects: Integer. Number of objects in the mask. If not given the value will be infered. If given, the computation will be faster.

Return

Dictionary: Dictionary with the RLE of the masks.

decode_batch_masks

decode_batch_masks(encoding)
Decode a batch of mask.

Decode a multi index mask and return its mask as a Numpy Array.

Arguments

  • encoding: Dictionary. Mask encoded object.

Returns

Numpy Array: Mask decoded with shape (B, H, W).