Mask API
- faster_coco_eval.core.mask.area(rleObjs)
Compute area of encoded masks.
- Parameters:
rleObjs (
dict|list[dict]) – Run-length encoding of binary mask(s).- Returns:
Area(s) of run-length encodings.
- Return type:
ndarray
- faster_coco_eval.core.mask.calculateRleForAllAnnotations(anns, img_sizes, compute_rle, compute_boundary, boundary_dilation_ratio, boundary_cpu_count)
Calculate run-length encoding for all annotations.
- Parameters:
anns (
list[dict]) – List of annotation dictionaries.img_sizes (
dict[int,tuple]) – Dictionary mapping image ids to their sizes (height, width).compute_rle (
bool) – Whether to compute run-length encoding.compute_boundary (
bool) – Whether to compute boundary run-length encoding.boundary_dilation_ratio (
float) – Ratio of dilation to apply to the mask boundary.boundary_cpu_count (
int) – Number of CPUs to use for boundary computation.
- Returns:
None
- faster_coco_eval.core.mask.decode(rleObjs)
Decode binary masks encoded via RLE.
- Parameters:
rleObjs (
dict|list[dict]) – Run-length encoding of binary mask(s).- Returns:
Decoded binary mask(s).
- Return type:
ndarray
- faster_coco_eval.core.mask.encode(bimask)
Encode binary mask(s) using RLE.
- Parameters:
bimask (
ndarray) – Binary mask. Can be 2D (H, W) or 3D (H, W, N).- Returns:
Run-length encoding of the binary mask(s).
- Return type:
dict
- faster_coco_eval.core.mask.frPyObjects(objs, h, w)
Convert a list of objects to RLE format suitable for use in mask API.
- Parameters:
objs (
list[ndarray] |list[list[float]] |ndarray|list[dict] |list[float] |dict) – Objects to be converted (polygons, bboxes, etc).h (
int) – Height of the image.w (
int) – Width of the image.
- Returns:
Run-length encoding of the objects.
- Return type:
dict|list[dict]
- faster_coco_eval.core.mask.iou(dt, gt, iscrowd)
Compute intersection over union (IoU) between two sets of run-length encoded masks.
- Parameters:
dt (
list[ndarray] |list[list[float]] |ndarray|list[dict]) – Detected masks, can be a list of RLEs or arrays.gt (
list[ndarray] |list[list[float]] |ndarray|list[dict]) – Ground truth masks, can be a list of RLEs or arrays.iscrowd (
list[int]) – List of flags indicating whether each ground truth mask is a crowd region.
- Returns:
Intersection over union between dt and gt masks.
- Return type:
list|ndarray
- faster_coco_eval.core.mask.merge(rleObjs, intersect=0)
Merge a list of run-length encoded objects.
- Parameters:
rleObjs (
list[dict]) – List of run-length encoding dictionaries of binary masks.intersect (
int) – Flag for type of merge to perform. Defaults to 0.
- Returns:
Run-length encoding of merged mask.
- Return type:
dict
- faster_coco_eval.core.mask.rleToBoundary(rle, dilation_ratio=0.02, backend='mask_api')
Convert run-length encoding to boundary rle.
- Parameters:
rle (
dict) – Run-length encoding of a binary mask.dilation_ratio (
float) – Ratio of dilation to apply to the mask. Defaults to 0.02.backend (
str) – Backend to use for conversion. ‘mask_api’ uses the faster_eval_api_cpp backend, ‘opencv’ uses OpenCV for conversion. Defaults to “mask_api”.
- Returns:
Run-length encoding of the boundary mask.
- Return type:
dict- Raises:
ImportError – If OpenCV is selected as backend but not available.
- faster_coco_eval.core.mask.rleToBoundaryCV(rle, dilation_ratio=0.02)
Convert run-length encoding to boundary rle using OpenCV backend.
- Parameters:
rle (
dict) – Run-length encoding of a binary mask.dilation_ratio (
float) – Ratio of dilation to apply to the mask. Defaults to 0.02.
- Returns:
Run-length encoding of the boundary mask.
- Return type:
dict
- faster_coco_eval.core.mask.segmToRle(segm, w, h)
Convert segm array to run-length encoding.
- Parameters:
segm (
list[float] |list[int] |dict) – Segmentation map, can be a list of floats, ints or a dictionary.w (
int) – Width of the image.h (
int) – Height of the image.
- Returns:
Run-length encoding of the segmentation map.
- Return type:
dict
- faster_coco_eval.core.mask.toBbox(rleObjs)
Get bounding boxes surrounding encoded masks.
- Parameters:
rleObjs (
dict|list[dict]) – Run-length encoding of binary mask(s).- Returns:
Bounding box(es) of run-length encodings.
- Return type:
ndarray