Mask

The aloscene Mask object represents a binary or float mask. It can be used to represent different objects, for example occlusions mask for flow and disparity use cases.

Note

The values of a Mask are between 0. and 1., to allow to partially/completely mask another tensor by multiplying it by the mask.

Basic Use

A Mask object can be initialized from a path to a mask file:

from aloscene import Mask
mask = Mask("path/to/mask.png")

or from an existing tensor:

import torch
mask_float_tensor = torch.rand((1,400,600))
mask = Mask(mask_tensor, names=("C","H","W"))

Mask API

class aloscene.mask.Mask(x, labels: Optional[Union[dict, aloscene.labels.Labels]] = None, *args, **kwargs)

Bases: aloscene.tensors.spatial_augmented_tensor.SpatialAugmentedTensor

Binary or Float Mask

Parameters
x :

path to the mask file (png) or tensor (values between 0. and 1.)

append_labels(labels, name=None)

Attach a set of labels to the masks.

Parameters
labels: aloscene.Labels

Set of labels to attached to the masks

name: str

If none, the label will be attached without name (if possible). Otherwise if no other unnamed labels are attached to the frame, the labels will be added to the set of labels.

get_view(frame=None, size=None, labels_set=None, color_by_cat=False, **kwargs)

Get view of segmentation mask and used it in a input Frame

Parameters
frameTensor, optional

Frame where the segmentation mask will be displayed, by default None

sizetuple, optional

Size of a desired masks, by default not-resize

labels_setstr, optional

Set of labels to show in segmentation when multiple labels are defined, by default None

color_by_catbool, optional

Set same color by category ID, by default False

Returns
Renderer.View

Frame view, ready to render

Raises
Exception

Input frame must be a aloscene.Frame object

iou_with(mask2)

IoU calculation between mask2 and itself

Parameters
mask2aloscene.Mask

Masks with size (M,H,W)

Returns
torch.Tensor

IoU matrix of size (N,M)

rtype

Tensor ..

mask2id(labels_set=None, return_ann=False, return_cats=False)

Create a panoptic view of the frame, where each pixel represent one class

Parameters
labels_setstr, optional

If multilabels are handled, get mask_id by a set of label desired, by default None

return_annbool, optional

Return annotations to get_view function, by default False

return_catsbool, optional

Return categories ID instance ID, by default False.

Returns
np.array

Array of (H,W) dimensions, where each value represent one class