class documentation

A semantic segmentation for an image.

Provide either the mask or mask_path argument to define the segmentation.

Parameters
maska numpy array with integer values encoding the semantic labels
mask_paththe absolute path to the segmentation image on disk
Method export_mask Exports this instance's mask to the given path.
Method get_mask Returns the segmentation mask for this instance.
Method import_mask Imports this instance's mask from disk to its mask attribute.
Method to_detections Returns a Detections representation of this instance with instance masks populated.
Method to_polylines Returns a Polylines representation of this instance.
Method transform_mask Transforms this instance's mask according to the provided targets map.
Instance Variable mask Undocumented
Instance Variable mask_path Undocumented
Property has_mask Whether this instance has a mask.
Constant _MEDIA_FIELD Undocumented

Inherited from _HasID:

Class Variable tags Undocumented
Instance Variable id Undocumented
Method _id.setter Undocumented
Property _id Undocumented

Inherited from Label (via _HasID, _HasMedia):

Method delete_attribute Deletes the attribute with the given name.
Method get_attribute_value Gets the value of the attribute with the given name.
Method has_attribute Determines whether the label has an attribute with the given name.
Method iter_attributes Returns an iterator over the custom attributes of the label.
Method set_attribute_value Sets the value of the attribute with the given name.
def export_mask(self, outpath, update=False): (source)

Exports this instance's mask to the given path.

Parameters
outpaththe path to write the mask
update:Falsewhether to clear this instance's mask attribute and set its mask_path attribute when exporting in-database segmentations
def get_mask(self): (source)

Returns the segmentation mask for this instance.

Returns
a numpy array, or None
def import_mask(self, update=False): (source)

Imports this instance's mask from disk to its mask attribute.

Parameters
update:Falsewhether to clear this instance's mask_path attribute after importing
def to_detections(self, mask_targets=None, mask_types='stuff'): (source)

Returns a Detections representation of this instance with instance masks populated.

Each "stuff" class will be converted to a single Detection whose instance mask spans all region(s) of the class.

Each "thing" class will result in one Detection instance per connected region of that class in the segmentation.

Parameters
mask_targets:Nonea dict mapping integer pixel values (2D masks) or RGB hex strings (3D masks) to label strings defining which classes to generate detections for. If omitted, all labels are assigned to their pixel values
mask_types:"stuff"

whether the classes are "stuff" (amorphous regions of pixels) or "thing" (connected regions, each representing an instance of the thing). Can be any of the following:

  • "stuff" if all classes are stuff classes
  • "thing" if all classes are thing classes
  • a dict mapping pixel values (2D masks) or RGB hex strings (3D masks) to "stuff" or "thing" for each class
Returns
a Detections
def to_polylines(self, mask_targets=None, mask_types='stuff', tolerance=2): (source)

Returns a Polylines representation of this instance.

Each "stuff" class will be converted to a single Polyline that may contain multiple disjoint shapes capturing the class.

Each "thing" class will result in one Polyline instance per connected region of that class.

Parameters
mask_targets:Nonea dict mapping integer pixel values (2D masks) or RGB hex strings (3D masks) to label strings defining which classes to generate detections for. If omitted, all labels are assigned to their pixel values
mask_types:"stuff"

whether the classes are "stuff" (amorphous regions of pixels) or "thing" (connected regions, each representing an instance of the thing). Can be any of the following:

  • "stuff" if all classes are stuff classes
  • "thing" if all classes are thing classes
  • a dict mapping pixel values (2D masks) or RGB hex strings (3D masks) to "stuff" or "thing" for each class
tolerance:2a tolerance, in pixels, when generating approximate polylines for each region. Typical values are 1-3 pixels
Returns
a Polylines
def transform_mask(self, targets_map, outpath=None, update=False): (source)

Transforms this instance's mask according to the provided targets map.

This method can be used to transform between grayscale and RGB masks, or it can be used to edit the pixel values or colors of a mask without changing the number of channels.

Note that any pixel values not in targets_map will be zero in the transformed mask.

Parameters
targets_mapa dict mapping existing pixel values (2D masks) or RGB hex strings (3D masks) to new pixel values or RGB hex strings. You may convert between grayscale and RGB using this argument
outpath:Nonean optional path to write the transformed mask on disk
update:Falsewhether to save the transformed mask on this instance
Returns
the transformed mask

Undocumented

mask_path: None = (source)

Undocumented

Whether this instance has a mask.

_MEDIA_FIELD: str = (source)

Undocumented

Value
'mask_path'