mask_tools module
- datumaro.util.mask_tools.generate_colormap(length=256, *, include_background=True)[source]
Generates colors using PASCAL VOC algorithm.
- If include_background is True, the result will include the item
“0: (0, 0, 0)”, which is typically used as a background color. Otherwise, indices will start from 0, but (0, 0, 0) is not included.
Returns index -> (R, G, B) mapping.
- datumaro.util.mask_tools.paint_mask(mask, colormap=None)[source]
Applies colormap to index mask
mask: HW(C) [0; max_index] mask colormap: index -> (R, G, B)
- datumaro.util.mask_tools.remap_mask(mask, map_fn)[source]
Changes mask elements from one colormap to another
# mask: HW(C) [0; max_index] mask
- datumaro.util.mask_tools.mask_to_polygons(mask, area_threshold=1)[source]
Convert an instance mask to polygons
- Parameters
mask – a 2d binary mask
tolerance – maximum distance from original points of a polygon to the approximated ones
area_threshold – minimal area of generated polygons
- Returns
A list of polygons like [[x1,y1, x2,y2 …], […]]
- datumaro.util.mask_tools.crop_covered_segments(segments, width, height, iou_threshold=0.0, ratio_tolerance=0.001, area_threshold=1, return_masks=False)[source]
Find all segments occluded by others and crop them to the visible part only. Input segments are expected to be sorted from background to foreground.
- Parameters
segments – 1d list of segment RLEs (in COCO format)
width – width of the image
height – height of the image
iou_threshold – IoU threshold for objects to be counted as intersected By default is set to 0 to process any intersected objects
ratio_tolerance – an IoU “handicap” value for a situation when an object is (almost) fully covered by another one and we don’t want make a “hole” in the background object
area_threshold – minimal area of included segments
- Returns
- [
[[x1,y1, x2,y2 …], …], # input segment #0 parts mask1, # input segment #1 mask (if source segment is mask) [], # when source segment is too small …
]
- Return type
A list of input segments’ parts (in the same order as input)