segmentation_maps
sleap_nn.data.segmentation_maps
¶
Generate ground truth tensors for instance segmentation from SegmentationMask objects.
Functions:
| Name | Description |
|---|---|
generate_center_heatmap |
Generate Gaussian heatmap at each instance mask centroid. |
generate_center_offsets |
Generate per-pixel offset vectors pointing to each pixel's instance center. |
generate_foreground_mask |
Generate binary foreground mask as union of all instance masks. |
generate_center_heatmap(masks, img_hw, output_stride=2, sigma=4.0, centers=None)
¶
Generate Gaussian heatmap at each instance mask centroid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
List[ndarray]
|
List of 2D boolean arrays (H, W), one per instance. |
required |
img_hw
|
Tuple[int, int]
|
Original image size as (height, width). |
required |
output_stride
|
int
|
Stride for downsampling the output. |
2
|
sigma
|
float
|
Standard deviation of the Gaussian in pixels (at original resolution). |
4.0
|
centers
|
Optional[List[Tuple[float, float]]]
|
Pre-computed list of (x, y) centroid coordinates. If None, centroids
will be computed from masks via |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape (1, 1, H/s, W/s) with float32 values. |
Source code in sleap_nn/data/segmentation_maps.py
generate_center_offsets(masks, img_hw, output_stride=2, centers=None)
¶
Generate per-pixel offset vectors pointing to each pixel's instance center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
List[ndarray]
|
List of 2D boolean arrays (H, W), one per instance. |
required |
img_hw
|
Tuple[int, int]
|
Original image size as (height, width). |
required |
output_stride
|
int
|
Stride for downsampling the output. |
2
|
centers
|
Optional[List[Tuple[float, float]]]
|
Pre-computed list of (x, y) centroid coordinates. If None, centroids
will be computed from masks via |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple of: offsets: Tensor of shape (1, 2, H/s, W/s) with (dx, dy) offset vectors. Only defined on foreground pixels; background pixels are 0. weight_mask: Tensor of shape (1, 1, H/s, W/s) binary mask indicating where offset loss should be computed (foreground pixels). |
Source code in sleap_nn/data/segmentation_maps.py
generate_foreground_mask(masks, img_hw, output_stride=2, maxpool=False)
¶
Generate binary foreground mask as union of all instance masks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
List[ndarray]
|
List of 2D boolean arrays (H, W), one per instance. |
required |
img_hw
|
Tuple[int, int]
|
Original image size as (height, width). |
required |
output_stride
|
int
|
Stride for downsampling the output mask. |
2
|
maxpool
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape (1, 1, H/s, W/s) with float32 values in [0, 1]. |