overlay
sleap_nn.inference.sam.overlay
¶
Review/debug overlay rendering for predicted segmentation masks.
A v1 deliverable is review-style overlays (PLAN L4): masks are produced now;
the GUI correction round-trip is gated on upstream frontend work. This module
renders a colored per-instance mask overlay PNG so a human can eyeball the
predictions before importing the .slp. Harvested from #642 _save_overlay
and repurposed for PredictedSegmentationMask (which carries scale/offset, so
masks are decoded to the image grid first).
cv2 is imported lazily inside the function so importing this module never
pulls OpenCV.
Functions:
| Name | Description |
|---|---|
save_mask_overlay |
Render image + colored per-instance mask overlay for one labeled frame. |
save_mask_overlay(labels, path, frame_index=0, low_score_threshold=None)
¶
Render image + colored per-instance mask overlay for one labeled frame.
When low_score_threshold is given, any mask whose .score falls below
it is rendered as a low-score flag so a human reviewer knows to scrutinize
it: its contour is drawn in a fixed warning color (:data:_WARNING_COLOR)
with a thicker outline, and a "!{score:.2f}" text label is drawn near the
mask centroid. Masks at/above the threshold (and all masks when the threshold
is None) render normally with their cycled per-instance :data:_COLORS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
A |
required | |
path
|
Output PNG path. |
required | |
frame_index
|
int
|
Which labeled frame to render (default the first). |
0
|
low_score_threshold
|
Optional[float]
|
Optional score floor; masks with |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Path]
|
The written |