Skip to content

Commit

Permalink
Add masking of expansion by parent to Expand Labels task.
Browse files Browse the repository at this point in the history
Ensures expanded labels do not cross into neighboring object.
  • Loading branch information
nrepina committed Aug 24, 2024
1 parent 4c8ebe3 commit 5db49b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/scmultiplex/__FRACTAL_MANIFEST__.json
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,12 @@
"title": "Expand By Factor",
"type": "number",
"description": "Multiplier that specifies pixels by which to expand each label. Float in range [0, 1 or higher], e.g. 0.2 means that 20% of mean equivalent diameter of labels in region is used."
},
"mask_expansion_by_parent": {
"default": false,
"title": "Mask Expansion By Parent",
"type": "boolean",
"description": "If True, final expanded labels are masked by group_by object. Recommended to set to True for child/parent masking."
}
},
"required": [
Expand Down
7 changes: 7 additions & 0 deletions src/scmultiplex/fractal/expand_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def expand_labels(
expand_by_pixels: Union[int, None] = None,
calculate_image_based_expansion_distance: bool = False,
expand_by_factor: Union[float, None] = None,
mask_expansion_by_parent: bool = False,
) -> dict[str, Any]:
"""
Expand labels in 2D or 3D image without overlap.
Expand All @@ -72,6 +73,8 @@ def expand_labels(
be supplied.
expand_by_factor: Multiplier that specifies pixels by which to expand each label. Float in range
[0, 1 or higher], e.g. 0.2 means that 20% of mean equivalent diameter of labels in region is used.
mask_expansion_by_parent: If True, final expanded labels are masked by group_by object. Recommended to set
to True for child/parent masking.
"""

logger.info(
Expand Down Expand Up @@ -243,6 +246,10 @@ def expand_labels(
expandby,
expansion_distance_image_based=calculate_image_based_expansion_distance,
)

if mask_expansion_by_parent and group_by is not None:
seg_expanded = seg_expanded * parent_mask

logger.info(f"Expanded label(s) in region {label_str} by {distance} pixels.")

##############
Expand Down

0 comments on commit 5db49b7

Please sign in to comment.