tlc.core.helpers.segmentation_helper¶
Module Contents¶
Classes¶
Class |
Description |
|---|---|
Helper class for segmentation operations. |
API¶
- class SegmentationHelper¶
Helper class for segmentation operations.
- static bbox_from_rle(
- rle: CocoRle,
Convert an RLE mask to a bounding box.
- Parameters:
rle – The RLE mask to convert
- Returns:
A list of bounding box coordinates [x1, y1, x2, y2]
- static empty_rle( ) CocoRle¶
Create an empty RLE mask with the given dimensions.
- Parameters:
height – Height of the mask
width – Width of the mask
- Returns:
An empty RLE mask dictionary with ‘counts’ and ‘size’ fields
- static mask_from_polygons( ) ndarray¶
Convert a list of polygons to a numpy array.
- Parameters:
polygons – The list of polygons to convert
height – The height of the image
width – The width of the image
relative – Whether the polygons are relative to the image size
- Returns:
A numpy array of shape (H, W, N) containing N binary masks
- static mask_from_rle( ) ndarray¶
Convert an RLE mask to a numpy array.
- Parameters:
rle – The RLE mask to convert
- Returns:
A numpy array of shape (H, W, N) containing N binary masks
- static masks_from_rles( ) ndarray¶
Convert multiple RLE masks to a numpy array.
- Parameters:
rles – List of RLE dictionaries with ‘counts’ and ‘size’ fields
- Returns:
A numpy array of shape (H, W, N) containing N binary masks
- static polygons_from_mask( ) list[float]¶
Convert a binary mask to a list of polygons using OpenCV contour detection.
- Parameters:
mask – The binary mask to convert
relative – Whether to return polygons with coordinates relative to image dimensions
- Returns:
List of polygons where each polygon is a flattened list of x,y coordinates
- static polygons_from_rles( ) list[list[float]]¶
Convert a list of RLE encoded masks to polygons.
- Parameters:
rles – List of RLE dictionaries with ‘counts’ and ‘size’ fields
relative – Whether to return polygons with coordinates relative to image dimensions
- Returns:
List of polygons where each polygon is a flattened list of x,y coordinates
- static rles_from_masks(
- masks: ndarray,
Convert a stack of binary masks to RLE format.
- Parameters:
masks – A numpy array of shape (H, W, N) containing N binary masks
- Returns:
List of RLE dictionaries with ‘counts’ and ‘size’ fields
- static rles_from_polygons( ) list[CocoRle]¶
Convert a list of polygons to RLE format.
- Parameters:
polygons – The list of polygons to convert
height – The height of the image
width – The width of the image
relative – Whether the polygons are relative to the image size
- Returns:
List of RLE dictionaries with ‘counts’ and ‘size’ fields